Revision e2d8ea1d
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.DistortedCubes; |
30 | 30 |
import org.distorted.library.EffectNames; |
31 | 31 |
import org.distorted.library.EffectTypes; |
32 |
import org.distorted.library.type.Dynamic1D; |
|
32 | 33 |
import org.distorted.library.type.Dynamic3D; |
33 | 34 |
import org.distorted.library.type.Dynamic4D; |
35 |
import org.distorted.library.type.Static1D; |
|
36 |
import org.distorted.library.type.Static2D; |
|
34 | 37 |
import org.distorted.library.type.Static3D; |
35 | 38 |
import org.distorted.library.type.Static4D; |
36 | 39 |
|
... | ... | |
45 | 48 |
class Vertex3DRenderer implements GLSurfaceView.Renderer |
46 | 49 |
{ |
47 | 50 |
private static final int SIZE = 100; |
48 |
|
|
51 |
private static final int NUM = 3; |
|
52 |
|
|
49 | 53 |
private GLSurfaceView mView; |
50 | 54 |
private static DistortedCubes mCube; |
51 | 55 |
|
52 | 56 |
private static EffectNames[] order; |
53 | 57 |
|
54 |
private static Dynamic3D mMoveInter, mScaleInter, mShearInter;
|
|
55 |
private static Dynamic4D mDynamicRotate;
|
|
58 |
private static Dynamic3D mDeformInter, mDistortInter;
|
|
59 |
private static Dynamic1D mSinkInter, mSwirlInter;
|
|
56 | 60 |
|
57 |
private static Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint; |
|
58 |
private static Static4D mRotatePoint; |
|
61 |
private static Static2D mCenterPoint; |
|
62 |
private static Static3D mDeformPoint, mDistortPoint; |
|
63 |
private static Static1D mSinkPoint, mSwirlPoint; |
|
59 | 64 |
|
60 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 66 |
|
62 | 67 |
public static void setDeform(float x, float y, float z) |
63 | 68 |
{ |
64 |
mMovePoint.set(x, y, z);
|
|
69 |
mDeformPoint.set(x, y, z);
|
|
65 | 70 |
} |
66 | 71 |
|
67 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 73 |
|
69 | 74 |
public static void setDistort(float x, float y, float z) |
70 | 75 |
{ |
71 |
mScalePoint.set(x, y, z);
|
|
76 |
mDistortPoint.set(x, y, z);
|
|
72 | 77 |
} |
73 | 78 |
|
74 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 80 |
|
76 |
public static void setSink(float a, float x, float y, float z)
|
|
81 |
public static void setSink(float s)
|
|
77 | 82 |
{ |
78 |
mRotatePoint.set(a,x,y,z);
|
|
83 |
mSinkPoint.set(s);
|
|
79 | 84 |
} |
80 | 85 |
|
81 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 87 |
|
83 |
public static void setSwirl(float x, float y, float z)
|
|
88 |
public static void setSwirl(float s)
|
|
84 | 89 |
{ |
85 |
mShearPoint.set(x, y, z);
|
|
90 |
mSwirlPoint.set(s);
|
|
86 | 91 |
} |
87 | 92 |
|
88 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
90 | 95 |
public static void setOrder(EffectNames[] effects) |
91 | 96 |
{ |
92 | 97 |
order = effects; |
93 |
setMatrixEffects();
|
|
98 |
setVertexEffects();
|
|
94 | 99 |
} |
95 | 100 |
|
96 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
97 | 102 |
|
98 |
public static void setMatrixEffects()
|
|
103 |
public static void setVertexEffects()
|
|
99 | 104 |
{ |
100 |
mCube.abortEffects(EffectTypes.MATRIX);
|
|
105 |
mCube.abortEffects(EffectTypes.VERTEX);
|
|
101 | 106 |
|
102 | 107 |
for( int i=0; i<=order.length-1 ; i++ ) |
103 | 108 |
{ |
104 | 109 |
switch(order[i]) |
105 | 110 |
{ |
106 |
case MOVE : mCube.move(mMoveInter) ; break;
|
|
107 |
case SCALE : mCube.scale(mScaleInter) ; break;
|
|
108 |
case ROTATE: mCube.rotate(mDynamicRotate,mZeroPoint); break;
|
|
109 |
case SHEAR : mCube.shear(mShearInter, mZeroPoint) ; break;
|
|
111 |
case DEFORM : mCube.deform( mDeformInter , mCenterPoint) ; break;
|
|
112 |
case DISTORT: mCube.distort(mDistortInter, mCenterPoint) ; break;
|
|
113 |
case SINK : mCube.sink( mSinkInter , mCenterPoint) ; break;
|
|
114 |
case SWIRL : mCube.swirl( mSwirlInter , mCenterPoint) ; break;
|
|
110 | 115 |
} |
111 | 116 |
} |
112 | 117 |
} |
... | ... | |
116 | 121 |
public Vertex3DRenderer(GLSurfaceView v) |
117 | 122 |
{ |
118 | 123 |
mView = v; |
119 |
mCube = new DistortedCubes( 1, "1", SIZE);
|
|
124 |
mCube = new DistortedCubes( NUM, "111101111", SIZE);
|
|
120 | 125 |
|
121 |
mZeroPoint = new Static3D(0,0,0);
|
|
122 |
mMovePoint = new Static3D(0,0,0);
|
|
123 |
mScalePoint = new Static3D(1,1,1);
|
|
124 |
mShearPoint = new Static3D(0,0,0);
|
|
125 |
mRotatePoint = new Static4D(0,1,0,0);
|
|
126 |
|
|
127 |
mMoveInter = new Dynamic3D();
|
|
128 |
mScaleInter = new Dynamic3D();
|
|
129 |
mShearInter = new Dynamic3D();
|
|
130 |
mDynamicRotate= new Dynamic4D();
|
|
131 |
|
|
132 |
mMoveInter.add(mMovePoint);
|
|
133 |
mScaleInter.add(mScalePoint);
|
|
134 |
mShearInter.add(mShearPoint);
|
|
135 |
mDynamicRotate.add(mRotatePoint);
|
|
126 |
mCenterPoint = new Static2D(0,0);
|
|
127 |
mDeformPoint = new Static3D(0,0,0);
|
|
128 |
mDistortPoint= new Static3D(1,1,1);
|
|
129 |
mSwirlPoint = new Static1D(0);
|
|
130 |
mSinkPoint = new Static1D(1);
|
|
131 |
|
|
132 |
mDeformInter = new Dynamic3D();
|
|
133 |
mDistortInter = new Dynamic3D();
|
|
134 |
mSwirlInter = new Dynamic1D();
|
|
135 |
mSinkInter = new Dynamic1D();
|
|
136 |
|
|
137 |
mDeformInter.add(mDeformPoint);
|
|
138 |
mDistortInter.add(mDistortPoint);
|
|
139 |
mSwirlInter.add(mSwirlPoint);
|
|
140 |
mSinkInter.add(mSinkPoint);
|
|
136 | 141 |
} |
137 | 142 |
|
138 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
149 | 154 |
|
150 | 155 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
151 | 156 |
{ |
152 |
setMatrixEffects(); |
|
157 |
mCube.abortEffects(EffectTypes.MATRIX); |
|
158 |
float factor = (width>height ? height:width)/((NUM+2)*SIZE); |
|
159 |
mCube.scale(factor); |
|
160 |
mCube.move( new Static3D( (width-factor*NUM*SIZE)/2,(height-factor*NUM*SIZE)/2,0) ); |
|
161 |
|
|
162 |
setVertexEffects(); |
|
153 | 163 |
|
154 | 164 |
Distorted.onSurfaceChanged(width, height); |
155 | 165 |
} |
Also available in: Unified diff
Progress with Vertex3D