Revision 261fe5bd
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
---|---|---|
27 | 27 |
import org.distorted.examples.R; |
28 | 28 |
import org.distorted.library.Distorted; |
29 | 29 |
import org.distorted.library.DistortedCubes; |
30 |
import org.distorted.library.DistortedObject; |
|
30 | 31 |
import org.distorted.library.EffectNames; |
31 | 32 |
import org.distorted.library.EffectTypes; |
32 | 33 |
import org.distorted.library.type.Dynamic1D; |
33 | 34 |
import org.distorted.library.type.Dynamic3D; |
34 |
import org.distorted.library.type.Dynamic4D; |
|
35 | 35 |
import org.distorted.library.type.DynamicQuat; |
36 | 36 |
import org.distorted.library.type.Static1D; |
37 | 37 |
import org.distorted.library.type.Static2D; |
... | ... | |
48 | 48 |
|
49 | 49 |
class Vertex3DRenderer implements GLSurfaceView.Renderer |
50 | 50 |
{ |
51 |
private static final int SIZE = 100; |
|
52 |
|
|
53 | 51 |
private GLSurfaceView mView; |
54 |
private static DistortedCubes mCube; |
|
55 |
private int mCols, mRows; |
|
52 |
private static DistortedObject mObject; |
|
53 |
|
|
54 |
private int mObjWidth, mObjHeight; |
|
55 |
|
|
56 | 56 |
private DynamicQuat mQuatInt1, mQuatInt2; |
57 | 57 |
|
58 | 58 |
private static EffectNames[] order; |
... | ... | |
107 | 107 |
|
108 | 108 |
public static void setVertexEffects() |
109 | 109 |
{ |
110 |
mCube.abortEffects(EffectTypes.VERTEX);
|
|
110 |
mObject.abortEffects(EffectTypes.VERTEX);
|
|
111 | 111 |
|
112 | 112 |
for( int i=0; i<=order.length-1 ; i++ ) |
113 | 113 |
{ |
114 | 114 |
switch(order[i]) |
115 | 115 |
{ |
116 |
case DEFORM : mCube.deform( mDeformInter , mCenterPoint) ; break;
|
|
117 |
case DISTORT: mCube.distort(mDistortInter, mCenterPoint) ; break;
|
|
118 |
case SINK : mCube.sink( mSinkInter , mCenterPoint) ; break;
|
|
119 |
case SWIRL : mCube.swirl( mSwirlInter , mCenterPoint) ; break;
|
|
116 |
case DEFORM : mObject.deform( mDeformInter , mCenterPoint) ; break;
|
|
117 |
case DISTORT: mObject.distort(mDistortInter, mCenterPoint) ; break;
|
|
118 |
case SINK : mObject.sink( mSinkInter , mCenterPoint) ; break;
|
|
119 |
case SWIRL : mObject.swirl( mSwirlInter , mCenterPoint) ; break;
|
|
120 | 120 |
} |
121 | 121 |
} |
122 | 122 |
} |
... | ... | |
127 | 127 |
{ |
128 | 128 |
mView = v; |
129 | 129 |
|
130 |
String shape = Vertex3DActivity.getShape(); |
|
130 |
mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), 100); |
|
131 |
//mObject = new DistortedBitmap( 100, 100, 10); |
|
131 | 132 |
|
132 |
mCols = Vertex3DActivity.getCols();
|
|
133 |
mRows = shape.length() / mCols;
|
|
133 |
mObjWidth = mObject.getWidth();
|
|
134 |
mObjHeight= mObject.getHeight();
|
|
134 | 135 |
|
135 |
mCube = new DistortedCubes( mCols, shape, SIZE); |
|
136 |
|
|
137 | 136 |
mCenterPoint = new Static2D(0,0); |
138 | 137 |
mDeformPoint = new Static3D(0,0,0); |
139 | 138 |
mDistortPoint= new Static3D(1,1,1); |
... | ... | |
167 | 166 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
168 | 167 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
169 | 168 |
|
170 |
mCube.draw(System.currentTimeMillis());
|
|
169 |
mObject.draw(System.currentTimeMillis());
|
|
171 | 170 |
} |
172 | 171 |
|
173 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
176 | 175 |
{ |
177 | 176 |
mScreenMin = width<height ? width:height; |
178 | 177 |
|
179 |
mCube.abortEffects(EffectTypes.MATRIX);
|
|
178 |
mObject.abortEffects(EffectTypes.MATRIX);
|
|
180 | 179 |
float factor; |
181 | 180 |
|
182 |
if( width*mRows > height*mCols ) // screen is more 'horizontal' than the shape
|
|
181 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
|
|
183 | 182 |
{ |
184 |
factor = ((float)height)/((mRows+2)*SIZE);
|
|
185 |
} |
|
183 |
factor = (0.8f*height)/mObjHeight;
|
|
184 |
}
|
|
186 | 185 |
else |
187 | 186 |
{ |
188 |
factor = ((float)width)/((mCols+2)*SIZE);
|
|
187 |
factor = (0.8f*width)/mObjWidth;
|
|
189 | 188 |
} |
190 | 189 |
|
191 |
mCube.move( new Static3D( (width-factor*mCols*SIZE)/2 , (height-factor*mRows*SIZE)/2 , 0) );
|
|
192 |
mCube.scale(factor);
|
|
190 |
mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
|
|
191 |
mObject.scale(factor);
|
|
193 | 192 |
|
194 |
Static3D center = new Static3D(mCols*SIZE/2,mRows*SIZE/2, 0);
|
|
193 |
Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0);
|
|
195 | 194 |
|
196 |
mCube.quaternion(mQuatInt1, center);
|
|
197 |
mCube.quaternion(mQuatInt2, center);
|
|
195 |
mObject.quaternion(mQuatInt1, center);
|
|
196 |
mObject.quaternion(mQuatInt2, center);
|
|
198 | 197 |
|
199 | 198 |
setVertexEffects(); |
200 | 199 |
|
... | ... | |
221 | 220 |
catch(IOException e) { } |
222 | 221 |
} |
223 | 222 |
|
224 |
mCube.setBitmap(bitmap);
|
|
223 |
mObject.setBitmap(bitmap);
|
|
225 | 224 |
|
226 | 225 |
try |
227 | 226 |
{ |
Also available in: Unified diff
Improvements to the Cubes & Vertex3D apps.