Revision 0de83d97
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/save/SaveRenderer.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import org.distorted.examples.R; |
32 | 32 |
|
33 |
import org.distorted.library.effect.MatrixEffectMove; |
|
34 | 33 |
import org.distorted.library.effect.MatrixEffectScale; |
35 | 34 |
import org.distorted.library.effect.VertexEffectSink; |
36 | 35 |
import org.distorted.library.main.Distorted; |
... | ... | |
61 | 60 |
private MeshFlat mMesh; |
62 | 61 |
private DistortedScreen mScreen; |
63 | 62 |
private Static1D s0; |
64 |
private Static3D mScaleFactor, mScaleMain, mMove;
|
|
63 |
private Static3D mScaleFactor, mScaleMain; |
|
65 | 64 |
|
66 | 65 |
private float mScale; |
67 | 66 |
private int bmpHeight, bmpWidth; |
... | ... | |
90 | 89 |
|
91 | 90 |
mScale = 1.0f; |
92 | 91 |
mScaleFactor = new Static3D(mScale,mScale,1.0f); |
93 |
mMove = new Static3D(0,0,0); |
|
94 | 92 |
mScaleMain = new Static3D(1,1,1); |
95 | 93 |
|
96 | 94 |
mEffects = new DistortedEffects(); |
97 | 95 |
mEffects.apply( new VertexEffectSink(diSink, pLeft , sinkRegion) ); |
98 | 96 |
mEffects.apply( new VertexEffectSink(diSink, pRight, sinkRegion) ); |
99 |
mEffects.apply( new MatrixEffectMove(mMove)); |
|
100 | 97 |
mEffects.apply( new MatrixEffectScale(mScaleMain)); |
101 | 98 |
mEffects.apply( new MatrixEffectScale(mScaleFactor)); |
102 | 99 |
|
... | ... | |
155 | 152 |
{ |
156 | 153 |
if( isSaving ) // render to an offscreen buffer and read pixels |
157 | 154 |
{ |
158 |
mMove.set(0,0,0); |
|
159 | 155 |
mScaleMain.set(1,1,1); |
160 | 156 |
mOffscreen.render(System.currentTimeMillis()); |
161 | 157 |
applyMatrixEffects(scrWidth,scrHeight); |
... | ... | |
194 | 190 |
|
195 | 191 |
private void applyMatrixEffects(int width, int height) |
196 | 192 |
{ |
197 |
if( (float)bmpHeight/bmpWidth > (float)height/width ) |
|
198 |
{ |
|
199 |
int w = (height*bmpWidth)/bmpHeight; |
|
200 |
float factor = (float)height/bmpHeight; |
|
201 |
|
|
202 |
mMove.set((width-w)/2,0,0); |
|
203 |
mScaleMain.set(factor,factor,factor); |
|
204 |
} |
|
205 |
else |
|
206 |
{ |
|
207 |
int h = (width*bmpHeight)/bmpWidth; |
|
208 |
float factor = (float)width/bmpWidth; |
|
209 |
|
|
210 |
mMove.set(0,(height-h)/2,0); |
|
211 |
mScaleMain.set(factor,factor,factor); |
|
212 |
} |
|
193 |
float horiRatio = (float)width / mTexture.getWidth(); |
|
194 |
float vertRatio = (float)height/ mTexture.getHeight(); |
|
195 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
196 |
mScaleMain.set(factor,factor,factor); |
|
213 | 197 |
} |
214 | 198 |
|
215 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.