Revision 392e16fd
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 | 25 |
import org.distorted.library.Distorted; |
26 |
import org.distorted.library.DistortedFramebuffer; |
|
26 | 27 |
import org.distorted.library.DistortedTexture; |
27 | 28 |
import org.distorted.library.DistortedEffectQueues; |
28 | 29 |
import org.distorted.library.GridObject; |
... | ... | |
51 | 52 |
|
52 | 53 |
private GLSurfaceView mView; |
53 | 54 |
private DistortedTexture fpsTexture, stretchTexture; |
54 |
private DistortedEffectQueues fpsQueues, stretchQueues;
|
|
55 |
private DistortedEffectQueues fpsEffects, stretchEffects;
|
|
55 | 56 |
private GridObject fpsGrid, stretchGrid; |
57 |
private DistortedFramebuffer mScreen; |
|
56 | 58 |
private Static3D touchPoint; |
57 | 59 |
|
58 | 60 |
private Dynamic3D mReleasedDistortDynamic; |
... | ... | |
90 | 92 |
mPaint.setAntiAlias(true); |
91 | 93 |
mPaint.setTextAlign(Paint.Align.CENTER); |
92 | 94 |
|
93 |
fpsQueues = new DistortedEffectQueues();
|
|
94 |
stretchQueues = new DistortedEffectQueues();
|
|
95 |
fpsEffects = new DistortedEffectQueues();
|
|
96 |
stretchEffects = new DistortedEffectQueues();
|
|
95 | 97 |
|
96 | 98 |
mRegion = new Static4D(0,0,50,50); |
97 | 99 |
|
... | ... | |
147 | 149 |
} |
148 | 150 |
|
149 | 151 |
mMovingShearDynamic.add(vShear[0]); |
152 |
|
|
153 |
mScreen = new DistortedFramebuffer(0); |
|
150 | 154 |
} |
151 | 155 |
|
152 | 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
178 | 182 |
|
179 | 183 |
long time = System.currentTimeMillis(); |
180 | 184 |
|
181 |
stretchQueues.draw(time,stretchTexture,stretchGrid);
|
|
185 |
stretchEffects.draw(time,stretchTexture,stretchGrid,mScreen);
|
|
182 | 186 |
|
183 | 187 |
mPaint.setColor(0xffffffff); |
184 | 188 |
fpsCanvas.drawRect(0, 0, fpsW, fpsH, mPaint); |
... | ... | |
186 | 190 |
fpsCanvas.drawText(fpsString, fpsW/2, 5*fpsH/6, mPaint); |
187 | 191 |
|
188 | 192 |
fpsTexture.setTexture(fpsBitmap); |
189 |
fpsQueues.draw(time,fpsTexture,fpsGrid);
|
|
193 |
fpsEffects.draw(time,fpsTexture,fpsGrid,mScreen);
|
|
190 | 194 |
|
191 | 195 |
computeFPS(time); |
192 | 196 |
} |
... | ... | |
198 | 202 |
scrHeight = height; |
199 | 203 |
scrWidth = width; |
200 | 204 |
|
201 |
Distorted.onSurfaceChanged(width, height); |
|
202 |
|
|
203 | 205 |
if( !bitmapCreated ) |
204 | 206 |
{ |
205 | 207 |
createBitmap(scrWidth/2,scrHeight/2); |
206 |
stretchQueues.abortAllEffects();
|
|
207 |
fpsQueues.abortAllEffects();
|
|
208 |
stretchQueues.move( new Static3D(scrWidth/4,scrHeight/4,0) );
|
|
209 |
fpsQueues.move( new Static3D(5,5,0) );
|
|
208 |
stretchEffects.abortAllEffects();
|
|
209 |
fpsEffects.abortAllEffects();
|
|
210 |
stretchEffects.move( new Static3D(scrWidth/4,scrHeight/4,0) );
|
|
211 |
fpsEffects.move( new Static3D(5,5,0) );
|
|
210 | 212 |
bitmapCreated=true; |
211 | 213 |
} |
212 | 214 |
else |
213 | 215 |
{ |
214 |
stretchQueues.abortEffects(EffectTypes.VERTEX);
|
|
215 |
stretchQueues.abortEffects(EffectTypes.FRAGMENT);
|
|
216 |
stretchQueues.abortEffects(EffectNames.SHEAR);
|
|
216 |
stretchEffects.abortEffects(EffectTypes.VERTEX);
|
|
217 |
stretchEffects.abortEffects(EffectTypes.FRAGMENT);
|
|
218 |
stretchEffects.abortEffects(EffectNames.SHEAR);
|
|
217 | 219 |
} |
220 |
|
|
221 |
mScreen.resize(width, height); |
|
218 | 222 |
} |
219 | 223 |
|
220 | 224 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
288 | 292 |
switch(mMode) |
289 | 293 |
{ |
290 | 294 |
case DISTORT: vDistort[0].set(0,0,0); |
291 |
mLastEffect = stretchQueues.distort( mMovingDistortDynamic, touchPoint, mRegion);
|
|
295 |
mLastEffect = stretchEffects.distort( mMovingDistortDynamic, touchPoint, mRegion);
|
|
292 | 296 |
break; |
293 | 297 |
case DEFORM : vDeform[0].set(0,0,0); |
294 |
mLastEffect = stretchQueues.deform( mMovingDeformDynamic, touchPoint, mRegion);
|
|
298 |
mLastEffect = stretchEffects.deform( mMovingDeformDynamic, touchPoint, mRegion);
|
|
295 | 299 |
break; |
296 | 300 |
case SHEAR : vShear[0].set(0,0,0); |
297 |
mLastEffect = stretchQueues.shear(mMovingShearDynamic, touchPoint);
|
|
301 |
mLastEffect = stretchEffects.shear(mMovingShearDynamic, touchPoint);
|
|
298 | 302 |
break; |
299 | 303 |
} |
300 | 304 |
} |
... | ... | |
318 | 322 |
|
319 | 323 |
void up() |
320 | 324 |
{ |
321 |
stretchQueues.abortEffect(mLastEffect);
|
|
325 |
stretchEffects.abortEffect(mLastEffect);
|
|
322 | 326 |
|
323 | 327 |
float damp = -0.65f; |
324 | 328 |
|
... | ... | |
329 | 333 |
vDistort[i].set( vDistort[i-1].getX()*damp, vDistort[i-1].getY()*damp ); |
330 | 334 |
} |
331 | 335 |
vDistort[NUM_VECTORS-1].set(0,0); |
332 |
stretchQueues.distort( mReleasedDistortDynamic, touchPoint, mRegion);
|
|
336 |
stretchEffects.distort( mReleasedDistortDynamic, touchPoint, mRegion);
|
|
333 | 337 |
break; |
334 | 338 |
case DEFORM : for(int i=1; i<NUM_VECTORS-1; i++) |
335 | 339 |
{ |
336 | 340 |
vDeform[i].set( vDeform[i-1].getX()*damp, vDeform[i-1].getY()*damp ); |
337 | 341 |
} |
338 | 342 |
vDeform[NUM_VECTORS-1].set(0,0); |
339 |
stretchQueues.deform( mReleasedDeformDynamic, touchPoint, mRegion);
|
|
343 |
stretchEffects.deform( mReleasedDeformDynamic, touchPoint, mRegion);
|
|
340 | 344 |
break; |
341 | 345 |
case SHEAR : for(int i=1; i<NUM_VECTORS-1; i++) |
342 | 346 |
{ |
343 | 347 |
vShear[i].set( vShear[i-1].getX()*damp, vShear[i-1].getY()*damp ); |
344 | 348 |
} |
345 | 349 |
vShear[NUM_VECTORS-1].set(0,0); |
346 |
stretchQueues.shear(mReleasedShearDynamic, touchPoint);
|
|
350 |
stretchEffects.shear(mReleasedShearDynamic, touchPoint);
|
|
347 | 351 |
break; |
348 | 352 |
} |
349 | 353 |
} |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.