Revision fc6d738d
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/overlays/OverlayStars.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import org.distorted.library.effect.EffectQuality; |
19 | 19 |
import org.distorted.library.effect.FragmentEffectAlpha; |
20 |
import org.distorted.library.effect.MatrixEffectMove; |
|
21 |
import org.distorted.library.effect.MatrixEffectScale; |
|
20 | 22 |
import org.distorted.library.effect.PostprocessEffectGlow; |
21 | 23 |
import org.distorted.library.effect.VertexEffectMove; |
22 | 24 |
import org.distorted.library.effect.VertexEffectScale; |
... | ... | |
53 | 55 |
private static final int INDEX = 5; |
54 | 56 |
|
55 | 57 |
private ListenerOverlay mListener; |
56 |
private DistortedNode mNode; |
|
58 |
private DistortedNode mNodeFalling, mNodeCentral;
|
|
57 | 59 |
private DistortedScreen mScreen; |
58 | 60 |
private DistortedTexture mTexture; |
59 | 61 |
private Bitmap mCountBitmap, mStarBitmap; |
... | ... | |
148 | 150 |
|
149 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
150 | 152 |
|
151 |
private DistortedNode createNode(Resources res, int numStars, boolean increase)
|
|
153 |
private void createBitmap(Resources res)
|
|
152 | 154 |
{ |
153 |
// texture ///////////////////////////////////////////////////// |
|
154 |
if( mTexture==null ) |
|
155 |
{ |
|
156 |
mTexture = new DistortedTexture(); |
|
157 |
mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star); |
|
158 |
mBmpW = mStarBitmap.getWidth(); |
|
159 |
mBmpH = mStarBitmap.getHeight(); |
|
160 |
mCountBitmap = Bitmap.createBitmap(2*mBmpW,mBmpH,Bitmap.Config.ARGB_8888); |
|
161 |
mCountCanvas = new Canvas(mCountBitmap); |
|
162 |
mPaint = new Paint(); |
|
163 |
mPaint.setColor(0xff000000); |
|
164 |
mPaint.setTextSize(mBmpH*0.28f); |
|
165 |
mPaint.setAntiAlias(true); |
|
166 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
167 |
renderStars(numStars); |
|
168 |
} |
|
155 |
mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star); |
|
156 |
mBmpW = mStarBitmap.getWidth(); |
|
157 |
mBmpH = mStarBitmap.getHeight(); |
|
158 |
mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888); |
|
159 |
mCountCanvas = new Canvas(mCountBitmap); |
|
160 |
mPaint = new Paint(); |
|
161 |
mPaint.setColor(0xff000000); |
|
162 |
mPaint.setTextSize(mBmpH*0.28f); |
|
163 |
mPaint.setAntiAlias(true); |
|
164 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
165 |
} |
|
169 | 166 |
|
170 |
// mesh //////////////////////////////////////////////////////// |
|
171 |
MeshQuad[] mesh = new MeshQuad[mNewStars+1]; |
|
167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 | 168 |
|
173 |
Static4D[] mapMain = new Static4D[1]; |
|
174 |
Static4D[] mapStar = new Static4D[1]; |
|
169 |
private DistortedNode createNodeFalling(boolean increase) |
|
170 |
{ |
|
171 |
DistortedTexture texture = new DistortedTexture(); |
|
172 |
texture.setTexture(mStarBitmap); |
|
175 | 173 |
|
176 |
mapMain[0] = new Static4D(0.5f,0.0f,0.5f,1.0f); |
|
177 |
mapStar[0] = new Static4D(0.0f,0.0f,0.5f,1.0f); |
|
174 |
MeshQuad[] mesh = new MeshQuad[mNewStars]; |
|
178 | 175 |
|
179 |
for(int i=0; i<mNewStars+1; i++)
|
|
176 |
for(int i=0; i<mNewStars; i++) |
|
180 | 177 |
{ |
181 | 178 |
mesh[i] = new MeshQuad(); |
182 |
|
|
183 |
if( i>=mNewStars ) |
|
184 |
{ |
|
185 |
mesh[i].setEffectAssociation(0,2,i); |
|
186 |
mesh[i].setTextureMap(mapMain,0); |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
mesh[i].setEffectAssociation(0,1,i); |
|
191 |
mesh[i].setTextureMap(mapStar,0); |
|
192 |
} |
|
179 |
mesh[i].setEffectAssociation(0,1,i+1); |
|
193 | 180 |
} |
194 | 181 |
|
195 | 182 |
MeshJoined wholeMesh = new MeshJoined(mesh); |
196 | 183 |
|
197 |
// effects: main /////////////////////////////////////////////// |
|
198 | 184 |
DistortedEffects effects = new DistortedEffects(); |
199 |
|
|
200 |
float scaleM = mWidth*0.40f; |
|
201 |
float scaleP = mWidth*0.15f; |
|
202 |
Static3D moveM= new Static3D(0,0,1); |
|
203 |
|
|
204 |
VertexEffectMove mainMove = new VertexEffectMove(moveM); |
|
205 |
VertexEffectScale mainScale = new VertexEffectScale(scaleM); |
|
206 |
mainMove.setMeshAssociation(2,-1); |
|
207 |
mainScale.setMeshAssociation(2,-1); |
|
208 |
|
|
209 |
// effects: moving stars /////////////////////////////////////// |
|
210 |
VertexEffectScale scaleE = new VertexEffectScale(scaleP); |
|
185 |
VertexEffectScale scaleE = new VertexEffectScale(mWidth*0.15f); |
|
211 | 186 |
scaleE.setMeshAssociation(1,-1); |
212 | 187 |
effects.apply(scaleE); |
213 | 188 |
|
... | ... | |
215 | 190 |
{ |
216 | 191 |
Dynamic3D moveP = createRandomMove(increase); |
217 | 192 |
VertexEffectMove moveE= new VertexEffectMove(moveP); |
218 |
moveE.setMeshAssociation(0,i); |
|
193 |
moveE.setMeshAssociation(0,i+1);
|
|
219 | 194 |
effects.apply(moveE); |
220 | 195 |
|
221 | 196 |
if( i==0 ) |
... | ... | |
225 | 200 |
} |
226 | 201 |
} |
227 | 202 |
|
228 |
// main effect queue /////////////////////////////////////////// |
|
229 |
effects.apply(mainMove); |
|
230 |
effects.apply(mainScale); |
|
203 |
return new DistortedNode(texture,effects,wholeMesh); |
|
204 |
} |
|
231 | 205 |
|
206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
207 |
|
|
208 |
private DistortedNode createNodeCentral(int numStars) |
|
209 |
{ |
|
210 |
mTexture = new DistortedTexture(); |
|
211 |
renderStars(numStars); |
|
212 |
|
|
213 |
MeshQuad mesh = new MeshQuad(); |
|
214 |
|
|
215 |
DistortedEffects effects = new DistortedEffects(); |
|
216 |
float scaleM = mWidth*0.40f; |
|
217 |
Static3D moveM= new Static3D(0,0,1); |
|
218 |
MatrixEffectMove move = new MatrixEffectMove(moveM); |
|
219 |
MatrixEffectScale scale= new MatrixEffectScale(scaleM); |
|
220 |
effects.apply(move); |
|
221 |
effects.apply(scale); |
|
232 | 222 |
createAlphaEffect(true); |
233 | 223 |
effects.apply(mAlpha); |
234 | 224 |
|
235 |
return new DistortedNode(mTexture,effects,wholeMesh);
|
|
225 |
return new DistortedNode(mTexture,effects,mesh);
|
|
236 | 226 |
} |
237 | 227 |
|
238 | 228 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
242 | 232 |
String txt = ""+numStars; |
243 | 233 |
mCountBitmap.eraseColor(0x00000000); |
244 | 234 |
mCountCanvas.drawBitmap(mStarBitmap,0,0,null); |
245 |
mCountCanvas.drawBitmap(mStarBitmap,mBmpW,0,null); |
|
246 |
mCountCanvas.drawText(txt,mBmpW*1.5f,mBmpH*0.64f,mPaint); |
|
235 |
mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint); |
|
247 | 236 |
mTexture.setTexture(mCountBitmap); |
248 | 237 |
} |
249 | 238 |
|
... | ... | |
262 | 251 |
mHeight= mScreen.getHeight(); |
263 | 252 |
mIncrease = mNewStars>0; |
264 | 253 |
if( !mIncrease ) mNewStars = -mNewStars; |
265 |
mNode = createNode(res,mTotalStars,mIncrease); |
|
266 |
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL); |
|
267 |
mScreen.attach(mNode); |
|
254 |
|
|
255 |
createBitmap(res); |
|
256 |
mNodeFalling = createNodeFalling(mIncrease); |
|
257 |
mNodeFalling.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL); |
|
258 |
mScreen.attach(mNodeFalling); |
|
259 |
mNodeCentral = createNodeCentral(mTotalStars); |
|
260 |
mNodeCentral.glDepthMask(false); |
|
261 |
mNodeCentral.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL); |
|
262 |
mScreen.attach(mNodeCentral); |
|
268 | 263 |
|
269 | 264 |
return 0; |
270 | 265 |
} |
... | ... | |
291 | 286 |
glow.setQuality(EffectQuality.MEDIUM); |
292 | 287 |
mGlowID = glow.getID(); |
293 | 288 |
glow.notifyWhenFinished(this); |
294 |
DistortedEffects effects = mNode.getEffects(); |
|
289 |
DistortedEffects effects = mNodeCentral.getEffects();
|
|
295 | 290 |
effects.apply(glow); |
296 | 291 |
renderStars(mTotalStars+(mIncrease ? mNewStars : -mNewStars)); |
297 | 292 |
} |
... | ... | |
303 | 298 |
} |
304 | 299 |
if( id==mAlphaID ) |
305 | 300 |
{ |
306 |
mScreen.detach(mNode); |
|
307 |
mNode.markForDeletion(); |
|
308 |
mNode=null; |
|
301 |
mScreen.detach(mNodeCentral); |
|
302 |
mNodeCentral.markForDeletion(); |
|
303 |
mNodeCentral=null; |
|
304 |
mScreen.detach(mNodeFalling); |
|
305 |
mNodeFalling.markForDeletion(); |
|
306 |
mNodeFalling=null; |
|
309 | 307 |
mListener.overlayFinished(id); |
310 | 308 |
} |
311 | 309 |
} |
Also available in: Unified diff
Now the 'stars' animation should fulling work, even on the physical LG phone.