Project

General

Profile

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

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

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 71c8884f Leszek Koltunski
// This file is part of Distorted.                                                               //
5 bc0a685b Leszek Koltunski
//                                                                                               //
6 71c8884f Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 bc0a685b Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 bc0a685b Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 f3ca895f Leszek Koltunski
import org.distorted.library.mesh.MeshRectangles;
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 13efa930 Leszek Koltunski
import org.distorted.library.message.EffectListener;
43 e3900503 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
44 01782e85 Leszek Koltunski
import org.distorted.library.main.DistortedTexture;
45
import org.distorted.library.main.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 41a85bb7 Leszek Koltunski
import android.opengl.GLES31;
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 76f2d645 leszek
  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 2f7afccf leszek
  private final float FOV_ANGLE   =  60.0f;
106
107 bc0a685b Leszek Koltunski
  private GLSurfaceView mView;
108 d2aee6cc leszek
  private DistortedTexture mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture;
109
  private DistortedEffects mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects;
110 d04a4886 Leszek Koltunski
  private DistortedEffects[] mStarEffects;
111 d2aee6cc leszek
  private DistortedNode mBackground;
112 d218d64e leszek
  private DistortedScreen mScreen;
113 f3ca895f Leszek Koltunski
  private MeshRectangles mQuad;
114 392e16fd Leszek Koltunski
115 8d5a8e06 Leszek Koltunski
  private long alphaEffectID, scaleEffectID, moveEffectID;
116 392e16fd Leszek Koltunski
  private Random mRnd = new Random(0);
117 c4f5a8db Leszek Koltunski
  private int mWidth, mHeight;
118 e8b6aa95 Leszek Koltunski
119 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121 e7a4ef16 Leszek Koltunski
  StarWarsRenderer(GLSurfaceView v)
122 bc0a685b Leszek Koltunski
    {
123
    mView = v;
124 e8b6aa95 Leszek Koltunski
125 f3ca895f Leszek Koltunski
    mQuad = new MeshRectangles(1,1);
126 f6d884d5 Leszek Koltunski
127 d04a4886 Leszek Koltunski
    mGFFAEffects            = new DistortedEffects();
128
    mLogoEffects            = new DistortedEffects();
129
    mCrawlEffects           = new DistortedEffects();
130
    mCrawlBackgroundEffects = new DistortedEffects();
131 f6d884d5 Leszek Koltunski
132 3f5b2cb3 leszek
    if( NUM_STARS>0 )
133
      {
134
      mStarEffects = new DistortedEffects[NUM_STARS];
135
      mStarEffects[0] = new DistortedEffects();
136 f6d884d5 Leszek Koltunski
137 3f5b2cb3 leszek
      for (int i = 1; i < NUM_STARS; i++)
138 e3900503 Leszek Koltunski
        mStarEffects[i] = new DistortedEffects(mStarEffects[0], DistortedLibrary.CLONE_VERTEX);
139 3f5b2cb3 leszek
      }
140 f6d884d5 Leszek Koltunski
141 e4330c89 Leszek Koltunski
    mScreen = new DistortedScreen();
142 2f7afccf leszek
    mScreen.setProjection(FOV_ANGLE, 0.02f);
143 bc0a685b Leszek Koltunski
    }
144 427ab7bf Leszek Koltunski
145 c4f5a8db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
  public void onPause()
148
    {
149
    mWidth = 0;
150
    mHeight= 0;
151
    }
152
153 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
154
   
155 bc0a685b Leszek Koltunski
  public void onDrawFrame(GL10 glUnused) 
156
    {
157 fe59d375 Leszek Koltunski
    mScreen.render(System.currentTimeMillis());
158 bc0a685b Leszek Koltunski
    }
159 427ab7bf Leszek Koltunski
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
    
162 bc0a685b Leszek Koltunski
  public void onSurfaceChanged(GL10 glUnused, int width, int height) 
163 b4cc083b Leszek Koltunski
    {
164 c4f5a8db Leszek Koltunski
    if( mWidth!=width || mHeight!=height )  // after onPause() we get 2 calls here
165
      {
166
      mWidth = width;
167
      mHeight= height;
168 b4cc083b Leszek Koltunski
169 392e16fd Leszek Koltunski
      mGFFAEffects.abortAllEffects();
170
      mLogoEffects.abortAllEffects();
171
      mCrawlEffects.abortAllEffects();
172
      mCrawlBackgroundEffects.abortAllEffects();
173 b4cc083b Leszek Koltunski
174 d04a4886 Leszek Koltunski
      for(int i=0; i<NUM_STARS; i++) mStarEffects[i].abortAllEffects();
175 b4cc083b Leszek Koltunski
176 fe59d375 Leszek Koltunski
      mScreen.detachAll();
177 d2aee6cc leszek
      setupScreen(width,height);
178 392e16fd Leszek Koltunski
      mScreen.resize(width, height);
179 c4f5a8db Leszek Koltunski
      }
180 bc0a685b Leszek Koltunski
    }
