Project

General

Profile

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

examples / src / main / java / org / distorted / examples / starwars / StarWarsRenderer.java @ 625c67de

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 698ad0a8 Leszek Koltunski
import org.distorted.library.mesh.MeshQuad;
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 dc10a48d Leszek Koltunski
import android.app.ActivityManager;
48
import android.content.Context;
49
import android.content.pm.ConfigurationInfo;
50
import android.content.res.Resources;
51 427ab7bf Leszek Koltunski
import android.graphics.Bitmap;
52
import android.graphics.BitmapFactory;
53
import android.graphics.Canvas;
54
import android.graphics.Paint;
55
import android.graphics.Typeface;
56 41a85bb7 Leszek Koltunski
import android.opengl.GLES31;
57 427ab7bf Leszek Koltunski
import android.opengl.GLSurfaceView;
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 dc10a48d Leszek Koltunski
class StarWarsRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.LibraryUser
62 bc0a685b Leszek Koltunski
  {
63
  private final String[] mGFFAString = 
64 427ab7bf Leszek Koltunski
         
65
            { "A long time ago, in a galaxy far,",
66
              "far away...." };                    // yes, there really was a four-dot ellipsis
67
68 bc0a685b Leszek Koltunski
  private final String[] mCRAWLString = 
69 427ab7bf Leszek Koltunski
      
70
            { "It is a period of civil war.",      // in the original 1977 version, there was no 
71
              "Rebel spaceships, striking",        // 'Episode IV New Hope' subtitle line before
72
              "from a hidden base, have",          // the crawl. Lets keep to the classic.
73
              "won their first victory",
74
              "against the evil Galactic",
75
              "Empire.",
76
              "",
77
              "During the battle, rebel",
78
              "spies managed to steal",
79
              "secret plans to the Empire's",
80
              "ultimate weapon, the",
81
              "DEATH STAR, an armored",
82
              "space station with enough",
83
              "power to destroy an entire",
84
              "planet.",
85
              "",
86
              "Pursued by the Empire's",
87
              "sinister agents, Princess",
88
              "Leia races home aboard her",
89
              "starship, custodian of the",
90
              "stolen plans that can save",
91
              "her people and restore",
92
              "freedom to the galaxy...." };      // four-dot.
93
   
94 76f2d645 leszek
  private final int NUM_STARS = 40;
95 427ab7bf Leszek Koltunski
   
96 bc0a685b Leszek Koltunski
  private final int CRAWL_COLOR = 0xffffe81f;
97
  private final int GFFA_COLOR  = 0xff0000ff;
98
  private final int FONT_HEIGHT      = 40;
99
  private final int VERTICAL_SPACING = 10;
100
  private final String CRAWL_TYPEFACE = "News Gothic";
101 427ab7bf Leszek Koltunski
   
102 bc0a685b Leszek Koltunski
  private final int CRAWL_WIDTH = 500;
103
  private final int CRAWL_HEIGHT= (FONT_HEIGHT+VERTICAL_SPACING)*(mCRAWLString.length+1);
104 427ab7bf Leszek Koltunski
   
105 bc0a685b Leszek Koltunski
  private final int GFFA_WIDTH = 600;
106
  private final int GFFA_HEIGHT= (FONT_HEIGHT+VERTICAL_SPACING)*(mGFFAString.length+1);
107 427ab7bf Leszek Koltunski
   
108 bc0a685b Leszek Koltunski
  private final float CRAWL_ANGLE = -30.0f;
109 2f7afccf leszek
  private final float FOV_ANGLE   =  60.0f;
110
111 dc10a48d Leszek Koltunski
  private final GLSurfaceView mView;
112
  private final DistortedEffects mGFFAEffects, mLogoEffects, mCrawlEffects, mCrawlBackgroundEffects;
113
  private final DistortedEffects[] mStarEffects;
114
  private final DistortedScreen mScreen;
115
  private final MeshQuad mQuad;
116
  private final Random mRnd = new Random(0);
117
  private final Resources mResources;
118
119 d2aee6cc leszek
  private DistortedTexture mGFFATexture, mLogoTexture, mCrawlTexture, mCrawlBackgroundTexture, mStarTexture;
120
  private DistortedNode mBackground;
121 8d5a8e06 Leszek Koltunski
  private long alphaEffectID, scaleEffectID, moveEffectID;
122 c4f5a8db Leszek Koltunski
  private int mWidth, mHeight;
123 5a683295 Leszek Koltunski
  private float mLogoRatio;
124
  private int mCrawlBackgroundW, mCrawlBackgroundH;
125 e8b6aa95 Leszek Koltunski
126 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
127
128 e7a4ef16 Leszek Koltunski
  StarWarsRenderer(GLSurfaceView v)
129 bc0a685b Leszek Koltunski
    {
130
    mView = v;
131 dc10a48d Leszek Koltunski
    mResources = v.getResources();
132 e8b6aa95 Leszek Koltunski
133 5a683295 Leszek Koltunski
    mQuad = new MeshQuad();
134 698ad0a8 Leszek Koltunski
135
    mGFFAEffects            = new DistortedEffects();
136
    mLogoEffects            = new DistortedEffects();
137
    mCrawlEffects           = new DistortedEffects();
138
    mCrawlBackgroundEffects = new DistortedEffects();
139 f6d884d5 Leszek Koltunski
140 3f5b2cb3 leszek
    if( NUM_STARS>0 )
141
      {
142
      mStarEffects = new DistortedEffects[NUM_STARS];
143 698ad0a8 Leszek Koltunski
      mStarEffects[0] = new DistortedEffects();
144 f6d884d5 Leszek Koltunski
145 3f5b2cb3 leszek
      for (int i = 1; i < NUM_STARS; i++)
146 e3900503 Leszek Koltunski
        mStarEffects[i] = new DistortedEffects(mStarEffects[0], DistortedLibrary.CLONE_VERTEX);
147 3f5b2cb3 leszek
      }
148 f6d884d5 Leszek Koltunski
149 e4330c89 Leszek Koltunski
    mScreen = new DistortedScreen();
150 2f7afccf leszek
    mScreen.setProjection(FOV_ANGLE, 0.02f);
151 bc0a685b Leszek Koltunski
    }
152 427ab7bf Leszek Koltunski
153 c4f5a8db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155
  public void onPause()
156
    {
157
    mWidth = 0;
158
    mHeight= 0;
159
    }
160
161 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
162
   
163 bc0a685b Leszek Koltunski
  public void onDrawFrame(GL10 glUnused) 
164
    {
165 fe59d375 Leszek Koltunski
    mScreen.render(System.currentTimeMillis());
166 bc0a685b Leszek Koltunski
    }
167 427ab7bf Leszek Koltunski
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
    
170 bc0a685b Leszek Koltunski
  public void onSurfaceChanged(GL10 glUnused, int width, int height) 
171 b4cc083b Leszek Koltunski
    {
172 c4f5a8db Leszek Koltunski
    if( mWidth!=width || mHeight!=height )  // after onPause() we get 2 calls here
173
      {
174
      mWidth = width;
175
      mHeight= height;
176 b4cc083b Leszek Koltunski
177 392e16fd Leszek Koltunski
      mGFFAEffects.abortAllEffects();
178
      mLogoEffects.abortAllEffects();
179
      mCrawlEffects.abortAllEffects();
180
      mCrawlBackgroundEffects.abortAllEffects();
181 b4cc083b Leszek Koltunski
182 d04a4886 Leszek Koltunski
      for(int i=0; i<NUM_STARS; i++) mStarEffects[i].abortAllEffects();
183 b4cc083b Leszek Koltunski
184 fe59d375 Leszek Koltunski
      mScreen.detachAll();
185 d2aee6cc leszek
      setupScreen(width,height);
186 392e16fd Leszek Koltunski
      mScreen.resize(width, height);
187 c4f5a8db Leszek Koltunski
      }
188 bc0a685b Leszek Koltunski
    }
189 427ab7bf Leszek Koltunski
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
    
192 bc0a685b Leszek Koltunski
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
193
    {
194
    setupBitmaps();
195 885b9cca leszek
    FragmentEffectAlpha.enable();
196 dc10a48d Leszek Koltunski
    DistortedLibrary.onSurfaceCreated(this);
197 bc0a685b Leszek Koltunski
    }
198 061449ed Leszek Koltunski
199 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
200
201 16b22aab Leszek Koltunski
  private void setupScreen(int scrW, int scrH)
202 bc0a685b Leszek Koltunski
    {
203 16b22aab Leszek Koltunski
    double angleA = (90.0f - FOV_ANGLE/2              ) * Math.PI/180;
204
    double angleB = (90.0f - FOV_ANGLE/2 + CRAWL_ANGLE) * Math.PI/180;
205 2f7afccf leszek
206 59540ba2 Leszek Koltunski
    if( mCrawlBackgroundTexture!=null ) mCrawlBackgroundTexture.markForDeletion();
207 687263cc Leszek Koltunski
    mCrawlBackgroundTexture = new DistortedTexture();
208
209 5a683295 Leszek Koltunski
    mCrawlBackgroundW = scrW;
210
    mCrawlBackgroundH = (int)(scrH*Math.sin(angleA)/Math.sin(angleB));
211 e8e54972 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 16b22aab Leszek Koltunski
      randomX = mRnd.nextInt(scrW) - scrW/2;
222
      randomY = mRnd.nextInt(scrH) - scrH/2;
223 5a683295 Leszek Koltunski
      randomS = (0.2f+ 0.8f*mRnd.nextFloat())*20;
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 e8e54972 Leszek Koltunski
229 fc448f77 Leszek Koltunski
      mStarEffects[i].apply( new MatrixEffectRotate(new Static1D(randomA), axis, center) );
230 e8e54972 Leszek Koltunski
      mStarEffects[i].apply( new MatrixEffectScale(randomS) );
231
      mStarEffects[i].apply( new MatrixEffectMove(new Static3D(randomX,randomY,0)) );
232
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 5a683295 Leszek Koltunski
      mScreen.attach(mStarTexture, mStarEffects[i], mQuad);
241 427ab7bf Leszek Koltunski
      }
242 5a683295 Leszek Koltunski
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 e8e54972 Leszek Koltunski
248
    FragmentEffectAlpha alpha = new FragmentEffectAlpha(di);
249
    alpha.notifyWhenFinished(this);
250
    alphaEffectID = alpha.getID();
251
252 5a683295 Leszek Koltunski
    Static3D scale = new Static3D(0.5f*scrW, 0.5f*scrW * GFFA_HEIGHT / GFFA_WIDTH, 1);
253
254 fc448f77 Leszek Koltunski
    mGFFAEffects.apply( new MatrixEffectScale(scale) );
255 5a683295 Leszek Koltunski
    mGFFAEffects.apply( new MatrixEffectMove(new Static3D(-scrW/3 + GFFA_WIDTH/2 ,scrH/6,0)) );
256 e8e54972 Leszek Koltunski
    mGFFAEffects.apply( alpha );
257 bc0a685b Leszek Koltunski
      
258 5a683295 Leszek Koltunski
    mScreen.attach(mGFFATexture, mGFFAEffects, mQuad);
259 bc0a685b Leszek Koltunski
    }
