Project

General

Profile

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

examples / src / main / java / org / distorted / examples / starwars / StarWarsRenderer.java @ 107e4b72

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