181 427ab7bf Leszek Koltunski
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
    
184 bc0a685b Leszek Koltunski
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
185
    {
186
    setupBitmaps();
187 b4cc083b Leszek Koltunski
188 885b9cca leszek
    FragmentEffectAlpha.enable();
189 6637d0f2 Leszek Koltunski
190 bc0a685b Leszek Koltunski
    try
191
      {
192 e3900503 Leszek Koltunski
      DistortedLibrary.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 630703d1 leszek
    int randomA, randomX, randomY, randomTime;
211
    float randomS, randomAlpha1, randomAlpha2;
212
       
213
    Static3D center = new Static3D(0,0,0);
214
    Static3D axis   = new Static3D(0,0,1);
215 9ff0c8c3 Leszek Koltunski
    Static1D alphaNoise = new Static1D(0.4f);
216
217 bc0a685b Leszek Koltunski
    for(int i=0; i<NUM_STARS; i++)
218
      {
219 630703d1 leszek
      randomX = mRnd.nextInt(w);
220
      randomY = mRnd.nextInt(h);
221 f6d884d5 Leszek Koltunski
      randomS = 0.2f+ 0.8f*mRnd.nextFloat();
222 630703d1 leszek
      randomA = (int)(180*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 dae661e9 Leszek Koltunski
227 fc448f77 Leszek Koltunski
      mStarEffects[i].apply( new MatrixEffectRotate(new Static1D(randomA), axis, center) );
228 dae661e9 Leszek Koltunski
      mStarEffects[i].apply( new MatrixEffectScale(randomS) );
229
      mStarEffects[i].apply( new MatrixEffectMove(new Static3D(randomX,randomY,0)) );
230
231 f988589e Leszek Koltunski
      Dynamic1D di = new Dynamic1D(randomTime,0.0f);
232 9ff0c8c3 Leszek Koltunski
      di.setNoise(alphaNoise);
233 7589635e Leszek Koltunski
      di.add(new Static1D(randomAlpha1));
234
      di.add(new Static1D(randomAlpha2));
235 427ab7bf Leszek Koltunski
      
236 fc448f77 Leszek Koltunski
      mStarEffects[i].apply( new FragmentEffectAlpha(di) );
237 427ab7bf Leszek Koltunski
      
238 d2aee6cc leszek
      mScreen.attach(mStarTexture, mStarEffects[i], mQuad);
239 427ab7bf Leszek Koltunski
      }
240 630703d1 leszek
      
241
    float scale = (0.5f*w/mGFFATexture.getWidth());
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 8d5a8e06 Leszek Koltunski
248
    FragmentEffectAlpha alpha = new FragmentEffectAlpha(di);
249
    alpha.notifyWhenFinished(this);
250
    alphaEffectID = alpha.getID();
251
252 fc448f77 Leszek Koltunski
    mGFFAEffects.apply( new MatrixEffectScale(scale) );
253 dae661e9 Leszek Koltunski
    mGFFAEffects.apply( new MatrixEffectMove(new Static3D(w/5,2*h/3,0)) );
254 8d5a8e06 Leszek Koltunski
    mGFFAEffects.apply( alpha );
255 bc0a685b Leszek Koltunski
      
256 d2aee6cc leszek
    mScreen.attach(mGFFATexture, mGFFAEffects, mQuad);
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 bc0a685b Leszek Koltunski
    }
327 427ab7bf Leszek Koltunski
 
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
330 bc0a685b Leszek Koltunski
  private void displayJustified(String str, int x, int y, int length, Canvas c, Paint paint)
331
    { 
332
    int len       = str.length();
333
    int numspaces = retNumSpaces(str);
334 427ab7bf Leszek Koltunski
    
335 bc0a685b Leszek Koltunski
    if( len>0 && str.charAt(len-1) == ' ' ) numspaces--;
336 427ab7bf Leszek Koltunski
337 bc0a685b Leszek Koltunski
    float left=x,w = (numspaces>0 ? (length-paint.measureText(str))/numspaces : 0);
338
    String tmp;
339
    int begin,end=0;
340 427ab7bf Leszek Koltunski
341 bc0a685b Leszek Koltunski
    while( end<len )
342
      {
343
      begin=end;
344
      end = str.indexOf(' ', begin)+1;
345
      if( end<=0 ) end = len;
346 427ab7bf Leszek Koltunski
347 bc0a685b Leszek Koltunski
      tmp = str.substring(begin,end);
348
      c.drawText( tmp, left, y, paint);
349
      left+= (paint.measureText(tmp)+w);
350
      }  
351
    }
352 427ab7bf Leszek Koltunski
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354
   
355 bc0a685b Leszek Koltunski
  private int retNumSpaces(String str)
356
    {
357
    int begin=0, ret=0;
358 427ab7bf Leszek Koltunski
359 bc0a685b Leszek Koltunski
    while( true )
360
      {
361
      begin = str.indexOf(' ', begin) +1;
362 427ab7bf Leszek Koltunski
363 bc0a685b Leszek Koltunski
      if( begin>0 ) ret++;
364
      else break;
365 427ab7bf Leszek Koltunski
      }
366 bc0a685b Leszek Koltunski
367
    return ret;
368
    }
369 427ab7bf Leszek Koltunski
    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
372 8d5a8e06 Leszek Koltunski
  public void effectFinished(final long effectID)
373 bc0a685b Leszek Koltunski
    {
374 8d5a8e06 Leszek Koltunski
    if( effectID == alphaEffectID )
375 427ab7bf Leszek Koltunski
      {
376 8d5a8e06 Leszek Koltunski
      mScreen.detach(mGFFAEffects);
377
      mGFFATexture.markForDeletion();
378 611ea379 Leszek Koltunski
379 8d5a8e06 Leszek Koltunski
      int screenW=mScreen.getWidth();
380
      int screenH=mScreen.getHeight();
381 630703d1 leszek
        
382 8d5a8e06 Leszek Koltunski
      int logoW = mLogoTexture.getWidth();
383
      int logoH = mLogoTexture.getHeight();
384 630703d1 leszek
      
385 8d5a8e06 Leszek Koltunski
      int initSize= (int)(3.0f*screenW/logoW);
386
      int finaSize= (int)(0.1f*screenW/logoW);
387 427ab7bf Leszek Koltunski
      
388 8d5a8e06 Leszek Koltunski
      Dynamic3D di = new Dynamic3D(10000,0.5f);
389
      di.add(new Static3D(initSize,initSize,1));
390
      di.add(new Static3D(finaSize,finaSize,1));
391
      MatrixEffectScale scale = new MatrixEffectScale(di);
392
      scale.notifyWhenFinished(this);
393
      scaleEffectID = scale.getID();
394
395
      mLogoEffects.apply( new MatrixEffectMove(new Static3D(-logoW/2,-logoH/2,0)) );
396 dae661e9 Leszek Koltunski
      mLogoEffects.apply( scale );
397
      mLogoEffects.apply( new MatrixEffectMove(new Static3D(screenW/2,screenH/2,0)) );
398
399 8d5a8e06 Leszek Koltunski
      mScreen.attach(mLogoTexture, mLogoEffects,mQuad);
400
      }
401
    else if( effectID == scaleEffectID )
402
      {
403
      mScreen.detach(mLogoEffects);
404
      mLogoTexture.markForDeletion();
405 427ab7bf Leszek Koltunski
        
406 8d5a8e06 Leszek Koltunski
      int crawlW = mCrawlTexture.getWidth();
407
      int crawlH = mCrawlTexture.getHeight();
408
      int screenW= mScreen.getWidth();
409
      int backH  = mCrawlBackgroundTexture.getHeight();
410
      float scale= (float)screenW/crawlW;
411
412
      mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(screenW/2,0,0)) );
413
414
      final int transpDist = 5;
415
      Static3D center = new Static3D( screenW/2 , transpDist*backH , 0 );
416
      Static3D region = new Static3D( transpDist*backH , transpDist*backH , transpDist*backH );
417
      mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) );
