Revision f6d884d5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
39 | 39 |
import org.distorted.library.message.EffectListener; |
40 | 40 |
import org.distorted.library.message.EffectMessage; |
41 | 41 |
import org.distorted.library.Distorted; |
42 |
import org.distorted.library.DistortedObject; |
|
42 |
import org.distorted.library.DistortedTexture; |
|
43 |
import org.distorted.library.DistortedEffectQueues; |
|
43 | 44 |
|
44 | 45 |
import android.graphics.Bitmap; |
45 | 46 |
import android.graphics.BitmapFactory; |
... | ... | |
101 | 102 |
private final float CRAWL_ANGLE = -30.0f; |
102 | 103 |
|
103 | 104 |
private GLSurfaceView mView; |
104 |
private DistortedObject mScreen, mGFFA, mLogo, mCrawl, mCrawlBackground; |
|
105 |
private DistortedObject[] mStars; |
|
105 |
private DistortedTexture mScreenTexture, mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture; |
|
106 |
private DistortedEffectQueues mScreenQueue, mGFFAQueue, mLogoQueue, mCrawlQueue, mCrawlBackgroundQueue; |
|
107 |
private DistortedEffectQueues[] mStarQueue; |
|
106 | 108 |
private long gffaID, logoID, crawlID; |
107 | 109 |
|
108 | 110 |
private Random mRnd = new Random(0); |
... | ... | |
117 | 119 |
mView = v; |
118 | 120 |
|
119 | 121 |
mQuad = new GridFlat(1,1); |
122 |
|
|
123 |
mScreenQueue = new DistortedEffectQueues(); |
|
124 |
mGFFAQueue = new DistortedEffectQueues(); |
|
125 |
mLogoQueue = new DistortedEffectQueues(); |
|
126 |
mCrawlQueue = new DistortedEffectQueues(); |
|
127 |
mCrawlBackgroundQueue = new DistortedEffectQueues(); |
|
128 |
|
|
129 |
mStarQueue = new DistortedEffectQueues[NUM_STARS]; |
|
130 |
mStarQueue[0] = new DistortedEffectQueues(); |
|
131 |
|
|
132 |
for(int i=1; i<NUM_STARS; i++) mStarQueue[i] = new DistortedEffectQueues(mStarQueue[0],Distorted.CLONE_VERTEX); |
|
133 |
|
|
120 | 134 |
Distorted.setProjection(60.0f, 0.0f, 0.0f); |
121 | 135 |
} |
122 | 136 |
|
... | ... | |
158 | 172 |
|
159 | 173 |
private void setupScreen(int w, int h) |
160 | 174 |
{ |
161 |
mScreen = new DistortedObject(w,h,1);
|
|
162 |
mRoot = new DistortedObjectTree(mScreen,mQuad); |
|
175 |
mScreenTexture = new DistortedTexture(w,h,0);
|
|
176 |
mRoot = new DistortedObjectTree(mScreenTexture,mScreenQueue,mQuad);
|
|
163 | 177 |
|
164 |
mCrawlBackground = new DistortedObject(w,(int)(Math.sqrt(3.0)*h),1);
|
|
178 |
mCrawlBackgroundTexture = new DistortedTexture(w,(int)(Math.sqrt(3.0)*h),0);
|
|
165 | 179 |
|
166 | 180 |
int randomA, randomX, randomY, randomTime; |
167 | 181 |
float randomS, randomAlpha1, randomAlpha2; |
... | ... | |
175 | 189 |
{ |
176 | 190 |
randomX = mRnd.nextInt(w); |
177 | 191 |
randomY = mRnd.nextInt(h); |
178 |
randomS = 0.2f+ mRnd.nextFloat(); |
|
192 |
randomS = 0.2f+ 0.8f*mRnd.nextFloat();
|
|
179 | 193 |
randomA = (int)(180*mRnd.nextFloat()); |
180 | 194 |
randomAlpha1 = 0.2f + 0.8f*mRnd.nextFloat(); |
181 | 195 |
randomAlpha2 = 0.8f + 0.2f*mRnd.nextFloat(); |
182 | 196 |
randomTime = 500+mRnd.nextInt(2000); |
183 | 197 |
|
184 |
mStars[i].move( new Static3D(randomX,randomY,0) );
|
|
185 |
mStars[i].scale( new Static3D(randomS,randomS,randomS) );
|
|
186 |
mStars[i].rotate( new Static1D(randomA), axis, center );
|
|
198 |
mStarQueue[i].move( new Static3D(randomX,randomY,0) );
|
|
199 |
mStarQueue[i].scale(randomS);
|
|
200 |
mStarQueue[i].rotate( new Static1D(randomA), axis, center );
|
|
187 | 201 |
|
188 | 202 |
Dynamic1D di = new Dynamic1D(randomTime,0.0f); |
189 | 203 |
di.setNoise(alphaNoise); |
190 | 204 |
di.add(new Static1D(randomAlpha1)); |
191 | 205 |
di.add(new Static1D(randomAlpha2)); |
192 | 206 |
|
193 |
mStars[i].alpha(di);
|
|
207 |
mStarQueue[i].alpha(di);
|
|
194 | 208 |
|
195 |
mRoot.attach(mStars[i], mQuad);
|
|
209 |
mRoot.attach(mStarTexture, mStarQueue[i], mQuad);
|
|
196 | 210 |
} |
197 | 211 |
|
198 |
float scale = (0.5f*w/mGFFA.getWidth()); |
|
212 |
float scale = (0.5f*w/mGFFATexture.getWidth());
|
|
199 | 213 |
|
200 | 214 |
Dynamic1D di = new Dynamic1D(6000,0.5f); |
201 | 215 |
di.add(new Static1D(1.0f)); |
202 | 216 |
di.add(new Static1D(1.0f)); |
203 | 217 |
di.add(new Static1D(0.0f)); |
204 | 218 |
|
205 |
mGFFA.move( new Static3D(w/5,h/3,0) ); |
|
206 |
mGFFA.scale( new Static3D(scale,scale,scale) ); |
|
207 |
mGFFA.alpha(di); |
|
219 |
mGFFAQueue.move( new Static3D(w/5,h/3,0) );
|
|
220 |
mGFFAQueue.scale( new Static3D(scale,scale,scale) );
|
|
221 |
mGFFAQueue.alpha(di);
|
|
208 | 222 |
|
209 |
mRoot.attach(mGFFA, mQuad); |
|
210 |
mGFFA.addEventListener(this);
|
|
223 |
mRoot.attach(mGFFATexture, mGFFAQueue, mQuad);
|
|
224 |
mGFFAQueue.addEventListener(this);
|
|
211 | 225 |
} |
212 | 226 |
|
213 | 227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
244 | 258 |
paint.setTypeface(tf); |
245 | 259 |
|
246 | 260 |
///// create GFFA /////////////////// |
247 |
mGFFA = new DistortedObject(GFFA_WIDTH, GFFA_HEIGHT, 1);
|
|
261 |
mGFFATexture = new DistortedTexture(GFFA_WIDTH, GFFA_HEIGHT, 0);
|
|
248 | 262 |
bitmapGFFA = Bitmap.createBitmap(GFFA_WIDTH,GFFA_HEIGHT,Bitmap.Config.ARGB_8888); |
249 | 263 |
bitmapGFFA.eraseColor(0x00000000); |
250 | 264 |
Canvas gffaCanvas = new Canvas(bitmapGFFA); |
... | ... | |
254 | 268 |
gffaCanvas.drawText(mGFFAString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), paint); |
255 | 269 |
} |
256 | 270 |
|
257 |
mGFFA.setTexture(bitmapGFFA); |
|
271 |
mGFFATexture.setTexture(bitmapGFFA);
|
|
258 | 272 |
|
259 | 273 |
///// create Logo /////////////////// |
260 |
mLogo = new DistortedObject(bitmapLogo.getWidth(),bitmapLogo.getHeight(),1);
|
|
261 |
mLogo.setTexture(bitmapLogo); |
|
274 |
mLogoTexture = new DistortedTexture(bitmapLogo.getWidth(),bitmapLogo.getHeight(),0);
|
|
275 |
mLogoTexture.setTexture(bitmapLogo);
|
|
262 | 276 |
|
263 | 277 |
///// create CRAWL ////////////////// |
264 |
mCrawl = new DistortedObject(CRAWL_WIDTH, CRAWL_HEIGHT, 1);
|
|
278 |
mCrawlTexture = new DistortedTexture(CRAWL_WIDTH, CRAWL_HEIGHT, 0);
|
|
265 | 279 |
bitmapText = Bitmap.createBitmap(CRAWL_WIDTH,CRAWL_HEIGHT,Bitmap.Config.ARGB_8888); |
266 | 280 |
bitmapText.eraseColor(0x00000000); |
267 | 281 |
Canvas textCanvas = new Canvas(bitmapText); |
... | ... | |
272 | 286 |
displayJustified(mCRAWLString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), CRAWL_WIDTH, textCanvas, paint); |
273 | 287 |
} |
274 | 288 |
|
275 |
mCrawl.setTexture(bitmapText); |
|
289 |
mCrawlTexture.setTexture(bitmapText);
|
|
276 | 290 |
|
277 | 291 |
///// create Stars /////////////////// |
278 |
|
|
279 |
mStars = new DistortedObject[NUM_STARS]; |
|
280 |
|
|
281 |
mStars[0] = new DistortedObject(bitmapStar.getWidth(),bitmapStar.getHeight(),1); |
|
282 |
mStars[0].setTexture(bitmapStar); |
|
292 |
mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight(),0); |
|
293 |
mStarTexture.setTexture(bitmapStar); |
|
283 | 294 |
|
284 |
for(int i=1; i<NUM_STARS; i++) |
|
285 |
{ |
|
286 |
mStars[i] = new DistortedObject(mStars[0], Distorted.CLONE_BITMAP|Distorted.CLONE_VERTEX); |
|
287 |
} |
|
288 |
|
|
289 |
gffaID = mGFFA.getID(); |
|
290 |
logoID = mLogo.getID(); |
|
291 |
crawlID= mCrawl.getID(); |
|
295 |
gffaID = mGFFAQueue.getID(); |
|
296 |
logoID = mLogoQueue.getID(); |
|
297 |
crawlID= mCrawlQueue.getID(); |
|
292 | 298 |
} |
293 | 299 |
|
294 | 300 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
342 | 348 |
{ |
343 | 349 |
if( objectID == gffaID ) |
344 | 350 |
{ |
345 |
mRoot.detach(mGFFA);
|
|
346 |
mGFFA.removeEventListener(this); |
|
351 |
mRoot.detach(mGFFAQueue);
|
|
352 |
mGFFAQueue.removeEventListener(this);
|
|
347 | 353 |
|
348 |
int screenW=mScreen.getWidth(); |
|
349 |
int screenH=mScreen.getHeight(); |
|
354 |
int screenW=mScreenTexture.getWidth();
|
|
355 |
int screenH=mScreenTexture.getHeight();
|
|
350 | 356 |
|
351 |
int logoW = mLogo.getWidth(); |
|
352 |
int logoH = mLogo.getHeight(); |
|
357 |
int logoW = mLogoTexture.getWidth();
|
|
358 |
int logoH = mLogoTexture.getHeight();
|
|
353 | 359 |
|
354 | 360 |
int initSize= (int)(3.0f*screenW/logoW); |
355 | 361 |
int finaSize= (int)(0.1f*screenW/logoW); |
... | ... | |
358 | 364 |
di.add(new Static3D(initSize,initSize,1)); |
359 | 365 |
di.add(new Static3D(finaSize,finaSize,1)); |
360 | 366 |
|
361 |
mLogo.move( new Static3D(screenW/2,screenH/2,0) ); |
|
362 |
mLogo.scale(di); |
|
363 |
mLogo.move( new Static3D(-logoW/2,-logoH/2,0) ); |
|
367 |
mLogoQueue.move( new Static3D(screenW/2,screenH/2,0) );
|
|
368 |
mLogoQueue.scale(di);
|
|
369 |
mLogoQueue.move( new Static3D(-logoW/2,-logoH/2,0) );
|
|
364 | 370 |
|
365 |
mRoot.attach(mLogo,mQuad); |
|
366 |
mLogo.addEventListener(this); |
|
371 |
mRoot.attach(mLogoTexture,mLogoQueue,mQuad);
|
|
372 |
mLogoQueue.addEventListener(this);
|
|
367 | 373 |
} |
368 | 374 |
else if( objectID==logoID ) |
369 | 375 |
{ |
370 |
mRoot.detach(mLogo);
|
|
371 |
mLogo.removeEventListener(this); |
|
376 |
mRoot.detach(mLogoQueue);
|
|
377 |
mLogoQueue.removeEventListener(this);
|
|
372 | 378 |
|
373 |
int crawlW = mCrawl.getWidth(); |
|
374 |
int crawlH = mCrawl.getHeight(); |
|
375 |
int screenW= mScreen.getWidth(); |
|
376 |
int screenH= mScreen.getHeight(); |
|
377 |
int backH = mCrawlBackground.getHeight(); |
|
379 |
int crawlW = mCrawlTexture.getWidth();
|
|
380 |
int crawlH = mCrawlTexture.getHeight();
|
|
381 |
int screenW= mScreenTexture.getWidth();
|
|
382 |
int screenH= mScreenTexture.getHeight();
|
|
383 |
int backH = mCrawlBackgroundTexture.getHeight();
|
|
378 | 384 |
float scale= (float)screenW/crawlW; |
379 | 385 |
|
380 | 386 |
Dynamic3D di = new Dynamic3D(60000,0.5f); |
381 | 387 |
di.add(new Static3D(screenW/2,+backH , 0)); |
382 | 388 |
di.add(new Static3D(screenW/2,-scale*crawlH, 0)); |
383 | 389 |
|
384 |
mCrawlBackground.move( new Static3D(0,screenH-backH,0) ); |
|
385 |
mCrawlBackground.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) ); |
|
390 |
mCrawlBackgroundQueue.move( new Static3D(0,screenH-backH,0) );
|
|
391 |
mCrawlBackgroundQueue.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) );
|
|
386 | 392 |
|
387 | 393 |
final int transpDist = 5; |
388 | 394 |
Static4D region = new Static4D(screenW/2,(1-transpDist)*backH,transpDist*backH,transpDist*backH); |
389 |
mCrawlBackground.alpha(new Static1D(1-transpDist/2), region, true); |
|
395 |
mCrawlBackgroundQueue.alpha(new Static1D(1-transpDist/2), region, true);
|
|
390 | 396 |
|
391 |
mCrawl.move(di); |
|
392 |
mCrawl.scale( new Static3D(scale,scale,scale) ); |
|
393 |
mCrawl.move( new Static3D(-crawlW/2,0,0) ); |
|
397 |
mCrawlQueue.move(di);
|
|
398 |
mCrawlQueue.scale( new Static3D(scale,scale,scale) );
|
|
399 |
mCrawlQueue.move( new Static3D(-crawlW/2,0,0) );
|
|
394 | 400 |
|
395 |
mBackground = mRoot.attach(mCrawlBackground,mQuad); |
|
396 |
mBackground.attach(mCrawl,mQuad); |
|
397 |
mCrawl.addEventListener(this); |
|
401 |
mBackground = mRoot.attach(mCrawlBackgroundTexture,mCrawlBackgroundQueue,mQuad);
|
|
402 |
mBackground.attach(mCrawlTexture,mCrawlQueue,mQuad);
|
|
403 |
mCrawlQueue.addEventListener(this);
|
|
398 | 404 |
} |
399 | 405 |
else if( objectID==crawlID ) |
400 | 406 |
{ |
401 | 407 |
mRoot.detach(mBackground); |
402 |
mBackground.detach(mCrawl); |
|
403 |
mCrawl.removeEventListener(this); |
|
408 |
mBackground.detach(mCrawlQueue);
|
|
409 |
mCrawlQueue.removeEventListener(this);
|
|
404 | 410 |
} |
405 | 411 |
} |
406 | 412 |
} |
Also available in: Unified diff
Complete the split DistortedObject -> (DistortedTexture,DistortedEffectQueue)