Project

General

Profile

Download (16 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / starwars / StarWarsRenderer.java @ d218d64e

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19 427ab7bf Leszek Koltunski
20 5068fa06 Leszek Koltunski
package org.distorted.examples.starwars;
21 427ab7bf Leszek Koltunski
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.util.Random;
25
26
import javax.microedition.khronos.egl.EGLConfig;
27
import javax.microedition.khronos.opengles.GL10;
28
29 5068fa06 Leszek Koltunski
import org.distorted.examples.R;
30
31 392e16fd Leszek Koltunski
import org.distorted.library.DistortedFramebuffer;
32 d218d64e leszek
import org.distorted.library.DistortedScreen;
33 b01acdaf Leszek Koltunski
import org.distorted.library.MeshFlat;
34 c5a28eb8 Leszek Koltunski
import org.distorted.library.EffectNames;
35 7589635e Leszek Koltunski
import org.distorted.library.type.Dynamic1D;
36
import org.distorted.library.type.Dynamic3D;
37 d04a4886 Leszek Koltunski
import org.distorted.library.DistortedTree;
38 7589635e Leszek Koltunski
import org.distorted.library.type.Static1D;
39
import org.distorted.library.type.Static3D;
40
import org.distorted.library.type.Static4D;
41 13efa930 Leszek Koltunski
import org.distorted.library.message.EffectListener;
42
import org.distorted.library.message.EffectMessage;
43 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
44 f6d884d5 Leszek Koltunski
import org.distorted.library.DistortedTexture;
45 d04a4886 Leszek Koltunski
import org.distorted.library.DistortedEffects;
46 427ab7bf Leszek Koltunski
47
import android.graphics.Bitmap;
48
import android.graphics.BitmapFactory;
49
import android.graphics.Canvas;
50
import android.graphics.Paint;
51
import android.graphics.Typeface;
52 41a81a14 Leszek Koltunski
import android.opengl.GLES30;
53 427ab7bf Leszek Koltunski
import android.opengl.GLSurfaceView;
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
class StarWarsRenderer implements GLSurfaceView.Renderer, EffectListener
58 bc0a685b Leszek Koltunski
  {
59
  private final String[] mGFFAString = 
60 427ab7bf Leszek Koltunski
         
61
            { "A long time ago, in a galaxy far,",
62
              "far away...." };                    // yes, there really was a four-dot ellipsis
63
64 bc0a685b Leszek Koltunski
  private final String[] mCRAWLString = 
65 427ab7bf Leszek Koltunski
      
66
            { "It is a period of civil war.",      // in the original 1977 version, there was no 
67
              "Rebel spaceships, striking",        // 'Episode IV New Hope' subtitle line before
68
              "from a hidden base, have",          // the crawl. Lets keep to the classic.
69
              "won their first victory",
70
              "against the evil Galactic",
71
              "Empire.",
72
              "",
73
              "During the battle, rebel",
74
              "spies managed to steal",
75
              "secret plans to the Empire's",
76
              "ultimate weapon, the",
77
              "DEATH STAR, an armored",
78
              "space station with enough",
79
              "power to destroy an entire",
80
              "planet.",
81
              "",
82
              "Pursued by the Empire's",
83
              "sinister agents, Princess",
84
              "Leia races home aboard her",
85
              "starship, custodian of the",
86
              "stolen plans that can save",
87
              "her people and restore",
88
              "freedom to the galaxy...." };      // four-dot.
89
   
90 bc0a685b Leszek Koltunski
  private final int NUM_STARS = 40;
91 427ab7bf Leszek Koltunski
   
92 bc0a685b Leszek Koltunski
  private final int CRAWL_COLOR = 0xffffe81f;
93
  private final int GFFA_COLOR  = 0xff0000ff;
94
  private final int FONT_HEIGHT      = 40;
95
  private final int VERTICAL_SPACING = 10;
96
  private final String CRAWL_TYPEFACE = "News Gothic";
97 427ab7bf Leszek Koltunski
   
98 bc0a685b Leszek Koltunski
  private final int CRAWL_WIDTH = 500;
99
  private final int CRAWL_HEIGHT= (FONT_HEIGHT+VERTICAL_SPACING)*(mCRAWLString.length+1);
100 427ab7bf Leszek Koltunski
   
101 bc0a685b Leszek Koltunski
  private final int GFFA_WIDTH = 600;
102
  private final int GFFA_HEIGHT= (FONT_HEIGHT+VERTICAL_SPACING)*(mGFFAString.length+1);
103 427ab7bf Leszek Koltunski
   
104 bc0a685b Leszek Koltunski
  private final float CRAWL_ANGLE = -30.0f;
105 427ab7bf Leszek Koltunski
   
106 bc0a685b Leszek Koltunski
  private GLSurfaceView mView;
107 f6d884d5 Leszek Koltunski
  private DistortedTexture mScreenTexture, mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture;
108 d04a4886 Leszek Koltunski
  private DistortedEffects mScreenEffects, mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects;
109
  private DistortedEffects[] mStarEffects;
110
  private DistortedTree mRoot, mBackground;
111 d218d64e leszek
  private DistortedScreen mScreen;
112 b01acdaf Leszek Koltunski
  private MeshFlat mQuad;
113 392e16fd Leszek Koltunski
114
  private long gffaID, logoID, crawlID;
115
  private Random mRnd = new Random(0);
116 c4f5a8db Leszek Koltunski
  private int mWidth, mHeight;
117 e8b6aa95 Leszek Koltunski
118 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120 e7a4ef16 Leszek Koltunski
  StarWarsRenderer(GLSurfaceView v)
121 bc0a685b Leszek Koltunski
    {
122
    mView = v;
123 e8b6aa95 Leszek Koltunski
124 b01acdaf Leszek Koltunski
    mQuad = new MeshFlat(1,1);
125 f6d884d5 Leszek Koltunski
126 d04a4886 Leszek Koltunski
    mScreenEffects          = new DistortedEffects();
127
    mGFFAEffects            = new DistortedEffects();
128
    mLogoEffects            = new DistortedEffects();
129
    mCrawlEffects           = new DistortedEffects();
130
    mCrawlBackgroundEffects = new DistortedEffects();
131 f6d884d5 Leszek Koltunski
132 d04a4886 Leszek Koltunski
    mStarEffects = new DistortedEffects[NUM_STARS];
133
    mStarEffects[0] = new DistortedEffects();
134 f6d884d5 Leszek Koltunski
135 d04a4886 Leszek Koltunski
    for(int i=1; i<NUM_STARS; i++) mStarEffects[i] = new DistortedEffects(mStarEffects[0],Distorted.CLONE_VERTEX);
136 f6d884d5 Leszek Koltunski
137 d218d64e leszek
    mScreen = new DistortedScreen();
138 392e16fd Leszek Koltunski
    mScreen.setProjection(60.0f, 0.0f, 0.0f);
139 bc0a685b Leszek Koltunski
    }
140 427ab7bf Leszek Koltunski
141 c4f5a8db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
142
143
  public void onPause()
144
    {
145
    mWidth = 0;
146
    mHeight= 0;
147
    }
148
149 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
150
   
151 bc0a685b Leszek Koltunski
  public void onDrawFrame(GL10 glUnused) 
152
    {
153 41a81a14 Leszek Koltunski
    GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
154 bc29e409 Leszek Koltunski
    mScreen.renderTo(mRoot,System.currentTimeMillis());
155 bc0a685b Leszek Koltunski
    }
156 427ab7bf Leszek Koltunski
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
    
159 bc0a685b Leszek Koltunski
  public void onSurfaceChanged(GL10 glUnused, int width, int height) 
160 b4cc083b Leszek Koltunski
    {
161 c4f5a8db Leszek Koltunski
    if( mWidth!=width || mHeight!=height )  // after onPause() we get 2 calls here
162
      {
163
      mWidth = width;
164
      mHeight= height;
165 b4cc083b Leszek Koltunski
166 392e16fd Leszek Koltunski
      mScreenEffects.abortAllEffects();
167
      mGFFAEffects.abortAllEffects();
168
      mLogoEffects.abortAllEffects();
169
      mCrawlEffects.abortAllEffects();
170
      mCrawlBackgroundEffects.abortAllEffects();
171 b4cc083b Leszek Koltunski
172 d04a4886 Leszek Koltunski
      for(int i=0; i<NUM_STARS; i++) mStarEffects[i].abortAllEffects();
173 b4cc083b Leszek Koltunski
174 c4f5a8db Leszek Koltunski
      setupScreen(width,height);
175
176 392e16fd Leszek Koltunski
      mScreen.resize(width, height);
177 c4f5a8db Leszek Koltunski
      }
178 bc0a685b Leszek Koltunski
    }
179 427ab7bf Leszek Koltunski
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
    
182 bc0a685b Leszek Koltunski
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
183
    {
184 41a81a14 Leszek Koltunski
    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
185 e7a4ef16 Leszek Koltunski
186 bc0a685b Leszek Koltunski
    setupBitmaps();
187 b4cc083b Leszek Koltunski
188 bc0a685b Leszek Koltunski
    try
189
      {
190 76f9798b Leszek Koltunski
      Distorted.onCreate(mView.getContext());
191 bc0a685b Leszek Koltunski
      }
192
    catch(Exception ex)
193
      {
194
      android.util.Log.e("Star Wars", ex.getMessage() );
195 427ab7bf Leszek Koltunski
      }
196 bc0a685b Leszek Koltunski
    }
197 427ab7bf Leszek Koltunski
    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
200 bc0a685b Leszek Koltunski
  private void setupScreen(int w, int h)
201
    {
202 7451c98a Leszek Koltunski
    mScreenTexture = new DistortedTexture(w,h);
203 d04a4886 Leszek Koltunski
    mRoot = new DistortedTree(mScreenTexture, mScreenEffects,mQuad);
204 427ab7bf Leszek Koltunski
      
205 7451c98a Leszek Koltunski
    mCrawlBackgroundTexture = new DistortedTexture(w,(int)(Math.sqrt(3.0)*h));
206 427ab7bf Leszek Koltunski
       
207 bc0a685b Leszek Koltunski
    int randomA, randomX, randomY, randomTime;
208
    float randomS, randomAlpha1, randomAlpha2;
209 427ab7bf Leszek Koltunski
       
210 7589635e Leszek Koltunski
    Static3D center = new Static3D(0,0,0);
211
    Static3D axis   = new Static3D(0,0,1);
212 9ff0c8c3 Leszek Koltunski
    Static1D alphaNoise = new Static1D(0.4f);
213
214 bc0a685b Leszek Koltunski
    for(int i=0; i<NUM_STARS; i++)
215
      {
216
      randomX = mRnd.nextInt(w);
217
      randomY = mRnd.nextInt(h);
218 f6d884d5 Leszek Koltunski
      randomS = 0.2f+ 0.8f*mRnd.nextFloat();
219 bc0a685b Leszek Koltunski
      randomA = (int)(180*mRnd.nextFloat());
220
      randomAlpha1 = 0.2f + 0.8f*mRnd.nextFloat();
221
      randomAlpha2 = 0.8f + 0.2f*mRnd.nextFloat();
222
      randomTime = 500+mRnd.nextInt(2000);
223 427ab7bf Leszek Koltunski
      
224 d04a4886 Leszek Koltunski
      mStarEffects[i].move( new Static3D(randomX,randomY,0) );
225
      mStarEffects[i].scale(randomS);
226
      mStarEffects[i].rotate( new Static1D(randomA), axis, center );
227 427ab7bf Leszek Koltunski
      
228 f988589e Leszek Koltunski
      Dynamic1D di = new Dynamic1D(randomTime,0.0f);
229 9ff0c8c3 Leszek Koltunski
      di.setNoise(alphaNoise);
230 7589635e Leszek Koltunski
      di.add(new Static1D(randomAlpha1));
231
      di.add(new Static1D(randomAlpha2));
232 427ab7bf Leszek Koltunski
      
233 d04a4886 Leszek Koltunski
      mStarEffects[i].alpha(di);
234 427ab7bf Leszek Koltunski
      
235 d04a4886 Leszek Koltunski
      mRoot.attach(mStarTexture, mStarEffects[i], mQuad);
236 427ab7bf Leszek Koltunski
      }
237 bc0a685b Leszek Koltunski
      
238 f6d884d5 Leszek Koltunski
    float scale = (0.5f*w/mGFFATexture.getWidth());
239 bc0a685b Leszek Koltunski
    
240 f988589e Leszek Koltunski
    Dynamic1D di = new Dynamic1D(6000,0.5f);
241 7589635e Leszek Koltunski
    di.add(new Static1D(1.0f));
242
    di.add(new Static1D(1.0f));
243
    di.add(new Static1D(0.0f));
244 bc0a685b Leszek Koltunski
    
245 392e16fd Leszek Koltunski
    mGFFAEffects.move( new Static3D(w/5,h/3,0) );
246
    mGFFAEffects.scale( new Static3D(scale,scale,scale) );
247
    mGFFAEffects.alpha(di);
248 bc0a685b Leszek Koltunski
      
249 392e16fd Leszek Koltunski
    mRoot.attach(mGFFATexture, mGFFAEffects, mQuad);
250
    mGFFAEffects.registerForMessages(this);
251 bc0a685b Leszek Koltunski
    }
252 427ab7bf Leszek Koltunski
    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255 bc0a685b Leszek Koltunski
  private void setupBitmaps()
256
    {
257
    InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.starwars);
258
    InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.star);
259 427ab7bf Leszek Koltunski
    
260 bc0a685b Leszek Koltunski
    Bitmap bitmapStar, bitmapGFFA, bitmapLogo, bitmapText;
261
      
262
    try 
263
      {
264
      bitmapLogo = BitmapFactory.decodeStream(is1);
265
      bitmapStar = BitmapFactory.decodeStream(is2);
266
      } 
267
    finally 
268
      {
269 427ab7bf Leszek Koltunski
      try 
270
        {
271 bc0a685b Leszek Koltunski
        is1.close();
272
        is2.close();
273 427ab7bf Leszek Koltunski
        } 
274 bc0a685b Leszek Koltunski
      catch(IOException e) { }
275
      } 
276 427ab7bf Leszek Koltunski
      
277 bc0a685b Leszek Koltunski
    Paint paint = new Paint();
278
    paint.setAntiAlias(true);
279
    paint.setTextAlign(Paint.Align.LEFT);
280
    paint.setTextSize(FONT_HEIGHT);
281
    paint.setColor(GFFA_COLOR);
282 427ab7bf Leszek Koltunski
      
283 bc0a685b Leszek Koltunski
    Typeface tf = Typeface.create(CRAWL_TYPEFACE, Typeface.BOLD);
284
    paint.setTypeface(tf);     
285 427ab7bf Leszek Koltunski
 
286 bc0a685b Leszek Koltunski
    ///// create GFFA ///////////////////
287 7451c98a Leszek Koltunski
    mGFFATexture  = new DistortedTexture(GFFA_WIDTH,GFFA_HEIGHT);
288 bc0a685b Leszek Koltunski
    bitmapGFFA = Bitmap.createBitmap(GFFA_WIDTH,GFFA_HEIGHT,Bitmap.Config.ARGB_8888);
289
    bitmapGFFA.eraseColor(0x00000000);
290
    Canvas gffaCanvas = new Canvas(bitmapGFFA);
291 427ab7bf Leszek Koltunski
      
292 bc0a685b Leszek Koltunski
    for(int i=0; i<mGFFAString.length; i++)
293
      {
294
      gffaCanvas.drawText(mGFFAString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), paint);  
295
      }
