Revision 2890c5df
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/glow/GlowRenderer.java | ||
---|---|---|
24 | 24 |
import android.opengl.GLSurfaceView; |
25 | 25 |
|
26 | 26 |
import org.distorted.examples.R; |
27 |
import org.distorted.library.effect.EffectName; |
|
28 |
import org.distorted.library.effect.FragmentEffectChroma; |
|
29 |
import org.distorted.library.effect.MatrixEffectMove; |
|
30 |
import org.distorted.library.effect.MatrixEffectRotate; |
|
31 |
import org.distorted.library.effect.MatrixEffectScale; |
|
32 |
import org.distorted.library.effect.PostprocessEffectGlow; |
|
27 | 33 |
import org.distorted.library.main.Distorted; |
28 | 34 |
import org.distorted.library.main.DistortedEffects; |
29 | 35 |
import org.distorted.library.main.DistortedEffectsPostprocess; |
30 | 36 |
import org.distorted.library.main.DistortedNode; |
31 | 37 |
import org.distorted.library.main.DistortedScreen; |
32 | 38 |
import org.distorted.library.main.DistortedTexture; |
33 |
import org.distorted.library.EffectNames; |
|
34 |
import org.distorted.library.EffectTypes; |
|
35 | 39 |
import org.distorted.library.main.MeshFlat; |
36 | 40 |
import org.distorted.library.main.MeshObject; |
37 | 41 |
import org.distorted.library.message.EffectListener; |
... | ... | |
57 | 61 |
private static final int NUM_LEAVES= colors.length/3; |
58 | 62 |
|
59 | 63 |
private GLSurfaceView mView; |
60 |
private DistortedNode mRoot; |
|
61 | 64 |
private DistortedTexture mLeaf; |
62 | 65 |
private DistortedScreen mScreen; |
63 | 66 |
private DistortedEffectsPostprocess[] mLeafGlow = new DistortedEffectsPostprocess[NUM_LEAVES]; |
67 |
private PostprocessEffectGlow[] mGlow = new PostprocessEffectGlow[NUM_LEAVES]; |
|
64 | 68 |
private int mRootW, mRootH; |
65 | 69 |
private int mGlowing; |
70 |
private Static3D mMove, mScale; |
|
66 | 71 |
|
67 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 73 |
|
... | ... | |
78 | 83 |
MeshObject mesh = new MeshFlat(1,1); |
79 | 84 |
DistortedEffects[] leafEffects = new DistortedEffects[NUM_LEAVES]; |
80 | 85 |
|
81 |
mRoot = new DistortedNode(surface, new DistortedEffects(), mesh);
|
|
86 |
DistortedNode root = new DistortedNode(surface, new DistortedEffects(), mesh);
|
|
82 | 87 |
|
83 | 88 |
Static3D moveVector = new Static3D(0,LEAF_SIZE,0); |
84 | 89 |
Static1D chromaLevel= new Static1D(0.5f); |
85 | 90 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0); |
86 | 91 |
Static3D axis = new Static3D(0,0,1); |
87 | 92 |
|
93 |
MatrixEffectMove leafMove = new MatrixEffectMove(moveVector); |
|
94 |
|
|
88 | 95 |
for(int j=0; j<NUM_LEAVES; j++) |
89 | 96 |
{ |
90 | 97 |
mLeafGlow[j] = new DistortedEffectsPostprocess(); |
91 | 98 |
mLeafGlow[j].registerForMessages(this); |
92 | 99 |
|
93 | 100 |
leafEffects[j] = new DistortedEffects(); |
94 |
leafEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
|
|
95 |
leafEffects[j].move(moveVector);
|
|
96 |
leafEffects[j].chroma( chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2]) );
|
|
101 |
leafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
|
|
102 |
leafEffects[j].apply(leafMove);
|
|
103 |
leafEffects[j].apply( new FragmentEffectChroma(chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2])) );
|
|
97 | 104 |
DistortedNode node = new DistortedNode( mLeaf, leafEffects[j], mesh); |
98 | 105 |
node.setPostprocessEffects(mLeafGlow[j]); |
99 |
mRoot.attach(node);
|
|
106 |
root.attach(node);
|
|
100 | 107 |
} |
101 | 108 |
|
102 | 109 |
makeGlow(0); |
103 | 110 |
|
104 | 111 |
mScreen = new DistortedScreen(mView); |
105 |
mScreen.attach(mRoot); |
|
112 |
mScreen.attach(root); |
|
113 |
|
|
114 |
mMove = new Static3D(0,0,0); |
|
115 |
mScale= new Static3D(1,1,1); |
|
116 |
|
|
117 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
|
118 |
rot.setMode(Dynamic1D.MODE_JUMP); |
|
119 |
rot.add(new Static1D( 0)); |
|
120 |
rot.add(new Static1D(360)); |
|
121 |
|
|
122 |
DistortedEffects effects = root.getEffects(); |
|
123 |
effects.apply(new MatrixEffectMove(mMove)); |
|
124 |
effects.apply(new MatrixEffectScale(mScale)); |
|
125 |
effects.apply( new MatrixEffectRotate(rot, axis, center) ); |
|
126 |
|
|
127 |
Dynamic1D radius = new Dynamic1D(5000,1.0f); |
|
128 |
Static1D startR = new Static1D( 0); |
|
129 |
Static1D endR = new Static1D(50); |
|
130 |
radius.add(startR); |
|
131 |
radius.add(endR); |
|
132 |
|
|
133 |
for(int leaf=0; leaf<NUM_LEAVES; leaf++) |
|
134 |
{ |
|
135 |
Dynamic4D color = new Dynamic4D(5000,1.0f); |
|
136 |
Static4D startC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0); |
|
137 |
Static4D endC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1); |
|
138 |
color.add(startC); |
|
139 |
color.add(endC); |
|
140 |
|
|
141 |
mGlow[leaf] = new PostprocessEffectGlow(radius,color); |
|
142 |
} |
|
106 | 143 |
} |
107 | 144 |
|
108 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
112 | 149 |
//android.util.Log.e("glow", "glowing: "+leaf); |
113 | 150 |
|
114 | 151 |
mGlowing = leaf; |
115 |
|
|
116 |
Dynamic1D radius = new Dynamic1D(5000,1.0f); |
|
117 |
Static1D startR = new Static1D( 0); |
|
118 |
Static1D endR = new Static1D(50); |
|
119 |
radius.add(startR); |
|
120 |
radius.add(endR); |
|
121 |
|
|
122 |
Dynamic4D color = new Dynamic4D(5000,1.0f); |
|
123 |
Static4D startC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 0); |
|
124 |
Static4D endC = new Static4D(colors[3*leaf],colors[3*leaf+1], colors[3*leaf+2], 1); |
|
125 |
color.add(startC); |
|
126 |
color.add(endC); |
|
127 |
|
|
128 |
mLeafGlow[leaf].glow( radius, color ); |
|
152 |
mLeafGlow[leaf].apply(mGlow[leaf]); |
|
129 | 153 |
} |
130 | 154 |
|
131 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
132 | 156 |
// Glow finished. Make the next Leaf glow. |
133 | 157 |
|
134 |
public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID)
|
|
158 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID) |
|
135 | 159 |
{ |
136 | 160 |
switch(em) |
137 | 161 |
{ |
... | ... | |
162 | 186 |
int w = (int)(factor*mRootW); |
163 | 187 |
int h = (int)(factor*mRootH); |
164 | 188 |
|
165 |
Dynamic1D rot = new Dynamic1D(5000,0.0f); |
|
166 |
rot.setMode(Dynamic1D.MODE_JUMP); |
|
167 |
rot.add(new Static1D( 0)); |
|
168 |
rot.add(new Static1D(360)); |
|
169 |
|
|
170 |
Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0); |
|
171 |
Static3D axis = new Static3D(0,0,1); |
|
172 |
|
|
173 |
DistortedEffects effects = mRoot.getEffects(); |
|
174 |
effects.abortEffects(EffectTypes.MATRIX); |
|
175 |
effects.move( new Static3D((width-w)/2 ,(height-h)/2, 0) ); |
|
176 |
effects.scale( factor ); |
|
177 |
effects.rotate( rot, axis, center ); |
|
178 |
|
|
189 |
mMove.set((width-w)/2 ,(height-h)/2, 0); |
|
190 |
mScale.set( factor,factor,factor ); |
|
179 | 191 |
mScreen.resize(width, height); |
180 | 192 |
} |
181 | 193 |
|
... | ... | |
201 | 213 |
|
202 | 214 |
mLeaf.setTexture(leaf); |
203 | 215 |
|
204 |
DistortedEffects.enableEffect(EffectNames.CHROMA);
|
|
205 |
DistortedEffects.enableEffect(EffectNames.GLOW);
|
|
216 |
DistortedEffects.enableEffect(EffectName.CHROMA); |
|
217 |
DistortedEffects.enableEffect(EffectName.GLOW); |
|
206 | 218 |
|
207 | 219 |
try |
208 | 220 |
{ |
Also available in: Unified diff
Further progress with Apps.