Revision 261fe5bd
Added by Leszek Koltunski almost 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 |
{ |
Also available in: Unified diff
Improvements to the Cubes & Vertex3D apps.