13 |
13 |
import android.graphics.Bitmap;
|
14 |
14 |
import android.graphics.BitmapFactory;
|
15 |
15 |
|
16 |
|
import org.distorted.library.effect.MatrixEffectMove;
|
17 |
|
import org.distorted.library.effect.MatrixEffectRotate;
|
18 |
|
import org.distorted.library.effect.MatrixEffectScale;
|
|
16 |
import org.distorted.library.effect.VertexEffectMove;
|
|
17 |
import org.distorted.library.effect.VertexEffectRotate;
|
|
18 |
import org.distorted.library.effect.VertexEffectScale;
|
19 |
19 |
import org.distorted.library.main.DistortedEffects;
|
20 |
20 |
import org.distorted.library.main.DistortedNode;
|
21 |
21 |
import org.distorted.library.main.DistortedScreen;
|
22 |
22 |
import org.distorted.library.main.DistortedTexture;
|
|
23 |
import org.distorted.library.main.InternalOutputSurface;
|
|
24 |
import org.distorted.library.mesh.MeshJoined;
|
23 |
25 |
import org.distorted.library.mesh.MeshQuad;
|
24 |
26 |
import org.distorted.library.message.EffectListener;
|
25 |
27 |
import org.distorted.library.type.Dynamic1D;
|
|
28 |
import org.distorted.library.type.Dynamic3D;
|
26 |
29 |
import org.distorted.library.type.Static1D;
|
27 |
30 |
import org.distorted.library.type.Static3D;
|
28 |
31 |
import org.distorted.main.R;
|
29 |
32 |
|
|
33 |
import java.util.Random;
|
|
34 |
|
30 |
35 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31 |
36 |
|
32 |
37 |
public class OverlayStars extends OverlayGeneric implements EffectListener
|
33 |
38 |
{
|
|
39 |
private static final int DUR_ALL = 10000;
|
|
40 |
private static final int DUR_MOV = 5000;
|
|
41 |
|
34 |
42 |
private ListenerOverlay mListener;
|
35 |
43 |
private DistortedNode mNode;
|
36 |
44 |
private DistortedScreen mScreen;
|
|
45 |
private final Static3D mPointE = new Static3D(0,0,2);
|
|
46 |
private float mWidth, mHeight;
|
|
47 |
private Random mRandom;
|
|
48 |
|
|
49 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
50 |
|
|
51 |
private Dynamic3D createRandomMove()
|
|
52 |
{
|
|
53 |
Dynamic3D move = new Dynamic3D();
|
|
54 |
move.setDuration(DUR_MOV);
|
|
55 |
move.setCount(0.5f);
|
|
56 |
|
|
57 |
float widthS = (mRandom.nextFloat()-0.5f)*mWidth;
|
|
58 |
float widthM = widthS + (mRandom.nextFloat()-0.5f)*mWidth*0.2f;
|
|
59 |
|
|
60 |
Static3D pointS = new Static3D(widthS,mHeight/2,2);
|
|
61 |
Static3D pointM = new Static3D(widthM,mHeight/4,2);
|
|
62 |
|
|
63 |
move.add(pointS);
|
|
64 |
move.add(pointM);
|
|
65 |
move.add(mPointE);
|
|
66 |
|
|
67 |
return move;
|
|
68 |
}
|
37 |
69 |
|
38 |
70 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
71 |
|
40 |
72 |
private DistortedNode createNode(Resources res, int totS, int newS)
|
41 |
73 |
{
|
|
74 |
// texture /////////////////////////////////////////////////////
|
42 |
75 |
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.star);
|
43 |
76 |
DistortedTexture texture = new DistortedTexture();
|
44 |
77 |
texture.setTexture(bmp);
|
45 |
78 |
|
46 |
|
float scale = mScreen.getWidth()*0.3f;
|
|
79 |
// mesh ////////////////////////////////////////////////////////
|
|
80 |
|
|
81 |
MeshQuad[] mesh = new MeshQuad[newS+1];
|
|
82 |
|
|
83 |
for(int i=0; i<newS+1; i++)
|
|
84 |
{
|
|
85 |
mesh[i] = new MeshQuad();
|
|
86 |
mesh[i].setEffectAssociation(0,(i==0?0:1),i);
|
|
87 |
}
|
47 |
88 |
|
48 |
|
Static3D move = new Static3D(0,0,1);
|
|
89 |
MeshJoined wholeMesh = new MeshJoined(mesh);
|
|
90 |
|
|
91 |
// effects: main ///////////////////////////////////////////////
|
|
92 |
DistortedEffects effects = new DistortedEffects();
|
|
93 |
|
|
94 |
float scaleM = mWidth*0.3f;
|
|
95 |
float scaleP = mWidth*0.1f;
|
|
96 |
|
|
97 |
Static3D moveM = new Static3D(0,0,1);
|
49 |
98 |
Static1D point0 = new Static1D(0);
|
50 |
99 |
Static1D point360 = new Static1D(360);
|
51 |
100 |
Dynamic1D angle = new Dynamic1D();
|
52 |
101 |
angle.add(point0);
|
53 |
102 |
angle.add(point360);
|
54 |
103 |
angle.setCount(0.5f);
|
55 |
|
angle.setDuration(5000);
|
|
104 |
angle.setDuration(DUR_ALL);
|
56 |
105 |
Static3D axis = new Static3D(0,0,1);
|
57 |
106 |
Static3D center = new Static3D(0,0,0);
|
58 |
107 |
|
59 |
|
DistortedEffects effects = new DistortedEffects();
|
60 |
|
MatrixEffectMove moveEffect = new MatrixEffectMove(move);
|
61 |
|
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
|
62 |
|
MatrixEffectRotate rotateEffect = new MatrixEffectRotate(angle,axis,center);
|
63 |
|
effects.apply(moveEffect);
|
64 |
|
effects.apply(scaleEffect);
|
65 |
|
effects.apply(rotateEffect);
|
66 |
|
|
67 |
|
rotateEffect.notifyWhenFinished(this);
|
68 |
|
|
69 |
|
MeshQuad mesh = new MeshQuad();
|
70 |
|
|
71 |
|
return new DistortedNode(texture,effects,mesh);
|
|
108 |
VertexEffectMove mainMove = new VertexEffectMove(moveM);
|
|
109 |
VertexEffectScale mainScale = new VertexEffectScale(scaleM);
|
|
110 |
VertexEffectRotate mainRotate = new VertexEffectRotate(angle,axis,center);
|
|
111 |
mainMove.setMeshAssociation(2,0);
|
|
112 |
mainScale.setMeshAssociation(2,0);
|
|
113 |
mainRotate.setMeshAssociation(2,0);
|
|
114 |
mainRotate.notifyWhenFinished(this);
|
|
115 |
|
|
116 |
// effects: moving stars ///////////////////////////////////////
|
|
117 |
VertexEffectScale scaleE = new VertexEffectScale(scaleP);
|
|
118 |
scaleE.setMeshAssociation(1,-1);
|
|
119 |
effects.apply(scaleE);
|
|
120 |
|
|
121 |
for(int i=1; i<newS+1; i++)
|
|
122 |
{
|
|
123 |
Dynamic3D moveP = createRandomMove();
|
|
124 |
VertexEffectMove moveE= new VertexEffectMove(moveP);
|
|
125 |
moveE.setMeshAssociation(2,i);
|
|
126 |
effects.apply(moveE);
|
|
127 |
}
|
|
128 |
|
|
129 |
// main effect queue ///////////////////////////////////////////
|
|
130 |
effects.apply(mainMove);
|
|
131 |
effects.apply(mainScale);
|
|
132 |
effects.apply(mainRotate);
|
|
133 |
|
|
134 |
return new DistortedNode(texture,effects,wholeMesh);
|
72 |
135 |
}
|
73 |
136 |
|
74 |
137 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
138 |
|
76 |
139 |
public long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data)
|
77 |
140 |
{
|
|
141 |
if( mRandom==null ) mRandom = new Random();
|
|
142 |
|
78 |
143 |
mScreen = screen;
|
79 |
144 |
mListener= listener;
|
80 |
145 |
DataStars stars = (DataStars)data;
|
... | ... | |
82 |
147 |
int newS = stars.getNew();
|
83 |
148 |
Resources res = stars.getResources();
|
84 |
149 |
|
|
150 |
mWidth = mScreen.getWidth();
|
|
151 |
mHeight= mScreen.getHeight();
|
|
152 |
|
85 |
153 |
mNode = createNode(res,totS,newS);
|
|
154 |
mNode.glDepthMask(false);
|
|
155 |
mNode.glStencilMask(0);
|
|
156 |
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
86 |
157 |
mScreen.attach(mNode);
|
87 |
158 |
|
88 |
159 |
return 0;
|
... | ... | |
95 |
166 |
mScreen.detach(mNode);
|
96 |
167 |
mListener.overlayFinished(id);
|
97 |
168 |
}
|
|
169 |
|
|
170 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
171 |
|
|
172 |
@SuppressWarnings("unused")
|
|
173 |
public static void enableEffects()
|
|
174 |
{
|
|
175 |
VertexEffectMove.enable();
|
|
176 |
VertexEffectScale.enable();
|
|
177 |
VertexEffectRotate.enable();
|
|
178 |
}
|
98 |
179 |
}
|
Disable writing DEPTH and STENCIL to the Screen from both the TwistyObjectNode and the Overlay Node.