Revision 392e16fd
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import org.distorted.examples.R; |
30 | 30 |
|
31 |
import org.distorted.library.DistortedFramebuffer; |
|
31 | 32 |
import org.distorted.library.GridFlat; |
32 | 33 |
import org.distorted.library.EffectNames; |
33 | 34 |
import org.distorted.library.type.Dynamic1D; |
... | ... | |
103 | 104 |
|
104 | 105 |
private GLSurfaceView mView; |
105 | 106 |
private DistortedTexture mScreenTexture, mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture; |
106 |
private DistortedEffectQueues mScreenQueue, mGFFAQueue, mLogoQueue, mCrawlQueue, mCrawlBackgroundQueue;
|
|
107 |
private DistortedEffectQueues mScreenEffects, mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects;
|
|
107 | 108 |
private DistortedEffectQueues[] mStarQueue; |
108 |
private long gffaID, logoID, crawlID; |
|
109 |
|
|
110 |
private Random mRnd = new Random(0); |
|
111 | 109 |
private DistortedObjectTree mRoot, mBackground; |
110 |
private DistortedFramebuffer mScreen; |
|
112 | 111 |
private GridFlat mQuad; |
112 |
|
|
113 |
private long gffaID, logoID, crawlID; |
|
114 |
private Random mRnd = new Random(0); |
|
113 | 115 |
private int mWidth, mHeight; |
114 | 116 |
|
115 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
120 | 122 |
|
121 | 123 |
mQuad = new GridFlat(1,1); |
122 | 124 |
|
123 |
mScreenQueue = new DistortedEffectQueues();
|
|
124 |
mGFFAQueue = new DistortedEffectQueues();
|
|
125 |
mLogoQueue = new DistortedEffectQueues();
|
|
126 |
mCrawlQueue = new DistortedEffectQueues();
|
|
127 |
mCrawlBackgroundQueue = new DistortedEffectQueues();
|
|
125 |
mScreenEffects = new DistortedEffectQueues();
|
|
126 |
mGFFAEffects = new DistortedEffectQueues();
|
|
127 |
mLogoEffects = new DistortedEffectQueues();
|
|
128 |
mCrawlEffects = new DistortedEffectQueues();
|
|
129 |
mCrawlBackgroundEffects = new DistortedEffectQueues();
|
|
128 | 130 |
|
129 | 131 |
mStarQueue = new DistortedEffectQueues[NUM_STARS]; |
130 | 132 |
mStarQueue[0] = new DistortedEffectQueues(); |
131 | 133 |
|
132 | 134 |
for(int i=1; i<NUM_STARS; i++) mStarQueue[i] = new DistortedEffectQueues(mStarQueue[0],Distorted.CLONE_VERTEX); |
133 | 135 |
|
134 |
Distorted.setProjection(60.0f, 0.0f, 0.0f); |
|
136 |
mScreen = new DistortedFramebuffer(0); |
|
137 |
mScreen.setProjection(60.0f, 0.0f, 0.0f); |
|
135 | 138 |
} |
136 | 139 |
|
137 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
147 | 150 |
public void onDrawFrame(GL10 glUnused) |
148 | 151 |
{ |
149 | 152 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
150 |
mRoot.draw(System.currentTimeMillis()); |
|
153 |
mRoot.draw(System.currentTimeMillis(),mScreen);
|
|
151 | 154 |
} |
152 | 155 |
|
153 | 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
159 | 162 |
mWidth = width; |
160 | 163 |
mHeight= height; |
161 | 164 |
|
162 |
mScreenQueue.abortAllEffects();
|
|
163 |
mGFFAQueue.abortAllEffects();
|
|
164 |
mLogoQueue.abortAllEffects();
|
|
165 |
mCrawlQueue.abortAllEffects();
|
|
166 |
mCrawlBackgroundQueue.abortAllEffects();
|
|
165 |
mScreenEffects.abortAllEffects();
|
|
166 |
mGFFAEffects.abortAllEffects();
|
|
167 |
mLogoEffects.abortAllEffects();
|
|
168 |
mCrawlEffects.abortAllEffects();
|
|
169 |
mCrawlBackgroundEffects.abortAllEffects();
|
|
167 | 170 |
|
168 | 171 |
for(int i=0; i<NUM_STARS; i++) mStarQueue[i].abortAllEffects(); |
169 | 172 |
|
170 | 173 |
setupScreen(width,height); |
171 | 174 |
|
172 |
Distorted.onSurfaceChanged(width, height);
|
|
175 |
mScreen.resize(width, height);
|
|
173 | 176 |
} |
174 | 177 |
} |
175 | 178 |
|
... | ... | |
196 | 199 |
private void setupScreen(int w, int h) |
197 | 200 |
{ |
198 | 201 |
mScreenTexture = new DistortedTexture(w,h); |
199 |
mRoot = new DistortedObjectTree(mScreenTexture,mScreenQueue,mQuad);
|
|
202 |
mRoot = new DistortedObjectTree(mScreenTexture, mScreenEffects,mQuad);
|
|
200 | 203 |
|
201 | 204 |
mCrawlBackgroundTexture = new DistortedTexture(w,(int)(Math.sqrt(3.0)*h)); |
202 | 205 |
|
... | ... | |
238 | 241 |
di.add(new Static1D(1.0f)); |
239 | 242 |
di.add(new Static1D(0.0f)); |
240 | 243 |
|
241 |
mGFFAQueue.move( new Static3D(w/5,h/3,0) );
|
|
242 |
mGFFAQueue.scale( new Static3D(scale,scale,scale) );
|
|
243 |
mGFFAQueue.alpha(di);
|
|
244 |
mGFFAEffects.move( new Static3D(w/5,h/3,0) );
|
|
245 |
mGFFAEffects.scale( new Static3D(scale,scale,scale) );
|
|
246 |
mGFFAEffects.alpha(di);
|
|
244 | 247 |
|
245 |
mRoot.attach(mGFFATexture, mGFFAQueue, mQuad);
|
|
246 |
mGFFAQueue.registerForMessages(this);
|
|
248 |
mRoot.attach(mGFFATexture, mGFFAEffects, mQuad);
|
|
249 |
mGFFAEffects.registerForMessages(this);
|
|
247 | 250 |
} |
248 | 251 |
|
249 | 252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
314 | 317 |
mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight()); |
315 | 318 |
mStarTexture.setTexture(bitmapStar); |
316 | 319 |
|
317 |
gffaID = mGFFAQueue.getID();
|
|
318 |
logoID = mLogoQueue.getID();
|
|
319 |
crawlID= mCrawlQueue.getID();
|
|
320 |
gffaID = mGFFAEffects.getID();
|
|
321 |
logoID = mLogoEffects.getID();
|
|
322 |
crawlID= mCrawlEffects.getID();
|
|
320 | 323 |
} |
321 | 324 |
|
322 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
370 | 373 |
{ |
371 | 374 |
if( objectID == gffaID ) |
372 | 375 |
{ |
373 |
mRoot.detach(mGFFAQueue);
|
|
374 |
mGFFAQueue.abortAllEffects();
|
|
376 |
mRoot.detach(mGFFAEffects);
|
|
377 |
mGFFAEffects.abortAllEffects();
|
|
375 | 378 |
mGFFATexture.markForDeletion(); |
376 | 379 |
|
377 | 380 |
int screenW=mScreenTexture.getWidth(); |
... | ... | |
387 | 390 |
di.add(new Static3D(initSize,initSize,1)); |
388 | 391 |
di.add(new Static3D(finaSize,finaSize,1)); |
389 | 392 |
|
390 |
mLogoQueue.move( new Static3D(screenW/2,screenH/2,0) );
|
|
391 |
mLogoQueue.scale(di);
|
|
392 |
mLogoQueue.move( new Static3D(-logoW/2,-logoH/2,0) );
|
|
393 |
mLogoEffects.move( new Static3D(screenW/2,screenH/2,0) );
|
|
394 |
mLogoEffects.scale(di);
|
|
395 |
mLogoEffects.move( new Static3D(-logoW/2,-logoH/2,0) );
|
|
393 | 396 |
|
394 |
mRoot.attach(mLogoTexture,mLogoQueue,mQuad);
|
|
395 |
mLogoQueue.registerForMessages(this);
|
|
397 |
mRoot.attach(mLogoTexture, mLogoEffects,mQuad);
|
|
398 |
mLogoEffects.registerForMessages(this);
|
|
396 | 399 |
} |
397 | 400 |
else if( objectID==logoID ) |
398 | 401 |
{ |
399 |
mRoot.detach(mLogoQueue);
|
|
400 |
mLogoQueue.abortAllEffects();
|
|
402 |
mRoot.detach(mLogoEffects);
|
|
403 |
mLogoEffects.abortAllEffects();
|
|
401 | 404 |
mLogoTexture.markForDeletion(); |
402 | 405 |
|
403 | 406 |
int crawlW = mCrawlTexture.getWidth(); |
... | ... | |
411 | 414 |
di.add(new Static3D(screenW/2,+backH , 0)); |
412 | 415 |
di.add(new Static3D(screenW/2,-scale*crawlH, 0)); |
413 | 416 |
|
414 |
mCrawlBackgroundQueue.move( new Static3D(0,screenH-backH,0) );
|
|
415 |
mCrawlBackgroundQueue.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) );
|
|
417 |
mCrawlBackgroundEffects.move( new Static3D(0,screenH-backH,0) );
|
|
418 |
mCrawlBackgroundEffects.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) );
|
|
416 | 419 |
|
417 | 420 |
final int transpDist = 5; |
418 | 421 |
Static4D region = new Static4D(screenW/2,(1-transpDist)*backH,transpDist*backH,transpDist*backH); |
419 |
mCrawlBackgroundQueue.alpha(new Static1D(1-transpDist/2), region, true);
|
|
422 |
mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist/2), region, true);
|
|
420 | 423 |
|
421 |
mCrawlQueue.move(di);
|
|
422 |
mCrawlQueue.scale( new Static3D(scale,scale,scale) );
|
|
423 |
mCrawlQueue.move( new Static3D(-crawlW/2,0,0) );
|
|
424 |
mCrawlEffects.move(di);
|
|
425 |
mCrawlEffects.scale( new Static3D(scale,scale,scale) );
|
|
426 |
mCrawlEffects.move( new Static3D(-crawlW/2,0,0) );
|
|
424 | 427 |
|
425 |
mBackground = mRoot.attach(mCrawlBackgroundTexture,mCrawlBackgroundQueue,mQuad);
|
|
426 |
mBackground.attach(mCrawlTexture,mCrawlQueue,mQuad);
|
|
427 |
mCrawlQueue.registerForMessages(this);
|
|
428 |
mBackground = mRoot.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
|
|
429 |
mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
|
|
430 |
mCrawlEffects.registerForMessages(this);
|
|
428 | 431 |
} |
429 | 432 |
else if( objectID==crawlID ) |
430 | 433 |
{ |
431 | 434 |
mRoot.detach(mBackground); |
432 |
mBackground.detach(mCrawlQueue);
|
|
433 |
mCrawlQueue.abortAllEffects();
|
|
435 |
mBackground.detach(mCrawlEffects);
|
|
436 |
mCrawlEffects.abortAllEffects();
|
|
434 | 437 |
mCrawlTexture.markForDeletion(); |
435 |
mCrawlBackgroundQueue.abortAllEffects();
|
|
438 |
mCrawlBackgroundEffects.abortAllEffects();
|
|
436 | 439 |
mCrawlBackgroundTexture.markForDeletion(); |
437 | 440 |
} |
438 | 441 |
} |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.