Revision c6526577
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import org.distorted.examples.R; |
30 | 30 |
|
31 |
import org.distorted.library.effect.MatrixEffectMove; |
|
32 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
33 |
import org.distorted.library.effect.MatrixEffectScale; |
|
31 | 34 |
import org.distorted.library.main.DistortedEffects; |
32 | 35 |
import org.distorted.library.main.DistortedScreen; |
33 |
import org.distorted.library.EffectTypes; |
|
34 | 36 |
import org.distorted.library.main.MeshObject; |
35 | 37 |
import org.distorted.library.type.Dynamic; |
36 | 38 |
import org.distorted.library.type.DynamicQuat; |
... | ... | |
52 | 54 |
|
53 | 55 |
private GLSurfaceView mView; |
54 | 56 |
private DistortedTexture mTexture; |
55 |
private DistortedEffects mEffects; |
|
56 | 57 |
private MeshObject mMesh; |
57 | 58 |
private DistortedScreen mScreen; |
58 |
private DynamicQuat mRot;
|
|
59 |
|
|
59 |
private Static3D mMove, mScale, mCenter;
|
|
60 |
|
|
60 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 62 |
|
62 | 63 |
QuaternionRenderer(GLSurfaceView v) |
63 | 64 |
{ |
64 | 65 |
mView = v; |
65 | 66 |
mTexture = new DistortedTexture(1,1); |
66 |
mEffects = new DistortedEffects(); |
|
67 | 67 |
mMesh = new MeshCubes(1,1,1); |
68 |
mRot = new DynamicQuat(); |
|
68 |
|
|
69 |
DistortedEffects effects = new DistortedEffects(); |
|
70 |
DynamicQuat rot = new DynamicQuat(); |
|
69 | 71 |
|
70 | 72 |
Random rnd = new Random(System.currentTimeMillis()); |
71 | 73 |
float x,y,z,w, len; |
... | ... | |
79 | 81 |
|
80 | 82 |
len = (float)Math.sqrt( x*x+y*y+z*z+w*w ); |
81 | 83 |
|
82 |
mRot.add(new Static4D(x/len,y/len,z/len,w/len));
|
|
84 |
rot.add(new Static4D(x/len,y/len,z/len,w/len));
|
|
83 | 85 |
} |
84 | 86 |
|
85 |
mRot.setCount(0); |
|
86 |
mRot.setDuration(8000); |
|
87 |
mRot.setMode(Dynamic.MODE_LOOP); |
|
87 |
rot.setCount(0); |
|
88 |
rot.setDuration(8000); |
|
89 |
rot.setMode(Dynamic.MODE_LOOP); |
|
90 |
|
|
91 |
mMove = new Static3D(0,0,0); |
|
92 |
mScale = new Static3D(1,1,1); |
|
93 |
mCenter = new Static3D(0,0,0); |
|
94 |
|
|
95 |
effects.apply( new MatrixEffectMove(mMove)); |
|
96 |
effects.apply(new MatrixEffectScale(mScale)); |
|
97 |
effects.apply( new MatrixEffectQuaternion(rot,mCenter) ); |
|
88 | 98 |
|
89 | 99 |
mScreen = new DistortedScreen(mView); |
90 |
mScreen.attach(mTexture,mEffects,mMesh);
|
|
100 |
mScreen.attach(mTexture,effects,mMesh);
|
|
91 | 101 |
} |
92 | 102 |
|
93 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
105 | 115 |
float h = mTexture.getHeight(); |
106 | 116 |
float d = mTexture.getDepth(mMesh); |
107 | 117 |
|
108 |
float scaleFactor = 0.5f*(width>height ? height/h:width/w); |
|
109 |
Static3D center = new Static3D(w/2,h/2,-d/2); |
|
118 |
float factor = 0.5f*(width>height ? height/h:width/w); |
|
119 |
|
|
120 |
mCenter.set(w/2,h/2,-d/2); |
|
121 |
mMove.set( (width-factor*w)/2 , (height-factor*h)/2 , 0 ); |
|
122 |
mScale.set(factor,factor,factor); |
|
110 | 123 |
|
111 |
mEffects.abortEffects(EffectTypes.MATRIX); |
|
112 |
mEffects.move( new Static3D( (width-scaleFactor*w)/2 , (height-scaleFactor*h)/2 , 0) ); |
|
113 |
mEffects.scale(scaleFactor); |
|
114 |
mEffects.quaternion( mRot,center ); |
|
115 |
|
|
116 | 124 |
mScreen.resize(width, height); |
117 | 125 |
} |
118 | 126 |
|
Also available in: Unified diff
Further progress with Apps: 18 (out of 30) compile now.