260 427ab7bf Leszek Koltunski
    
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262
263 bc0a685b Leszek Koltunski
  private void setupBitmaps()
264
    {
265
    InputStream is1 = mView.getContext().getResources().openRawResource(R.raw.starwars);
266
    InputStream is2 = mView.getContext().getResources().openRawResource(R.raw.star);
267 427ab7bf Leszek Koltunski
    
268 bc0a685b Leszek Koltunski
    Bitmap bitmapStar, bitmapGFFA, bitmapLogo, bitmapText;
269
      
270
    try 
271
      {
272
      bitmapLogo = BitmapFactory.decodeStream(is1);
273
      bitmapStar = BitmapFactory.decodeStream(is2);
274
      } 
275
    finally 
276
      {
277 427ab7bf Leszek Koltunski
      try 
278
        {
279 bc0a685b Leszek Koltunski
        is1.close();
280
        is2.close();
281 427ab7bf Leszek Koltunski
        } 
282 bc0a685b Leszek Koltunski
      catch(IOException e) { }
283
      } 
284 427ab7bf Leszek Koltunski
      
285 bc0a685b Leszek Koltunski
    Paint paint = new Paint();
286
    paint.setAntiAlias(true);
287
    paint.setTextAlign(Paint.Align.LEFT);
288
    paint.setTextSize(FONT_HEIGHT);
289
    paint.setColor(GFFA_COLOR);
290 427ab7bf Leszek Koltunski
      
291 bc0a685b Leszek Koltunski
    Typeface tf = Typeface.create(CRAWL_TYPEFACE, Typeface.BOLD);
292
    paint.setTypeface(tf);     
293 427ab7bf Leszek Koltunski
 
294 bc0a685b Leszek Koltunski
    ///// create GFFA ///////////////////
295 687263cc Leszek Koltunski
    if( mGFFATexture==null ) mGFFATexture  = new DistortedTexture();
296 bc0a685b Leszek Koltunski
    bitmapGFFA = Bitmap.createBitmap(GFFA_WIDTH,GFFA_HEIGHT,Bitmap.Config.ARGB_8888);
297
    bitmapGFFA.eraseColor(0x00000000);
298
    Canvas gffaCanvas = new Canvas(bitmapGFFA);
299 427ab7bf Leszek Koltunski
      
300 bc0a685b Leszek Koltunski
    for(int i=0; i<mGFFAString.length; i++)
301
      {
302
      gffaCanvas.drawText(mGFFAString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), paint);  
303
      }