296 427ab7bf Leszek Koltunski
  
297 f6d884d5 Leszek Koltunski
    mGFFATexture.setTexture(bitmapGFFA);
298 427ab7bf Leszek Koltunski
      
299 bc0a685b Leszek Koltunski
    ///// create Logo ///////////////////
300 7451c98a Leszek Koltunski
    mLogoTexture  = new DistortedTexture(bitmapLogo.getWidth(),bitmapLogo.getHeight());
301 f6d884d5 Leszek Koltunski
    mLogoTexture.setTexture(bitmapLogo);
302 e8b6aa95 Leszek Koltunski
303 bc0a685b Leszek Koltunski
    ///// create CRAWL //////////////////
304 7451c98a Leszek Koltunski
    mCrawlTexture = new DistortedTexture(CRAWL_WIDTH,CRAWL_HEIGHT);
305 bc0a685b Leszek Koltunski
    bitmapText = Bitmap.createBitmap(CRAWL_WIDTH,CRAWL_HEIGHT,Bitmap.Config.ARGB_8888);
306
    bitmapText.eraseColor(0x00000000);
307
    Canvas textCanvas = new Canvas(bitmapText);
308
    paint.setColor(CRAWL_COLOR);
309 427ab7bf Leszek Koltunski
  
310 bc0a685b Leszek Koltunski
    for(int i=0; i<mCRAWLString.length; i++)
