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