304 427ab7bf Leszek Koltunski
  
305 f6d884d5 Leszek Koltunski
    mGFFATexture.setTexture(bitmapGFFA);
306 427ab7bf Leszek Koltunski
      
307 bc0a685b Leszek Koltunski
    ///// create Logo ///////////////////
308 5a683295 Leszek Koltunski
    if( mLogoTexture==null ) mLogoTexture = new DistortedTexture();
309 f6d884d5 Leszek Koltunski
    mLogoTexture.setTexture(bitmapLogo);
310 5a683295 Leszek Koltunski
    mLogoRatio = (float)bitmapLogo.getWidth()/bitmapLogo.getHeight();
311 e8b6aa95 Leszek Koltunski
312 bc0a685b Leszek Koltunski
    ///// create CRAWL //////////////////
313 687263cc Leszek Koltunski
    if( mCrawlTexture==null ) mCrawlTexture = new DistortedTexture();
314 bc0a685b Leszek Koltunski
    bitmapText = Bitmap.createBitmap(CRAWL_WIDTH,CRAWL_HEIGHT,Bitmap.Config.ARGB_8888);
315
    bitmapText.eraseColor(0x00000000);
316
    Canvas textCanvas = new Canvas(bitmapText);
317
    paint.setColor(CRAWL_COLOR);
