Revision 2890c5df
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/flag/FlagRenderer.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.MatrixEffectMove; |
|
29 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
30 |
import org.distorted.library.effect.MatrixEffectScale; |
|
31 |
import org.distorted.library.effect.VertexEffectWave; |
|
27 | 32 |
import org.distorted.library.main.Distorted; |
28 | 33 |
import org.distorted.library.main.DistortedEffects; |
29 | 34 |
import org.distorted.library.main.DistortedScreen; |
30 |
import org.distorted.library.EffectNames; |
|
31 | 35 |
import org.distorted.library.main.MeshCubes; |
32 | 36 |
import org.distorted.library.main.DistortedTexture; |
33 |
import org.distorted.library.EffectTypes; |
|
34 | 37 |
import org.distorted.library.type.Dynamic; |
35 | 38 |
import org.distorted.library.type.Dynamic5D; |
36 |
import org.distorted.library.type.DynamicQuat; |
|
37 | 39 |
import org.distorted.library.type.Static3D; |
38 | 40 |
import org.distorted.library.type.Static4D; |
39 | 41 |
import org.distorted.library.type.Static5D; |
... | ... | |
52 | 54 |
private DistortedEffects mEffects; |
53 | 55 |
private DistortedTexture mTexture; |
54 | 56 |
private DistortedScreen mScreen; |
55 |
private DynamicQuat mQuatInt1, mQuatInt2; |
|
56 | 57 |
private Dynamic5D mWaveDyn; |
57 | 58 |
private Static5D mWaveSta1, mWaveSta2; |
58 | 59 |
private int mObjWidth, mObjHeight; |
60 |
private Static3D mMove, mScale, mCenter; |
|
59 | 61 |
|
60 | 62 |
Static4D mQuat1, mQuat2; |
61 | 63 |
int mScreenMin; |
... | ... | |
83 | 85 |
mQuat1 = new Static4D( 0, 0, 0, 1); // unity quaternion |
84 | 86 |
mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); // something semi-random that looks good |
85 | 87 |
|
86 |
mQuatInt1 = new DynamicQuat(0,0.5f); |
|
87 |
mQuatInt2 = new DynamicQuat(0,0.5f); |
|
88 |
|
|
89 |
mQuatInt1.add(mQuat1); |
|
90 |
mQuatInt2.add(mQuat2); |
|
91 |
|
|
92 | 88 |
Static3D waveCenter = new Static3D(mObjWidth, mObjHeight/2, 0); // middle of the right edge |
93 | 89 |
Static4D waveRegion = new Static4D(0,0,mObjWidth,mObjWidth); |
94 | 90 |
|
95 |
mEffects.wave(mWaveDyn, waveCenter, waveRegion); |
|
91 |
mEffects.apply( new VertexEffectWave(mWaveDyn, waveCenter, waveRegion) ); |
|
92 |
|
|
93 |
mMove = new Static3D(0,0,0); |
|
94 |
mScale = new Static3D(1,1,1); |
|
95 |
mCenter= new Static3D(0,0,0); |
|
96 |
|
|
97 |
mEffects.apply( new MatrixEffectMove(mMove)); |
|
98 |
mEffects.apply( new MatrixEffectScale(mScale)); |
|
99 |
mEffects.apply( new MatrixEffectQuaternion(mQuat1, mCenter) ); |
|
100 |
mEffects.apply( new MatrixEffectQuaternion(mQuat2, mCenter) ); |
|
96 | 101 |
|
97 | 102 |
mScreen = new DistortedScreen(mView); |
98 | 103 |
mScreen.attach(mTexture,mEffects, new MeshCubes(50,30,1) ); |
... | ... | |
149 | 154 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
150 | 155 |
{ |
151 | 156 |
mScreenMin = width<height ? width:height; |
152 |
|
|
153 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
154 |
float factor; |
|
155 |
|
|
156 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
|
157 |
{ |
|
158 |
factor = (0.8f*height)/mObjHeight; |
|
159 |
} |
|
160 |
else |
|
161 |
{ |
|
162 |
factor = (0.8f*width)/mObjWidth; |
|
163 |
} |
|
164 |
|
|
165 |
mEffects.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) ); |
|
166 |
mEffects.scale(factor); |
|
167 |
Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
|
168 |
|
|
169 |
mEffects.quaternion(mQuatInt1, center); |
|
170 |
mEffects.quaternion(mQuatInt2, center); |
|
171 |
|
|
157 |
float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.8f*height)/mObjHeight : (0.8f*width)/mObjWidth; |
|
158 |
mMove.set((width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0); |
|
159 |
mScale.set(factor,factor,factor); |
|
160 |
mCenter.set(mObjWidth/2,mObjHeight/2, 0); |
|
172 | 161 |
mScreen.resize(width, height); |
173 | 162 |
} |
174 | 163 |
|
... | ... | |
194 | 183 |
|
195 | 184 |
mTexture.setTexture(bitmap); |
196 | 185 |
|
197 |
DistortedEffects.enableEffect(EffectNames.WAVE);
|
|
186 |
DistortedEffects.enableEffect(EffectName.WAVE); |
|
198 | 187 |
|
199 | 188 |
try |
200 | 189 |
{ |
Also available in: Unified diff
Further progress with Apps.