311
      {
312
      displayJustified(mCRAWLString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), CRAWL_WIDTH, textCanvas, paint);  
313
      }
314 427ab7bf Leszek Koltunski
      
315 f6d884d5 Leszek Koltunski
    mCrawlTexture.setTexture(bitmapText);
316 427ab7bf Leszek Koltunski
      
317 bc0a685b Leszek Koltunski
    ///// create Stars ///////////////////
318 7451c98a Leszek Koltunski
    mStarTexture = new DistortedTexture(bitmapStar.getWidth(),bitmapStar.getHeight());
319 f6d884d5 Leszek Koltunski
    mStarTexture.setTexture(bitmapStar);
320 e8b6aa95 Leszek Koltunski
321 392e16fd Leszek Koltunski
    gffaID = mGFFAEffects.getID();
322
    logoID = mLogoEffects.getID();
323
    crawlID= mCrawlEffects.getID();
324 bc0a685b Leszek Koltunski
    }
325 427ab7bf Leszek Koltunski
 
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328 bc0a685b Leszek Koltunski
  private void displayJustified(String str, int x, int y, int length, Canvas c, Paint paint)
329
    { 
330
    int len       = str.length();
331
    int numspaces = retNumSpaces(str);
332 427ab7bf Leszek Koltunski
    
333 bc0a685b Leszek Koltunski
    if( len>0 && str.charAt(len-1) == ' ' ) numspaces--;
334 427ab7bf Leszek Koltunski
335 bc0a685b Leszek Koltunski
    float left=x,w = (numspaces>0 ? (length-paint.measureText(str))/numspaces : 0);
336
    String tmp;
337
    int begin,end=0;
338 427ab7bf Leszek Koltunski
339 bc0a685b Leszek Koltunski
    while( end<len )
340
      {
341
      begin=end;
342
      end = str.indexOf(' ', begin)+1;
343
      if( end<=0 ) end = len;
344 427ab7bf Leszek Koltunski
345 bc0a685b Leszek Koltunski
      tmp = str.substring(begin,end);
346
      c.drawText( tmp, left, y, paint);
347
      left+= (paint.measureText(tmp)+w);
348
      }  
349
    }