318 427ab7bf Leszek Koltunski
  
319 bc0a685b Leszek Koltunski
    for(int i=0; i<mCRAWLString.length; i++)
320
      {
321
      displayJustified(mCRAWLString[i], 0, (i+1)*(FONT_HEIGHT+VERTICAL_SPACING), CRAWL_WIDTH, textCanvas, paint);  
322
      }
323 427ab7bf Leszek Koltunski
      
324 f6d884d5 Leszek Koltunski
    mCrawlTexture.setTexture(bitmapText);
325 427ab7bf Leszek Koltunski
      
326 bc0a685b Leszek Koltunski
    ///// create Stars ///////////////////
327 687263cc Leszek Koltunski
    if( mStarTexture==null ) mStarTexture = new DistortedTexture();
328 f6d884d5 Leszek Koltunski
    mStarTexture.setTexture(bitmapStar);
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
375 8d5a8e06 Leszek Koltunski
  public void effectFinished(final long effectID)
376 bc0a685b Leszek Koltunski
    {
377 8d5a8e06 Leszek Koltunski
    if( effectID == alphaEffectID )
378 427ab7bf Leszek Koltunski
      {
379 8d5a8e06 Leszek Koltunski
      mScreen.detach(mGFFAEffects);
380
      mGFFATexture.markForDeletion();
381 611ea379 Leszek Koltunski
382 e8e54972 Leszek Koltunski
      int screenW = mScreen.getWidth();
383 5a683295 Leszek Koltunski
      int initSize= (int)(3.00f*screenW);
384
      int finaSize= (int)(0.01f*screenW);
385 427ab7bf Leszek Koltunski
      
386 8d5a8e06 Leszek Koltunski
      Dynamic3D di = new Dynamic3D(10000,0.5f);
387 5a683295 Leszek Koltunski
      di.add(new Static3D(initSize,initSize/mLogoRatio,1));
388
      di.add(new Static3D(finaSize,finaSize/mLogoRatio,1));
389 8d5a8e06 Leszek Koltunski
      MatrixEffectScale scale = new MatrixEffectScale(di);
390
      scale.notifyWhenFinished(this);
391
      scaleEffectID = scale.getID();
392 dae661e9 Leszek Koltunski
      mLogoEffects.apply( scale );
393 5a683295 Leszek Koltunski
      mScreen.attach(mLogoTexture, mLogoEffects, mQuad);
394 8d5a8e06 Leszek Koltunski
      }
395
    else if( effectID == scaleEffectID )
396
      {
397
      mScreen.detach(mLogoEffects);
398
      mLogoTexture.markForDeletion();
399 5a683295 Leszek Koltunski
400
      float scale = mCrawlBackgroundW/CRAWL_WIDTH;
401
402
      mCrawlBackgroundEffects.apply( new MatrixEffectScale( new Static3D(mCrawlBackgroundW, mCrawlBackgroundH, 1) ) );
403
      mCrawlBackgroundEffects.apply( new MatrixEffectRotate(new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0,-mCrawlBackgroundH/2,0)) );
404
      mCrawlBackgroundEffects.apply( new MatrixEffectMove(new Static3D( 0, (mCrawlBackgroundH-mHeight)/2, 0)) );
405
406
      final float transpDist = 5;
407
      Static3D center = new Static3D( 0, transpDist-0.5f, 0 );
408
      Static3D region = new Static3D( transpDist, transpDist, transpDist );
409 8d5a8e06 Leszek Koltunski
      mCrawlBackgroundEffects.apply( new FragmentEffectAlpha(new Static1D(1-transpDist*0.6f), center, region, true) );
410
411
      Dynamic3D di = new Dynamic3D(70000,0.5f);
412 5a683295 Leszek Koltunski
      di.add(new Static3D(0, -(scale*CRAWL_HEIGHT+mCrawlBackgroundH)/2, 0));
413
      di.add(new Static3D(0, +(scale*CRAWL_HEIGHT+mCrawlBackgroundH)/2, 0));
414 8d5a8e06 Leszek Koltunski
      MatrixEffectMove move = new MatrixEffectMove(di);
415
      move.notifyWhenFinished(this);
416
      moveEffectID = move.getID();
417
418 5a683295 Leszek Koltunski
      mCrawlEffects.apply( new MatrixEffectScale(new Static3D(scale*CRAWL_WIDTH,scale*CRAWL_HEIGHT,1)) );
419 dae661e9 Leszek Koltunski
      mCrawlEffects.apply( move );
420
421 5a683295 Leszek Koltunski
      mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects, mQuad);
