Revision 261fe5bd
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/examples/cubes/CubesRenderer.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
import org.distorted.examples.R; |
29 | 29 |
|
30 |
import org.distorted.library.DistortedObject; |
|
30 | 31 |
import org.distorted.library.EffectTypes; |
31 | 32 |
import org.distorted.library.type.DynamicQuat; |
32 | 33 |
import org.distorted.library.DistortedCubes; |
... | ... | |
43 | 44 |
|
44 | 45 |
class CubesRenderer implements GLSurfaceView.Renderer |
45 | 46 |
{ |
46 |
private static final int SIZE = 100; |
|
47 |
|
|
48 |
private int mCols, mRows; |
|
49 |
|
|
50 | 47 |
private GLSurfaceView mView; |
51 |
private DistortedCubes mCubes; |
|
48 |
private DistortedObject mObject; |
|
49 |
private int mObjWidth, mObjHeight; |
|
50 |
|
|
52 | 51 |
private DynamicQuat mQuatInt1, mQuatInt2; |
53 | 52 |
|
54 | 53 |
Static4D mQuat1, mQuat2; |
... | ... | |
59 | 58 |
public CubesRenderer(GLSurfaceView v) |
60 | 59 |
{ |
61 | 60 |
mView = v; |
62 |
|
|
63 |
String shape = CubesActivity.getShape(); |
|
64 |
|
|
65 |
mCols = CubesActivity.getCols(); |
|
66 |
mRows = shape.length() / mCols; |
|
67 |
|
|
68 |
mCubes = new DistortedCubes( mCols, shape, SIZE); |
|
69 |
|
|
61 |
|
|
62 |
mObject = new DistortedCubes( CubesActivity.getCols(), CubesActivity.getShape(), 100); |
|
63 |
|
|
64 |
mObjWidth = mObject.getWidth(); |
|
65 |
mObjHeight= mObject.getHeight(); |
|
66 |
|
|
70 | 67 |
mQuat1 = new Static4D(0,0,0,1); // unity |
71 | 68 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
72 | 69 |
|
... | ... | |
84 | 81 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
85 | 82 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
86 | 83 |
|
87 |
mCubes.draw(System.currentTimeMillis());
|
|
84 |
mObject.draw(System.currentTimeMillis());
|
|
88 | 85 |
} |
89 | 86 |
|
90 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
93 | 90 |
{ |
94 | 91 |
mScreenMin = width<height ? width:height; |
95 | 92 |
|
96 |
mCubes.abortEffects(EffectTypes.MATRIX); |
|
93 |
mObject.abortEffects(EffectTypes.MATRIX); |
|
94 |
float factor; |
|
97 | 95 |
|
98 |
if( mRows/mCols > height/width )
|
|
96 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
|
|
99 | 97 |
{ |
100 |
int w = (height*mRows)/mCols; |
|
101 |
float factor = (float)height/(mRows*SIZE); |
|
102 |
|
|
103 |
mCubes.move( new Static3D((width-w)/2,0,0) ); |
|
104 |
mCubes.scale(factor); |
|
105 |
} |
|
98 |
factor = (0.8f*height)/mObjHeight; |
|
99 |
} |
|
106 | 100 |
else |
107 |
{ |
|
108 |
int h = (width*mRows)/mCols; |
|
109 |
float factor = (float)width/(mCols*SIZE); |
|
110 |
|
|
111 |
mCubes.move( new Static3D(0,(height-h)/2,0) ); |
|
112 |
mCubes.scale(factor); |
|
101 |
{ |
|
102 |
factor = (0.8f*width)/mObjWidth; |
|
113 | 103 |
} |
114 |
|
|
115 |
Static3D center = new Static3D(mCols*SIZE/2,mRows*SIZE/2, 0); |
|
116 |
|
|
117 |
mCubes.quaternion(mQuatInt1, center); |
|
118 |
mCubes.quaternion(mQuatInt2, center); |
|
104 |
|
|
105 |
mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) ); |
|
106 |
mObject.scale(factor); |
|
107 |
Static3D center = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
|
108 |
|
|
109 |
mObject.quaternion(mQuatInt1, center); |
|
110 |
mObject.quaternion(mQuatInt2, center); |
|
119 | 111 |
|
120 | 112 |
Distorted.onSurfaceChanged(width, height); |
121 | 113 |
} |
... | ... | |
140 | 132 |
catch(IOException e) { } |
141 | 133 |
} |
142 | 134 |
|
143 |
mCubes.setBitmap(bitmap);
|
|
135 |
mObject.setBitmap(bitmap);
|
|
144 | 136 |
|
145 | 137 |
try |
146 | 138 |
{ |
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.