Revision e8b6aa95
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.DistortedBitmapGrid; |
|
31 | 32 |
import org.distorted.library.EffectNames; |
32 | 33 |
import org.distorted.library.type.Dynamic1D; |
33 | 34 |
import org.distorted.library.type.Dynamic3D; |
... | ... | |
38 | 39 |
import org.distorted.library.message.EffectListener; |
39 | 40 |
import org.distorted.library.message.EffectMessage; |
40 | 41 |
import org.distorted.library.Distorted; |
41 |
import org.distorted.library.DistortedBitmap;
|
|
42 |
import org.distorted.library.DistortedObject;
|
|
42 | 43 |
|
43 | 44 |
import android.graphics.Bitmap; |
44 | 45 |
import android.graphics.BitmapFactory; |
... | ... | |
100 | 101 |
private final float CRAWL_ANGLE = -30.0f; |
101 | 102 |
|
102 | 103 |
private GLSurfaceView mView; |
103 |
private DistortedBitmap mScreen, mGFFA, mLogo, mCrawl, mCrawlBackground;
|
|
104 |
private DistortedBitmap[] mStars;
|
|
104 |
private DistortedObject mScreen, mGFFA, mLogo, mCrawl, mCrawlBackground;
|
|
105 |
private DistortedObject[] mStars;
|
|
105 | 106 |
private long gffaID, logoID, crawlID; |
106 | 107 |
|
107 | 108 |
private Random mRnd = new Random(0); |
108 | 109 |
private DistortedNode mRoot, mBackground; |
109 |
|
|
110 |
private DistortedBitmapGrid mQuad; |
|
111 |
|
|
112 |
|
|
110 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 114 |
|
112 | 115 |
StarWarsRenderer(GLSurfaceView v) |
113 | 116 |
{ |
114 | 117 |
mView = v; |
115 |
|
|
118 |
|
|
119 |
mQuad = new DistortedBitmapGrid(1,1); |
|
116 | 120 |
Distorted.setProjection(60.0f, 0.0f, 0.0f); |
117 | 121 |
} |
118 | 122 |
|
... | ... | |
154 | 158 |
|
155 | 159 |
private void setupScreen(int w, int h) |
156 | 160 |
{ |
157 |
mScreen = new DistortedBitmap(w,h,1);
|
|
158 |
mRoot = new DistortedNode(mScreen); |
|
161 |
mScreen = new DistortedObject(w,h,1);
|
|
162 |
mRoot = new DistortedNode(mScreen,mQuad);
|
|
159 | 163 |
|
160 |
mCrawlBackground = new DistortedBitmap(w,(int)(Math.sqrt(3.0)*h),1);
|
|
164 |
mCrawlBackground = new DistortedObject(w,(int)(Math.sqrt(3.0)*h),1);
|
|
161 | 165 |
|
162 | 166 |
int randomA, randomX, randomY, randomTime; |
163 | 167 |
float randomS, randomAlpha1, randomAlpha2; |
... | ... | |
188 | 192 |
|
189 | 193 |
mStars[i].alpha(di); |
190 | 194 |
|
191 |
mRoot.attach(mStars[i]); |
|
195 |
mRoot.attach(mStars[i], mQuad);
|
|
192 | 196 |
} |
193 | 197 |
|
194 | 198 |
float scale = (0.5f*w/mGFFA.getWidth()); |
... | ... | |
202 | 206 |
mGFFA.scale( new Static3D(scale,scale,scale) ); |
203 | 207 |
mGFFA.alpha(di); |
204 | 208 |
|
205 |
mRoot.attach(mGFFA); |
|
209 |
mRoot.attach(mGFFA, mQuad);
|
|
206 | 210 |
mGFFA.addEventListener(this); |
207 | 211 |
} |
208 | 212 |
|
... | ... | |
240 | 244 |
paint.setTypeface(tf); |
241 | 245 |
|
242 | 246 |
///// create GFFA /////////////////// |
243 |
mGFFA = new DistortedBitmap(GFFA_WIDTH, GFFA_HEIGHT, 1);
|
|
247 |
mGFFA = new DistortedObject(GFFA_WIDTH, GFFA_HEIGHT, 1);
|
|
244 | 248 |
bitmapGFFA = Bitmap.createBitmap(GFFA_WIDTH,GFFA_HEIGHT,Bitmap.Config.ARGB_8888); |
245 | 249 |
bitmapGFFA.eraseColor(0x00000000); |
246 | 250 |
Canvas gffaCanvas = new Canvas(bitmapGFFA); |
... | ... | |
250 | 254 |
gffaCanvas.drawText(mGFFAString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), paint); |
251 | 255 |
} |
252 | 256 |
|
253 |
mGFFA.setBitmap(bitmapGFFA);
|
|
257 |
mGFFA.setTexture(bitmapGFFA);
|
|
254 | 258 |
|
255 | 259 |
///// create Logo /////////////////// |
256 |
mLogo = new DistortedBitmap(bitmapLogo, 1); |
|
257 |
|
|
260 |
mLogo = new DistortedObject(bitmapLogo.getWidth(),bitmapLogo.getHeight(),1); |
|
261 |
mLogo.setTexture(bitmapLogo); |
|
262 |
|
|
258 | 263 |
///// create CRAWL ////////////////// |
259 |
mCrawl = new DistortedBitmap(CRAWL_WIDTH, CRAWL_HEIGHT, 1);
|
|
264 |
mCrawl = new DistortedObject(CRAWL_WIDTH, CRAWL_HEIGHT, 1);
|
|
260 | 265 |
bitmapText = Bitmap.createBitmap(CRAWL_WIDTH,CRAWL_HEIGHT,Bitmap.Config.ARGB_8888); |
261 | 266 |
bitmapText.eraseColor(0x00000000); |
262 | 267 |
Canvas textCanvas = new Canvas(bitmapText); |
... | ... | |
267 | 272 |
displayJustified(mCRAWLString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), CRAWL_WIDTH, textCanvas, paint); |
268 | 273 |
} |
269 | 274 |
|
270 |
mCrawl.setBitmap(bitmapText);
|
|
275 |
mCrawl.setTexture(bitmapText);
|
|
271 | 276 |
|
272 | 277 |
///// create Stars /////////////////// |
273 | 278 |
|
274 |
mStars = new DistortedBitmap[NUM_STARS]; |
|
275 |
|
|
276 |
mStars[0] = new DistortedBitmap(bitmapStar,1); |
|
279 |
mStars = new DistortedObject[NUM_STARS]; |
|
277 | 280 |
|
281 |
mStars[0] = new DistortedObject(bitmapStar.getWidth(),bitmapStar.getHeight(),1); |
|
282 |
mStars[0].setTexture(bitmapStar); |
|
283 |
|
|
278 | 284 |
for(int i=1; i<NUM_STARS; i++) |
279 | 285 |
{ |
280 |
mStars[i] = new DistortedBitmap(mStars[0], Distorted.CLONE_BITMAP|Distorted.CLONE_VERTEX);
|
|
286 |
mStars[i] = new DistortedObject(mStars[0], Distorted.CLONE_BITMAP|Distorted.CLONE_VERTEX);
|
|
281 | 287 |
} |
282 | 288 |
|
283 | 289 |
gffaID = mGFFA.getID(); |
... | ... | |
356 | 362 |
mLogo.scale(di); |
357 | 363 |
mLogo.move( new Static3D(-logoW/2,-logoH/2,0) ); |
358 | 364 |
|
359 |
mRoot.attach(mLogo); |
|
365 |
mRoot.attach(mLogo,mQuad);
|
|
360 | 366 |
mLogo.addEventListener(this); |
361 | 367 |
} |
362 | 368 |
else if( objectID==logoID ) |
... | ... | |
386 | 392 |
mCrawl.scale( new Static3D(scale,scale,scale) ); |
387 | 393 |
mCrawl.move( new Static3D(-crawlW/2,0,0) ); |
388 | 394 |
|
389 |
mBackground = mRoot.attach(mCrawlBackground); |
|
390 |
mBackground.attach(mCrawl); |
|
395 |
mBackground = mRoot.attach(mCrawlBackground,mQuad);
|
|
396 |
mBackground.attach(mCrawl,mQuad);
|
|
391 | 397 |
mCrawl.addEventListener(this); |
392 | 398 |
} |
393 | 399 |
else if( objectID==crawlID ) |
Also available in: Unified diff
Major change in API: separate the GRID from DistortedObject; completely remove classes derived from DistortedObject.