Project

General

Profile

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

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

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