Project

General

Profile

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

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

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