1 |
29fdea14
|
Leszek Koltunski
|
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.mesh.MeshQuad;
|
12 |
|
|
import org.distorted.library.message.EffectListener;
|
13 |
|
|
import org.distorted.library.type.Dynamic2D;
|
14 |
|
|
import org.distorted.library.type.Dynamic4D;
|
15 |
|
|
import org.distorted.library.type.Static2D;
|
16 |
|
|
import org.distorted.library.type.Static4D;
|
17 |
|
|
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
public class OverlayStars implements EffectListener
|
21 |
|
|
{
|
22 |
|
|
private static final int DUR_GLO = 2000;
|
23 |
|
|
|
24 |
|
|
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
|
25 |
|
|
private static final int INDEX = 5;
|
26 |
|
|
|
27 |
|
|
private DistortedNode mNode1, mNode2;
|
28 |
|
|
private DistortedScreen mScreen;
|
29 |
|
|
|
30 |
395cabff
|
Leszek Koltunski
|
private long mGlowID;
|
31 |
29fdea14
|
Leszek Koltunski
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
private DistortedNode createNode2()
|
35 |
|
|
{
|
36 |
|
|
DistortedTexture texture = new DistortedTexture();
|
37 |
|
|
texture.setColorARGB(0xffff0000);
|
38 |
|
|
MeshQuad mesh = new MeshQuad();
|
39 |
|
|
DistortedEffects effects = new DistortedEffects();
|
40 |
|
|
|
41 |
|
|
return new DistortedNode(texture,effects,mesh);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
private DistortedNode createNode1()
|
47 |
|
|
{
|
48 |
|
|
DistortedTexture texture = new DistortedTexture();
|
49 |
|
|
texture.setColorARGB(0xffff0000);
|
50 |
|
|
MeshQuad mesh = new MeshQuad();
|
51 |
|
|
DistortedEffects effects = new DistortedEffects();
|
52 |
395cabff
|
Leszek Koltunski
|
VertexEffectScale mainScale= new VertexEffectScale(200);
|
53 |
29fdea14
|
Leszek Koltunski
|
effects.apply(mainScale);
|
54 |
|
|
|
55 |
|
|
return new DistortedNode(texture,effects,mesh);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
|
|
public void startOverlay(DistortedScreen screen)
|
61 |
|
|
{
|
62 |
|
|
mScreen = screen;
|
63 |
|
|
mNode1 = createNode1();
|
64 |
|
|
mScreen.attach(mNode1);
|
65 |
|
|
mNode2 = createNode2();
|
66 |
|
|
mScreen.attach(mNode2);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
public void effectFinished(long id)
|
72 |
|
|
{
|
73 |
|
|
if( id==mGlowID )
|
74 |
|
|
{
|
75 |
|
|
mScreen.detach(mNode1);
|
76 |
|
|
mNode1.markForDeletion();
|
77 |
|
|
mNode1=null;
|
78 |
|
|
mScreen.detach(mNode2);
|
79 |
|
|
mNode2.markForDeletion();
|
80 |
|
|
mNode2=null;
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
395cabff
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
public void button2()
|
87 |
|
|
{
|
88 |
|
|
Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
|
89 |
|
|
haloRadius.add(new Static2D( 0, 0));
|
90 |
|
|
haloRadius.add(new Static2D(15,50));
|
91 |
|
|
haloRadius.add(new Static2D( 0, 0));
|
92 |
|
|
|
93 |
|
|
Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
|
94 |
|
|
Static4D P1 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
|
95 |
|
|
Static4D P2 = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
|
96 |
|
|
color.add(P1);
|
97 |
|
|
color.add(P2);
|
98 |
|
|
color.add(P1);
|
99 |
|
|
|
100 |
|
|
PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
|
101 |
|
|
glow.setQuality(EffectQuality.MEDIUM);
|
102 |
|
|
mGlowID = glow.getID();
|
103 |
|
|
glow.notifyWhenFinished(this);
|
104 |
|
|
DistortedEffects effects = mNode1.getEffects();
|
105 |
|
|
effects.apply(glow);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
29fdea14
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
@SuppressWarnings("unused")
|
111 |
|
|
public static void enableEffects()
|
112 |
|
|
{
|
113 |
|
|
VertexEffectMove.enable();
|
114 |
|
|
VertexEffectScale.enable();
|
115 |
|
|
PostprocessEffectGlow.enable();
|
116 |
|
|
}
|
117 |
|
|
}
|