350 427ab7bf Leszek Koltunski
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352
   
353 bc0a685b Leszek Koltunski
  private int retNumSpaces(String str)
354
    {
355
    int begin=0, ret=0;
356 427ab7bf Leszek Koltunski
357 bc0a685b Leszek Koltunski
    while( true )
358
      {
359
      begin = str.indexOf(' ', begin) +1;
360 427ab7bf Leszek Koltunski
361 bc0a685b Leszek Koltunski
      if( begin>0 ) ret++;
362
      else break;
363 427ab7bf Leszek Koltunski
      }
364 bc0a685b Leszek Koltunski
365
    return ret;
366
    }
367 427ab7bf Leszek Koltunski
    
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369 c5a28eb8 Leszek Koltunski
// the library sending messages to us. This is running on a library 'MessageSender' thread.
370 427ab7bf Leszek Koltunski
371 9d12dd4a Leszek Koltunski
  public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID)
372 bc0a685b Leszek Koltunski
    {
373
    if( em==EffectMessage.EFFECT_FINISHED )
374 427ab7bf Leszek Koltunski
      {
375 c5a28eb8 Leszek Koltunski
      if( objectID == gffaID )
376 427ab7bf Leszek Koltunski
        {
377 392e16fd Leszek Koltunski
        mRoot.detach(mGFFAEffects);
378
        mGFFAEffects.abortAllEffects();
379 3c8b1903 Leszek Koltunski
        mGFFATexture.markForDeletion();
380 611ea379 Leszek Koltunski
381 f6d884d5 Leszek Koltunski
        int screenW=mScreenTexture.getWidth();
382
        int screenH=mScreenTexture.getHeight();
383 427ab7bf Leszek Koltunski
        
384 f6d884d5 Leszek Koltunski
        int logoW = mLogoTexture.getWidth();
385
        int logoH = mLogoTexture.getHeight();
386 427ab7bf Leszek Koltunski
      
387 bc0a685b Leszek Koltunski
        int initSize= (int)(3.0f*screenW/logoW);
388
        int finaSize= (int)(0.1f*screenW/logoW);
389 427ab7bf Leszek Koltunski
      
390 f988589e Leszek Koltunski
        Dynamic3D di = new Dynamic3D(10000,0.5f);
391 7589635e Leszek Koltunski
        di.add(new Static3D(initSize,initSize,1));
392
        di.add(new Static3D(finaSize,finaSize,1));
393 f988589e Leszek Koltunski
394 392e16fd Leszek Koltunski
        mLogoEffects.move( new Static3D(screenW/2,screenH/2,0) );
395
        mLogoEffects.scale(di);
396
        mLogoEffects.move( new Static3D(-logoW/2,-logoH/2,0) );
397 427ab7bf Leszek Koltunski
      
398 392e16fd Leszek Koltunski
        mRoot.attach(mLogoTexture, mLogoEffects,mQuad);
399
        mLogoEffects.registerForMessages(this);
400 bc0a685b Leszek Koltunski
        }
401 c5a28eb8 Leszek Koltunski
      else if( objectID==logoID )
402 bc0a685b Leszek Koltunski
        {
403 392e16fd Leszek Koltunski
        mRoot.detach(mLogoEffects);
404
        mLogoEffects.abortAllEffects();
405 3c8b1903 Leszek Koltunski
        mLogoTexture.markForDeletion();
406 427ab7bf Leszek Koltunski
        
407 f6d884d5 Leszek Koltunski
        int crawlW = mCrawlTexture.getWidth();
408
        int crawlH = mCrawlTexture.getHeight();
409
        int screenW= mScreenTexture.getWidth();
410
        int screenH= mScreenTexture.getHeight();
411
        int backH  = mCrawlBackgroundTexture.getHeight();
412 bc0a685b Leszek Koltunski
        float scale= (float)screenW/crawlW;
413
      
414 f988589e Leszek Koltunski
        Dynamic3D di = new Dynamic3D(60000,0.5f);
415 7589635e Leszek Koltunski
        di.add(new Static3D(screenW/2,+backH       , 0));
416
        di.add(new Static3D(screenW/2,-scale*crawlH, 0));
417 427ab7bf Leszek Koltunski
        
418 392e16fd Leszek Koltunski
        mCrawlBackgroundEffects.move( new Static3D(0,screenH-backH,0) );
419
        mCrawlBackgroundEffects.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,backH,0) );
420 427ab7bf Leszek Koltunski
        
421 59759251 Leszek Koltunski
        final int transpDist = 5;
422
        Static4D region = new Static4D(screenW/2,(1-transpDist)*backH,transpDist*backH,transpDist*backH);
423 392e16fd Leszek Koltunski
        mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist/2), region, true);
