Revision 16b22aab
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/objecttree/ObjectTreeRenderer.java | ||
---|---|---|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 | 30 |
import org.distorted.library.effect.FragmentEffectChroma; |
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
32 | 31 |
import org.distorted.library.effect.MatrixEffectRotate; |
33 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
34 | 33 |
import org.distorted.library.effect.VertexEffectSink; |
... | ... | |
62 | 61 |
private DistortedNode mRoot; |
63 | 62 |
private MeshFlat mMeshFlat; |
64 | 63 |
private MeshCubes mMeshCubes; |
65 |
private int lisaHeight, lisaWidth; |
|
66 | 64 |
private boolean mDepth; |
67 |
private Static3D mScale, mMove;
|
|
65 |
private Static3D mScale; |
|
68 | 66 |
|
69 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
70 | 68 |
|
... | ... | |
73 | 71 |
mView = v; |
74 | 72 |
mDepth = true; |
75 | 73 |
mScale = new Static3D(1,1,1); |
76 |
mMove = new Static3D(0,0,0); |
|
77 | 74 |
Dynamic1D chromaDyn = new Dynamic1D(5000,0.0f); |
78 | 75 |
chromaDyn.add(new Static1D(0.0f)); |
79 | 76 |
chromaDyn.add(new Static1D(0.8f)); |
80 | 77 |
|
81 | 78 |
mEffects= new DistortedEffects(); |
82 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
83 | 79 |
mEffects.apply(new MatrixEffectScale(mScale)); |
84 | 80 |
mEffects.apply(new FragmentEffectChroma(chromaDyn, new Static3D(0,0,1))); |
85 | 81 |
|
... | ... | |
118 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
119 | 115 |
|
120 | 116 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
121 |
{ |
|
122 |
if( (float)lisaHeight/lisaWidth > (float)height/width ) |
|
123 |
{ |
|
124 |
int w = (height*lisaWidth)/lisaHeight; |
|
125 |
float factor = (float)height/lisaHeight; |
|
126 |
|
|
127 |
mMove.set((width-w)/2,0,0); |
|
128 |
mScale.set(factor,factor,factor); |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
int h = (width*lisaHeight)/lisaWidth; |
|
133 |
float factor = (float)width/lisaWidth; |
|
117 |
{ |
|
118 |
float horiRatio = (float)width / mLisaTexture.getWidth(); |
|
119 |
float vertRatio = (float)height/ mLisaTexture.getHeight(); |
|
120 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
134 | 121 |
|
135 |
mMove.set(0,(height-h)/2,0); |
|
136 |
mScale.set(factor,factor,factor); |
|
137 |
} |
|
138 |
|
|
122 |
mScale.set( factor,factor,factor ); |
|
139 | 123 |
mScreen.resize(width, height); |
140 | 124 |
} |
141 | 125 |
|
... | ... | |
170 | 154 |
catch(IOException e) { } |
171 | 155 |
} |
172 | 156 |
|
173 |
lisaWidth = bitmap1.getWidth(); |
|
174 |
lisaHeight = bitmap1.getHeight(); |
|
157 |
int lisaWidth = bitmap1.getWidth();
|
|
158 |
int lisaHeight = bitmap1.getHeight();
|
|
175 | 159 |
int gridWidth = bitmap2.getWidth(); |
176 | 160 |
int gridHeight= bitmap2.getHeight(); |
177 | 161 |
|
... | ... | |
200 | 184 |
mScreen.attach(mRoot); |
201 | 185 |
|
202 | 186 |
float factor = lisaWidth/(2.0f*gridWidth); |
203 |
MatrixEffectMove move = new MatrixEffectMove( new Static3D((lisaWidth-factor*gridWidth)/2,(lisaHeight-factor*gridHeight)/2, gridWidth/(2.0f*GRID))); |
|
204 | 187 |
MatrixEffectScale scale = new MatrixEffectScale( new Static3D(factor,factor,factor) ); |
205 |
gridEffects.apply(move); |
|
206 | 188 |
gridEffects.apply(scale); |
207 | 189 |
|
208 | 190 |
Dynamic1D rotDyn = new Dynamic1D(12000,0.0f); |
209 | 191 |
rotDyn.add(new Static1D( 0)); |
210 | 192 |
rotDyn.add(new Static1D(360)); |
211 | 193 |
rotDyn.setMode(Dynamic.MODE_JUMP); |
212 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(gridWidth/2,gridHeight/2,gridWidth/(2*GRID)));
|
|
194 |
MatrixEffectRotate rotate = new MatrixEffectRotate(rotDyn, new Static3D(1,0,0), new Static3D(0,0,0));
|
|
213 | 195 |
gridEffects.apply(rotate); |
214 | 196 |
|
215 | 197 |
Dynamic1D sinkDyn = new Dynamic1D(3000,0.0f); |
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.