422
      mBackground.resizeFBO(mCrawlBackgroundW,mCrawlBackgroundH);
423
      mBackground.attach(mCrawlTexture, mCrawlEffects, mQuad);
424 8d5a8e06 Leszek Koltunski
      mBackground.glDisable(GLES31.GL_DEPTH_TEST);
425
      mBackground.glDepthMask(false);
426
      }
427 e8e54972 Leszek Koltunski
    else if( effectID == moveEffectID )
428 8d5a8e06 Leszek Koltunski
      {
429
      mScreen.detach(mBackground);
430
      mBackground.detach(mCrawlEffects);
431
      mCrawlTexture.markForDeletion();
432
      mCrawlBackgroundEffects.abortAllEffects();
433
      mCrawlBackgroundTexture.markForDeletion();
434 427ab7bf Leszek Koltunski
      }
435 bc0a685b Leszek Koltunski
    }
436 dc10a48d Leszek Koltunski
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438
439
  public void distortedException(Exception ex)
440
    {
441
    android.util.Log.e("StarWars", ex.getMessage() );
442
    }
443
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445
446
  public InputStream localFile(int fileID)
447
    {
448
    return mResources.openRawResource(fileID);
449
    }
450
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452
453
  public void logMessage(String message)
454
    {
455
    android.util.Log.e("StarWars", message );
456
    }
457 bc0a685b Leszek Koltunski
  }