Revision b62eb334
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
34 | 34 |
import org.distorted.library.mesh.MeshBase; |
35 | 35 |
import org.distorted.library.mesh.MeshFlat; |
36 | 36 |
|
37 |
import org.distorted.library.message.EffectListener; |
|
38 |
import org.distorted.library.message.EffectMessage; |
|
37 | 39 |
import org.distorted.library.type.Dynamic3D; |
38 | 40 |
import org.distorted.library.type.Static3D; |
39 | 41 |
import org.distorted.library.type.Static4D; |
... | ... | |
46 | 48 |
|
47 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 50 |
|
49 |
class DeformRenderer implements GLSurfaceView.Renderer |
|
51 |
class DeformRenderer implements GLSurfaceView.Renderer , EffectListener
|
|
50 | 52 |
{ |
51 | 53 |
private static final int NUM_VECTORS = 8; |
52 | 54 |
private static final int NUM_LINES = 10; |
53 | 55 |
|
54 | 56 |
private GLSurfaceView mView; |
55 |
private DistortedTexture stretchTexture;
|
|
56 |
private DistortedEffects stretchEffects;
|
|
57 |
private MeshBase stretchMesh;
|
|
57 |
private DistortedTexture mTexture;
|
|
58 |
private DistortedEffects mEffects;
|
|
59 |
private MeshBase mMesh;
|
|
58 | 60 |
private DistortedScreen mScreen; |
59 | 61 |
private Static3D mTouchPoint; |
60 | 62 |
|
... | ... | |
80 | 82 |
{ |
81 | 83 |
mView = view; |
82 | 84 |
|
83 |
stretchEffects = new DistortedEffects();
|
|
85 |
mEffects = new DistortedEffects();
|
|
84 | 86 |
mRegion = new Static4D(0,0,0,0); |
85 | 87 |
mMove = new Static3D(0,0,0); |
86 | 88 |
mTouchPoint = new Static3D(0,0,0); |
87 | 89 |
|
90 |
mEffects.registerForMessages(this); |
|
91 |
|
|
88 | 92 |
// DISTORT |
89 | 93 |
Dynamic3D releasedDistortDynamic = new Dynamic3D(NUM_VECTORS*500, 0.5f); |
90 | 94 |
releasedDistortDynamic.setMode(Dynamic3D.MODE_PATH); |
... | ... | |
143 | 147 |
mReleasedDeform = new VertexEffectDeform ( releasedDeformDynamic , mTouchPoint, mRegion); |
144 | 148 |
mReleasedShear = new MatrixEffectShear ( releasedShearDynamic , mTouchPoint ); |
145 | 149 |
|
146 |
stretchEffects.apply(new MatrixEffectMove(mMove));
|
|
150 |
mEffects.apply(new MatrixEffectMove(mMove));
|
|
147 | 151 |
} |
148 | 152 |
|
149 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
161 | 165 |
mRegion.set4(mRadius*scrWidth); |
162 | 166 |
} |
163 | 167 |
|
168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
169 |
// keep aborting the 'released' effects, otherwise we are quickly going to run out of room in |
|
170 |
// effect queues. |
|
171 |
|
|
172 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
173 |
{ |
|
174 |
switch(em) |
|
175 |
{ |
|
176 |
case EFFECT_FINISHED: mEffects.abortById(effectID); break; |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
164 | 180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
165 | 181 |
|
166 | 182 |
public void onDrawFrame(GL10 glUnused) |
... | ... | |
181 | 197 |
int w=width/2; |
182 | 198 |
int h=height/2; |
183 | 199 |
|
184 |
if( stretchMesh!=null ) stretchMesh.markForDeletion();
|
|
200 |
if( mMesh!=null ) mMesh.markForDeletion();
|
|
185 | 201 |
|
186 |
stretchMesh = new MeshFlat(50,50*h/w);
|
|
202 |
mMesh = new MeshFlat(50,50*h/w);
|
|
187 | 203 |
Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888); |
188 | 204 |
stretchCanvas = new Canvas(stretchBitmap); |
189 | 205 |
|
... | ... | |
199 | 215 |
stretchCanvas.drawRect( 0, h*i/NUM_LINES-1, w , h*i/NUM_LINES+1, paint); |
200 | 216 |
} |
201 | 217 |
|
202 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h);
|
|
203 |
stretchTexture.setTexture(stretchBitmap);
|
|
218 |
if( mTexture==null ) mTexture = new DistortedTexture(w,h);
|
|
219 |
mTexture.setTexture(stretchBitmap);
|
|
204 | 220 |
|
205 | 221 |
mMove.set(scrWidth/4,scrHeight/4,0); |
206 | 222 |
|
207 | 223 |
mScreen.detachAll(); |
208 |
mScreen.attach(stretchTexture,stretchEffects,stretchMesh);
|
|
224 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
209 | 225 |
|
210 | 226 |
mScreen.resize(width, height); |
211 | 227 |
} |
... | ... | |
244 | 260 |
switch(mMode) |
245 | 261 |
{ |
246 | 262 |
case DISTORT: vDistort[0].set(0,0,0); |
247 |
stretchEffects.apply(mMovingDistort);
|
|
263 |
mEffects.apply(mMovingDistort);
|
|
248 | 264 |
mLastEffect = mMovingDistort.getID(); |
249 | 265 |
break; |
250 | 266 |
case DEFORM : vDeform[0].set(0,0,0); |
251 |
stretchEffects.apply(mMovingDeform);
|
|
267 |
mEffects.apply(mMovingDeform);
|
|
252 | 268 |
mLastEffect = mMovingDeform.getID(); |
253 | 269 |
break; |
254 | 270 |
case SHEAR : vShear[0].set(0,0,0); |
255 |
stretchEffects.apply(mMovingShear);
|
|
271 |
mEffects.apply(mMovingShear);
|
|
256 | 272 |
mLastEffect = mMovingShear.getID(); |
257 | 273 |
break; |
258 | 274 |
} |
... | ... | |
277 | 293 |
|
278 | 294 |
void up() |
279 | 295 |
{ |
280 |
stretchEffects.abortById(mLastEffect);
|
|
296 |
mEffects.abortById(mLastEffect);
|
|
281 | 297 |
|
282 | 298 |
float damp = -0.65f; |
283 | 299 |
|
... | ... | |
288 | 304 |
vDistort[i].set( vDistort[i-1].get1()*damp, vDistort[i-1].get2()*damp, 0 ); |
289 | 305 |
} |
290 | 306 |
vDistort[NUM_VECTORS-1].set(0,0,0); |
291 |
stretchEffects.apply(mReleasedDistort);
|
|
307 |
mEffects.apply(mReleasedDistort);
|
|
292 | 308 |
break; |
293 | 309 |
case DEFORM : for(int i=1; i<NUM_VECTORS-1; i++) |
294 | 310 |
{ |
295 | 311 |
vDeform[i].set( vDeform[i-1].get1()*damp, vDeform[i-1].get2()*damp, 0 ); |
296 | 312 |
} |
297 | 313 |
vDeform[NUM_VECTORS-1].set(0,0,0); |
298 |
stretchEffects.apply(mReleasedDeform);
|
|
314 |
mEffects.apply(mReleasedDeform);
|
|
299 | 315 |
break; |
300 | 316 |
case SHEAR : for(int i=1; i<NUM_VECTORS-1; i++) |
301 | 317 |
{ |
302 | 318 |
vShear[i].set( vShear[i-1].get1()*damp, vShear[i-1].get2()*damp, 0 ); |
303 | 319 |
} |
304 | 320 |
vShear[NUM_VECTORS-1].set(0,0,0); |
305 |
stretchEffects.apply(mReleasedShear);
|
|
321 |
mEffects.apply(mReleasedShear);
|
|
306 | 322 |
break; |
307 | 323 |
} |
308 | 324 |
} |
Also available in: Unified diff
Many things.
1) make the Dynamic.setDuration() able to be called AFTER the Dynamic has already been run. (and rename it to 'makeRunNowFor()' )
2) remove the automatic removal of zero Effects from EffectQueues.
3) adjust several Apps to cope with 2)
4) add post-rotation to Rubik (still not finished)