418
419
      Dynamic3D di = new Dynamic3D(70000,0.5f);
420
      di.add(new Static3D(screenW/2,-scale*crawlH/2        , 0));
421
      di.add(new Static3D(screenW/2,+scale*crawlH/2 + backH, 0));
422
      MatrixEffectMove move = new MatrixEffectMove(di);
423
      move.notifyWhenFinished(this);
424
      moveEffectID = move.getID();
425
426
      mCrawlEffects.apply( new MatrixEffectMove(new Static3D(-crawlW/2,-crawlH/2,0)) );
427 dae661e9 Leszek Koltunski
      mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale,scale,scale)) );
428
      mCrawlEffects.apply( move );
429
430 8d5a8e06 Leszek Koltunski
      mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
431
      mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
432
      mBackground.glDisable(GLES31.GL_DEPTH_TEST);
433
      mBackground.glDepthMask(false);
434
      }
435
    else if( effectID == moveEffectID )
436
      {
437
      mScreen.detach(mBackground);
438
      mBackground.detach(mCrawlEffects);
439
      mCrawlTexture.markForDeletion();
440
      mCrawlBackgroundEffects.abortAllEffects();
441
      mCrawlBackgroundTexture.markForDeletion();
442 427ab7bf Leszek Koltunski
      }
443 bc0a685b Leszek Koltunski
    }
444
  }