1 |
36532c7f
|
Leszek Koltunski
|
package org.distorted.examples.flatblur;
|
2 |
|
|
|
3 |
|
|
import org.distorted.library.effect.EffectQuality;
|
4 |
|
|
import org.distorted.library.effect.PostprocessEffectGlow;
|
5 |
|
|
import org.distorted.library.effect.VertexEffectMove;
|
6 |
|
|
import org.distorted.library.effect.VertexEffectScale;
|
7 |
|
|
import org.distorted.library.main.DistortedEffects;
|
8 |
|
|
import org.distorted.library.main.DistortedNode;
|
9 |
|
|
import org.distorted.library.main.DistortedScreen;
|
10 |
|
|
import org.distorted.library.main.DistortedTexture;
|
11 |
|
|
import org.distorted.library.main.InternalOutputSurface;
|
12 |
|
|
import org.distorted.library.mesh.MeshJoined;
|
13 |
|
|
import org.distorted.library.mesh.MeshQuad;
|
14 |
|
|
import org.distorted.library.message.EffectListener;
|
15 |
|
|
import org.distorted.library.type.Dynamic;
|
16 |
|
|
import org.distorted.library.type.Dynamic2D;
|
17 |
|
|
import org.distorted.library.type.Dynamic3D;
|
18 |
|
|
import org.distorted.library.type.Dynamic4D;
|
19 |
|
|
import org.distorted.library.type.Static2D;
|
20 |
|
|
import org.distorted.library.type.Static3D;
|
21 |
|
|
import org.distorted.library.type.Static4D;
|
22 |
|
|
|
23 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24 |
|
|
|
25 |
|
|
public class OverlayStars implements EffectListener
|
26 |
|
|
{
|
27 |
|
|
private static final int DUR_MOV = 4000;
|
28 |
|
|
private static final int DUR_GLO = 2000;
|
29 |
|
|
|
30 |
|
|
private static final int[] colors = new int[] {0,0,1, 1,0,1, 1,0,0, 1,1,0, 0,1,0, 1,1,1}; // blue, pink, red, yellow, green, white
|
31 |
|
|
private static final int INDEX = 5;
|
32 |
|
|
|
33 |
|
|
private DistortedNode mNode;
|
34 |
|
|
private DistortedScreen mScreen;
|
35 |
|
|
|
36 |
|
|
private float mWidth;
|
37 |
|
|
private long mMoveID, mGlowID;
|
38 |
|
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
private Dynamic3D createRandomMove()
|
42 |
|
|
{
|
43 |
|
|
Dynamic3D move = new Dynamic3D();
|
44 |
|
|
move.setMode(Dynamic.MODE_PATH);
|
45 |
|
|
move.setDuration(DUR_MOV);
|
46 |
|
|
move.setCount(0.5f);
|
47 |
|
|
|
48 |
|
|
Static3D pointS = new Static3D(0,-500,0);
|
49 |
|
|
Static3D pointE = new Static3D(0,0,0);
|
50 |
|
|
|
51 |
|
|
move.add(pointS);
|
52 |
|
|
move.add(pointE);
|
53 |
|
|
|
54 |
|
|
return move;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
|
|
private DistortedNode createNode()
|
60 |
|
|
{
|
61 |
|
|
DistortedTexture texture = new DistortedTexture();
|
62 |
|
|
texture.setColorARGB(0xffff0000);
|
63 |
|
|
|
64 |
|
|
MeshQuad[] mesh = new MeshQuad[2];
|
65 |
|
|
mesh[0] = new MeshQuad();
|
66 |
|
|
mesh[1] = new MeshQuad();
|
67 |
|
|
mesh[0].setEffectAssociation(0,1,0);
|
68 |
|
|
mesh[1].setEffectAssociation(0,2,1);
|
69 |
|
|
|
70 |
|
|
MeshJoined wholeMesh = new MeshJoined(mesh);
|
71 |
|
|
|
72 |
|
|
DistortedEffects effects = new DistortedEffects();
|
73 |
|
|
|
74 |
|
|
float scaleM = mWidth*0.40f;
|
75 |
|
|
float scaleP = mWidth*0.15f;
|
76 |
|
|
Static3D moveM= new Static3D(0,0,1);
|
77 |
|
|
|
78 |
|
|
VertexEffectMove mainMove = new VertexEffectMove(moveM);
|
79 |
|
|
VertexEffectScale mainScale = new VertexEffectScale(scaleM);
|
80 |
|
|
mainMove.setMeshAssociation(2,-1);
|
81 |
|
|
mainScale.setMeshAssociation(2,-1);
|
82 |
|
|
|
83 |
|
|
VertexEffectScale scaleE = new VertexEffectScale(scaleP);
|
84 |
|
|
scaleE.setMeshAssociation(1,-1);
|
85 |
|
|
effects.apply(scaleE);
|
86 |
|
|
|
87 |
|
|
Dynamic3D moveP = createRandomMove();
|
88 |
|
|
VertexEffectMove moveE= new VertexEffectMove(moveP);
|
89 |
|
|
moveE.setMeshAssociation(0,0);
|
90 |
|
|
effects.apply(moveE);
|
91 |
|
|
|
92 |
|
|
mMoveID = moveE.getID();
|
93 |
|
|
moveE.notifyWhenFinished(this);
|
94 |
|
|
|
95 |
|
|
effects.apply(mainMove);
|
96 |
|
|
effects.apply(mainScale);
|
97 |
|
|
|
98 |
|
|
return new DistortedNode(texture,effects,wholeMesh);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
public void startOverlay(DistortedScreen screen)
|
104 |
|
|
{
|
105 |
|
|
mScreen = screen;
|
106 |
|
|
mWidth = mScreen.getWidth();
|
107 |
|
|
|
108 |
|
|
mNode = createNode();
|
109 |
|
|
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
110 |
|
|
mScreen.attach(mNode);
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114 |
|
|
|
115 |
|
|
public void effectFinished(long id)
|
116 |
|
|
{
|
117 |
|
|
if( id==mMoveID )
|
118 |
|
|
{
|
119 |
|
|
Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
|
120 |
|
|
haloRadius.add(new Static2D( 0, 0));
|
121 |
|
|
haloRadius.add(new Static2D(15,50));
|
122 |
|
|
haloRadius.add(new Static2D( 0, 0));
|
123 |
|
|
|
124 |
|
|
Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
|
125 |
|
|
Static4D P1 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
|
126 |
|
|
Static4D P2 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
|
127 |
|
|
color.add(P1);
|
128 |
|
|
color.add(P2);
|
129 |
|
|
color.add(P1);
|
130 |
|
|
|
131 |
|
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
132 |
|
|
glow.setQuality(EffectQuality.MEDIUM);
|
133 |
|
|
mGlowID = glow.getID();
|
134 |
|
|
glow.notifyWhenFinished(this);
|
135 |
|
|
DistortedEffects effects = mNode.getEffects();
|
136 |
|
|
effects.apply(glow);
|
137 |
|
|
}
|
138 |
|
|
if( id==mGlowID )
|
139 |
|
|
{
|
140 |
|
|
mScreen.detach(mNode);
|
141 |
|
|
mNode.markForDeletion();
|
142 |
|
|
mNode=null;
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147 |
|
|
|
148 |
|
|
@SuppressWarnings("unused")
|
149 |
|
|
public static void enableEffects()
|
150 |
|
|
{
|
151 |
|
|
VertexEffectMove.enable();
|
152 |
|
|
VertexEffectScale.enable();
|
153 |
|
|
PostprocessEffectGlow.enable();
|
154 |
|
|
}
|
155 |
|
|
}
|