424 427ab7bf Leszek Koltunski
        
425 392e16fd Leszek Koltunski
        mCrawlEffects.move(di);
426
        mCrawlEffects.scale( new Static3D(scale,scale,scale) );
427
        mCrawlEffects.move( new Static3D(-crawlW/2,0,0) );
428 427ab7bf Leszek Koltunski
        
429 392e16fd Leszek Koltunski
        mBackground = mRoot.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
430
        mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
431
        mCrawlEffects.registerForMessages(this);
432 bc0a685b Leszek Koltunski
        }
433 c5a28eb8 Leszek Koltunski
      else if( objectID==crawlID )
434 bc0a685b Leszek Koltunski
        {
435
        mRoot.detach(mBackground);
436 392e16fd Leszek Koltunski
        mBackground.detach(mCrawlEffects);
437
        mCrawlEffects.abortAllEffects();
438 3c8b1903 Leszek Koltunski
        mCrawlTexture.markForDeletion();
439 392e16fd Leszek Koltunski
        mCrawlBackgroundEffects.abortAllEffects();
440 3c8b1903 Leszek Koltunski
        mCrawlBackgroundTexture.markForDeletion();
441 427ab7bf Leszek Koltunski
        }
442
      }
443 bc0a685b Leszek Koltunski
    }
444
  }