Revision d79a56d3
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/examples/catanddog/CatAndDogRenderer.java | ||
---|---|---|
134 | 134 |
|
135 | 135 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
136 | 136 |
{ |
137 |
int duration = 10000; // 10 seconds |
|
138 |
|
|
137 |
// 1 cycle = 10000 ms = 10 seconds long |
|
138 |
int duration = 10000; |
|
139 |
|
|
140 |
// First abort all effect we might have had before |
|
141 |
// (we will if we got here from a brief stay in the background) |
|
142 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
143 |
|
|
144 |
// Now start applying the effects. Matrix effects are, like the name suggests, multiplications |
|
145 |
// of the Mesh by certain Projective Transformation Matrix. As such, those are - confusingly - |
|
146 |
// applied in exactly the opposite order than given, i.e. here the last SCALE would be the |
|
147 |
// first effect applied to each vertex of our Mesh, followed by a ROTATION, and only then by |
|
148 |
// the MOVE ! |
|
149 |
|
|
150 |
// MOVES ///////// |
|
151 |
// Now, after the SCALE and ROTATE, the center of our Mesh is still exactly at the center of |
|
152 |
// the Screen. Thus we move the Mesh back and forth between (0.5,0.5,0) and (-0.5,-0.5,0) , |
|
153 |
// i.e. between the lower right and upper left corners of the screen. |
|
139 | 154 |
Dynamic3D diMove = new Dynamic3D(duration,0.0f); |
140 |
diMove.add(new Static3D(width-bmpWidth,height-bmpHeight,0)); |
|
141 |
diMove.add(new Static3D(0,0,0)); |
|
142 |
|
|
143 |
Dynamic3D diScale = new Dynamic3D(duration,0.0f); |
|
144 |
diScale.add(new Static3D(1,1,1)); |
|
145 |
diScale.add(new Static3D(0.33f,0.33f,1)); |
|
146 |
|
|
155 |
Static3D lowerRight = new Static3D( +0.5f, +0.5f, 0); |
|
156 |
Static3D upperLeft = new Static3D( -0.5f, -0.5f, 0); |
|
157 |
diMove.add(lowerRight); |
|
158 |
diMove.add(upperLeft); |
|
159 |
mEffects.move(diMove); |
|
160 |
|
|
161 |
// ROTATION ////// |
|
162 |
// Now, after the SCALE, our Texture is positioned at the center of the screen - coords (0,0,0). |
|
163 |
// Rotate the whole Mesh around this point, along the (0,0,1) axis (i.e. vector perpendicular to |
|
164 |
// the surface of the screen) starting from 0 degrees to 360 and back. |
|
147 | 165 |
Dynamic1D diRotate = new Dynamic1D(duration,0.0f); |
148 | 166 |
diRotate.add(new Static1D( 0)); |
149 | 167 |
diRotate.add(new Static1D(360)); |
150 |
|
|
151 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
152 |
|
|
153 |
mEffects.move(diMove); |
|
168 |
Static3D axis = new Static3D(0,0,1); |
|
169 |
Static3D center = new Static3D(0,0,0); |
|
170 |
mEffects.rotate( diRotate, axis, center ); |
|
171 |
|
|
172 |
// SCALING /////// |
|
173 |
// Before we apply any effects, at the very start, out Mesh skinned by the 'Cat and Dog' texture |
|
174 |
// fills up the whole Screen. First we need to scale it down so that the resolution of the |
|
175 |
// original 'Cat and Dog' bitmap are preserved, (qx/qy part) and also apply a Dynamic switching |
|
176 |
// the size from 80% of the Screen to 20% and back. |
|
177 |
Dynamic3D diScale = new Dynamic3D(duration,0.0f); |
|
178 |
float qx = (float)width /bmpWidth; |
|
179 |
float qy = (float)height/bmpHeight; |
|
180 |
float start_scale = 0.8f; |
|
181 |
float end_scale = 0.2f; |
|
182 |
diScale.add(qx<qy ? (new Static3D( start_scale,start_scale*qx/qy,1)) : (new Static3D(start_scale*qy/qx,start_scale,1))); |
|
183 |
diScale.add(qx<qy ? (new Static3D( end_scale ,end_scale *qx/qy,1)) : (new Static3D(end_scale *qy/qx,end_scale ,1))); |
|
154 | 184 |
mEffects.scale(diScale); |
155 |
mEffects.rotate( diRotate, new Static3D(0,0,1), new Static3D(bmpWidth/2,bmpHeight/2,0) ); |
|
156 | 185 |
|
186 |
// Finally, tell the Screen itself the underlying OpenGL surface has changed dimensions. |
|
157 | 187 |
mScreen.resize(width, height); |
158 | 188 |
} |
159 | 189 |
} |
Also available in: Unified diff
Major refactoring: convert the Matrix Effects to be independent of the resolution of the surface we render to.
Re-write the first 15 apps to work with this.