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