Revision 5a683295
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
110 | 110 |
private DistortedEffects[] mStarEffects; |
111 | 111 |
private DistortedNode mBackground; |
112 | 112 |
private DistortedScreen mScreen; |
113 |
private MeshQuad mGFFAQuad, mCrawlQuad, mCrawlBackgroundQuad, mLogoQuad, mStarQuad;
|
|
113 |
private MeshQuad mQuad; |
|
114 | 114 |
|
115 | 115 |
private long alphaEffectID, scaleEffectID, moveEffectID; |
116 | 116 |
private Random mRnd = new Random(0); |
117 | 117 |
private int mWidth, mHeight; |
118 |
private float mLogoRatio; |
|
119 |
private int mCrawlBackgroundW, mCrawlBackgroundH; |
|
118 | 120 |
|
119 | 121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | 122 |
|
... | ... | |
122 | 124 |
{ |
123 | 125 |
mView = v; |
124 | 126 |
|
125 |
mGFFAQuad = new MeshQuad(); |
|
126 |
mStarQuad = new MeshQuad(); |
|
127 |
mCrawlQuad = new MeshQuad(); |
|
128 |
mCrawlBackgroundQuad = new MeshQuad(); |
|
129 |
mLogoQuad = new MeshQuad(); |
|
130 |
|
|
131 |
mGFFAQuad.setStretch(GFFA_WIDTH,GFFA_HEIGHT,0); |
|
132 |
mCrawlQuad.setStretch(CRAWL_WIDTH,CRAWL_HEIGHT,0); |
|
127 |
mQuad = new MeshQuad(); |
|
133 | 128 |
|
134 | 129 |
mGFFAEffects = new DistortedEffects(); |
135 | 130 |
mLogoEffects = new DistortedEffects(); |
... | ... | |
214 | 209 |
if( mCrawlBackgroundTexture!=null ) mCrawlBackgroundTexture.markForDeletion(); |
215 | 210 |
mCrawlBackgroundTexture = new DistortedTexture(); |
216 | 211 |
|
217 |
mCrawlBackgroundQuad.setStretch(scrW,(int)(scrH*Math.sin(angleA)/Math.sin(angleB)),0); |
|
212 |
mCrawlBackgroundW = scrW; |
|
213 |
mCrawlBackgroundH = (int)(scrH*Math.sin(angleA)/Math.sin(angleB)); |
|
218 | 214 |
|
219 | 215 |
int randomA, randomX, randomY, randomTime; |
220 | 216 |
float randomS, randomAlpha1, randomAlpha2; |
... | ... | |
227 | 223 |
{ |
228 | 224 |
randomX = mRnd.nextInt(scrW) - scrW/2; |
229 | 225 |
randomY = mRnd.nextInt(scrH) - scrH/2; |
230 |
randomS = 0.2f+ 0.8f*mRnd.nextFloat();
|
|
226 |
randomS = (0.2f+ 0.8f*mRnd.nextFloat())*20;
|
|
231 | 227 |
randomA = (int)(180*mRnd.nextFloat()); |
232 | 228 |
randomAlpha1 = 0.2f + 0.8f*mRnd.nextFloat(); |
233 | 229 |
randomAlpha2 = 0.8f + 0.2f*mRnd.nextFloat(); |
... | ... | |
244 | 240 |
|
245 | 241 |
mStarEffects[i].apply( new FragmentEffectAlpha(di) ); |
246 | 242 |
|
247 |
mScreen.attach(mStarTexture, mStarEffects[i], mStarQuad);
|
|
243 |
mScreen.attach(mStarTexture, mStarEffects[i], mQuad); |
|
248 | 244 |
} |
249 |
|
|
250 |
float scale = (0.5f*scrW/mGFFAQuad.getStretchX()); |
|
251 |
|
|
245 |
|
|
252 | 246 |
Dynamic1D di = new Dynamic1D(6000,0.5f); |
253 | 247 |
di.add(new Static1D(1.0f)); |
254 | 248 |
di.add(new Static1D(1.0f)); |
... | ... | |
258 | 252 |
alpha.notifyWhenFinished(this); |
259 | 253 |
alphaEffectID = alpha.getID(); |
260 | 254 |
|
255 |
Static3D scale = new Static3D(0.5f*scrW, 0.5f*scrW * GFFA_HEIGHT / GFFA_WIDTH, 1); |
|
256 |
|
|
261 | 257 |
mGFFAEffects.apply( new MatrixEffectScale(scale) ); |
262 |
mGFFAEffects.apply( new MatrixEffectMove(new Static3D(-scrW/3 + mGFFAQuad.getStretchX()/2 ,scrH/6,0)) );
|
|
258 |
mGFFAEffects.apply( new MatrixEffectMove(new Static3D(-scrW/3 + GFFA_WIDTH/2 ,scrH/6,0)) );
|
|
263 | 259 |
mGFFAEffects.apply( alpha ); |
264 | 260 |
|
265 |
mScreen.attach(mGFFATexture, mGFFAEffects, mGFFAQuad);
|
|
261 |
mScreen.attach(mGFFATexture, mGFFAEffects, mQuad); |
|
266 | 262 |
} |
267 | 263 |
|
268 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
312 | 308 |
mGFFATexture.setTexture(bitmapGFFA); |
313 | 309 |
|
314 | 310 |
///// create Logo /////////////////// |
315 |
mLogoQuad.setStretch(bitmapLogo.getWidth(),bitmapLogo.getHeight(),0); |
|
316 |
if( mLogoTexture==null ) mLogoTexture = new DistortedTexture(); |
|
311 |
if( mLogoTexture==null ) mLogoTexture = new DistortedTexture(); |
|
317 | 312 |
mLogoTexture.setTexture(bitmapLogo); |
313 |
mLogoRatio = (float)bitmapLogo.getWidth()/bitmapLogo.getHeight(); |
|
318 | 314 |
|
319 | 315 |
///// create CRAWL ////////////////// |
320 | 316 |
if( mCrawlTexture==null ) mCrawlTexture = new DistortedTexture(); |
... | ... | |
331 | 327 |
mCrawlTexture.setTexture(bitmapText); |
332 | 328 |
|
333 | 329 |
///// create Stars /////////////////// |
334 |
mStarQuad.setStretch(bitmapStar.getWidth(),bitmapStar.getHeight(),0); |
|
335 | 330 |
if( mStarTexture==null ) mStarTexture = new DistortedTexture(); |
336 | 331 |
mStarTexture.setTexture(bitmapStar); |
337 | 332 |
} |
... | ... | |
388 | 383 |
mGFFATexture.markForDeletion(); |
389 | 384 |
|
390 | 385 |
int screenW = mScreen.getWidth(); |
391 |
float logoW = mLogoQuad.getStretchX(); |
|
392 |
int initSize= (int)(3.0f*screenW/logoW); |
|
393 |
int finaSize= (int)(0.1f*screenW/logoW); |
|
386 |
int initSize= (int)(3.00f*screenW); |
|
387 |
int finaSize= (int)(0.01f*screenW); |
|
394 | 388 |
|
395 | 389 |
Dynamic3D di = new Dynamic3D(10000,0.5f); |
396 |
di.add(new Static3D(initSize,initSize,1)); |
|
397 |
di.add(new Static3D(finaSize,finaSize,1)); |
|
390 |
di.add(new Static3D(initSize,initSize/mLogoRatio,1));
|
|
391 |
di.add(new Static3D(finaSize,finaSize/mLogoRatio,1));
|
|
398 | 392 |
MatrixEffectScale scale = new MatrixEffectScale(di); |
399 | 393 |
scale.notifyWhenFinished(this); |
400 | 394 |
scaleEffectID = scale.getID(); |
401 | 395 |
mLogoEffects.apply( scale ); |
402 |
mScreen.attach(mLogoTexture, mLogoEffects, mLogoQuad);
|
|
396 |
mScreen.attach(mLogoTexture, mLogoEffects, mQuad); |
|
403 | 397 |
} |
404 | 398 |
else if( effectID == scaleEffectID ) |
405 | 399 |
{ |
406 | 400 |
mScreen.detach(mLogoEffects); |
407 | 401 |
mLogoTexture.markForDeletion(); |
408 |
|
|
409 |
float crawlW = mCrawlQuad.getStretchX(); |
|
410 |
float crawlH = mCrawlQuad.getStretchY(); |
|
411 |
float screenW= mScreen.getWidth(); |
|
412 |
float screenH= mScreen.getHeight(); |
|
413 |
float backW = mCrawlBackgroundQuad.getStretchX(); |
|
414 |
float backH = mCrawlBackgroundQuad.getStretchY(); |
|
415 |
float scale = backW/crawlW; |
|
416 |
|
|
417 |
mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0,-backH/2,0)) ); |
|
418 |
mCrawlBackgroundEffects.apply( new MatrixEffectMove(new Static3D( 0, (backH-screenH)/2, 0)) ); |
|
419 |
|
|
420 |
final int transpDist = 5; |
|
421 |
Static3D center = new Static3D( 0, (transpDist-0.5f)*backH , 0 ); |
|
422 |
Static3D region = new Static3D( transpDist*backH , transpDist*backH , transpDist*backH ); |
|
402 |
|
|
403 |
float scale = mCrawlBackgroundW/CRAWL_WIDTH; |
|
404 |
|
|
405 |
mCrawlBackgroundEffects.apply( new MatrixEffectScale( new Static3D(mCrawlBackgroundW, mCrawlBackgroundH, 1) ) ); |
|
406 |
mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0,-mCrawlBackgroundH/2,0)) ); |
|
407 |
mCrawlBackgroundEffects.apply( new MatrixEffectMove(new Static3D( 0, (mCrawlBackgroundH-mHeight)/2, 0)) ); |
|
408 |
|
|
409 |
final float transpDist = 5; |
|
410 |
Static3D center = new Static3D( 0, transpDist-0.5f, 0 ); |
|
411 |
Static3D region = new Static3D( transpDist, transpDist, transpDist ); |
|
423 | 412 |
mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) ); |
424 | 413 |
|
425 | 414 |
Dynamic3D di = new Dynamic3D(70000,0.5f); |
426 |
di.add(new Static3D(0, -(scale*crawlH+backH)/2, 0));
|
|
427 |
di.add(new Static3D(0, +(scale*crawlH+backH)/2, 0));
|
|
415 |
di.add(new Static3D(0, -(scale*CRAWL_HEIGHT+mCrawlBackgroundH)/2, 0));
|
|
416 |
di.add(new Static3D(0, +(scale*CRAWL_HEIGHT+mCrawlBackgroundH)/2, 0));
|
|
428 | 417 |
MatrixEffectMove move = new MatrixEffectMove(di); |
429 | 418 |
move.notifyWhenFinished(this); |
430 | 419 |
moveEffectID = move.getID(); |
431 | 420 |
|
432 |
mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale,scale,scale)) );
|
|
421 |
mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale*CRAWL_WIDTH,scale*CRAWL_HEIGHT,1)) );
|
|
433 | 422 |
mCrawlEffects.apply( move ); |
434 | 423 |
|
435 |
mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects, mCrawlBackgroundQuad); |
|
436 |
mBackground.attach(mCrawlTexture, mCrawlEffects, mCrawlQuad); |
|
424 |
mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects, mQuad); |
|
425 |
mBackground.resizeFBO(mCrawlBackgroundW,mCrawlBackgroundH); |
|
426 |
mBackground.attach(mCrawlTexture, mCrawlEffects, mQuad); |
|
437 | 427 |
mBackground.glDisable(GLES31.GL_DEPTH_TEST); |
438 | 428 |
mBackground.glDepthMask(false); |
439 | 429 |
} |
Also available in: Unified diff
Size of the FBO internal to Nodes is now NO MORE taken from the Mesh's stretch values.
Instead, the size is copied from child's FBO size (if there is one) or if the child is a leaf with texture in it (which is sizeless) then we get the default 100x100 ( which means we probably have to explicitly call Node.resizeFBO() )