40 |
40 |
{
|
41 |
41 |
private static final int NUM_UNIFORMS = 7;
|
42 |
42 |
private static final int INDEX = EffectTypes.MATRIX.ordinal();
|
43 |
|
private static float[] mMVPMatrix= new float[16];
|
44 |
|
private static float[] mTmpMatrix= new float[16];
|
45 |
|
|
|
43 |
|
|
44 |
private static float[] mMVPMatrix = new float[16];
|
|
45 |
private static float[] mTmpMatrix = new float[16];
|
|
46 |
private static float[] mViewMatrix= new float[16];
|
|
47 |
|
46 |
48 |
private static int mObjDH; // This is a handle to half a Object dimensions
|
47 |
49 |
private static int mDepthH; // Handle to the max Depth, i.e (farplane-nearplane)/2
|
48 |
50 |
private static int mMVPMatrixH; // pass in the transformation matrix
|
... | ... | |
151 |
153 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152 |
154 |
// here construct the ModelView Matrix
|
153 |
155 |
|
154 |
|
synchronized void send(float[] viewMatrix, DistortedProjection dp)
|
|
156 |
synchronized void send(DistortedProjection dp)
|
155 |
157 |
{
|
156 |
|
Matrix.setIdentityM(viewMatrix, 0);
|
157 |
|
Matrix.translateM(viewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance);
|
|
158 |
Matrix.setIdentityM(mViewMatrix, 0);
|
|
159 |
Matrix.translateM(mViewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance);
|
158 |
160 |
|
159 |
161 |
float x,y,z, sx,sy,sz;
|
160 |
162 |
|
... | ... | |
166 |
168 |
y = mUniforms[NUM_UNIFORMS*i+5];
|
167 |
169 |
z = mUniforms[NUM_UNIFORMS*i+6];
|
168 |
170 |
|
169 |
|
Matrix.translateM(viewMatrix, 0, x,-y, z);
|
170 |
|
Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
|
171 |
|
Matrix.translateM(viewMatrix, 0,-x, y,-z);
|
|
171 |
Matrix.translateM(mViewMatrix, 0, x,-y, z);
|
|
172 |
Matrix.rotateM( mViewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
|
|
173 |
Matrix.translateM(mViewMatrix, 0,-x, y,-z);
|
172 |
174 |
}
|
173 |
175 |
else if(mName[i] == EffectNames.QUATERNION.ordinal() )
|
174 |
176 |
{
|
... | ... | |
176 |
178 |
y = mUniforms[NUM_UNIFORMS*i+5];
|
177 |
179 |
z = mUniforms[NUM_UNIFORMS*i+6];
|
178 |
180 |
|
179 |
|
Matrix.translateM(viewMatrix, 0, x,-y, z);
|
180 |
|
multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
|
181 |
|
Matrix.translateM(viewMatrix, 0,-x, y,-z);
|
|
181 |
Matrix.translateM(mViewMatrix, 0, x,-y, z);
|
|
182 |
multiplyByQuat(mViewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
|
|
183 |
Matrix.translateM(mViewMatrix, 0,-x, y,-z);
|
182 |
184 |
}
|
183 |
185 |
else if(mName[i] == EffectNames.MOVE.ordinal() )
|
184 |
186 |
{
|
... | ... | |
186 |
188 |
sy = mUniforms[NUM_UNIFORMS*i+1];
|
187 |
189 |
sz = mUniforms[NUM_UNIFORMS*i+2];
|
188 |
190 |
|
189 |
|
Matrix.translateM(viewMatrix, 0, sx,-sy, sz);
|
|
191 |
Matrix.translateM(mViewMatrix, 0, sx,-sy, sz);
|
190 |
192 |
}
|
191 |
193 |
else if(mName[i] == EffectNames.SCALE.ordinal() )
|
192 |
194 |
{
|
... | ... | |
194 |
196 |
sy = mUniforms[NUM_UNIFORMS*i+1];
|
195 |
197 |
sz = mUniforms[NUM_UNIFORMS*i+2];
|
196 |
198 |
|
197 |
|
Matrix.scaleM(viewMatrix, 0, sx, sy, sz);
|
|
199 |
Matrix.scaleM(mViewMatrix, 0, sx, sy, sz);
|
198 |
200 |
}
|
199 |
201 |
else if(mName[i] == EffectNames.SHEAR.ordinal() )
|
200 |
202 |
{
|
... | ... | |
206 |
208 |
y = mUniforms[NUM_UNIFORMS*i+5];
|
207 |
209 |
z = mUniforms[NUM_UNIFORMS*i+6];
|
208 |
210 |
|
209 |
|
Matrix.translateM(viewMatrix, 0, x,-y, z);
|
|
211 |
Matrix.translateM(mViewMatrix, 0, x,-y, z);
|
210 |
212 |
|
211 |
|
viewMatrix[4] += sx*viewMatrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
|
212 |
|
viewMatrix[5] += sx*viewMatrix[1]; // 0 1 0 0
|
213 |
|
viewMatrix[6] += sx*viewMatrix[2]; // 0 0 1 0
|
214 |
|
viewMatrix[7] += sx*viewMatrix[3]; // 0 0 0 1
|
|
213 |
mViewMatrix[4] += sx*mViewMatrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
|
|
214 |
mViewMatrix[5] += sx*mViewMatrix[1]; // 0 1 0 0
|
|
215 |
mViewMatrix[6] += sx*mViewMatrix[2]; // 0 0 1 0
|
|
216 |
mViewMatrix[7] += sx*mViewMatrix[3]; // 0 0 0 1
|
215 |
217 |
|
216 |
|
viewMatrix[0] += sy*viewMatrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
|
217 |
|
viewMatrix[1] += sy*viewMatrix[5]; // y 1 0 0
|
218 |
|
viewMatrix[2] += sy*viewMatrix[6]; // 0 0 1 0
|
219 |
|
viewMatrix[3] += sy*viewMatrix[7]; // 0 0 0 1
|
|
218 |
mViewMatrix[0] += sy*mViewMatrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear.
|
|
219 |
mViewMatrix[1] += sy*mViewMatrix[5]; // y 1 0 0
|
|
220 |
mViewMatrix[2] += sy*mViewMatrix[6]; // 0 0 1 0
|
|
221 |
mViewMatrix[3] += sy*mViewMatrix[7]; // 0 0 0 1
|
220 |
222 |
|
221 |
|
viewMatrix[4] += sz*viewMatrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
|
222 |
|
viewMatrix[5] += sz*viewMatrix[9]; // 0 1 0 0
|
223 |
|
viewMatrix[6] += sz*viewMatrix[10];// 0 z 1 0
|
224 |
|
viewMatrix[7] += sz*viewMatrix[11];// 0 0 0 1
|
|
223 |
mViewMatrix[4] += sz*mViewMatrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear.
|
|
224 |
mViewMatrix[5] += sz*mViewMatrix[9]; // 0 1 0 0
|
|
225 |
mViewMatrix[6] += sz*mViewMatrix[10];// 0 z 1 0
|
|
226 |
mViewMatrix[7] += sz*mViewMatrix[11];// 0 0 0 1
|
225 |
227 |
|
226 |
|
Matrix.translateM(viewMatrix, 0,-x, y, -z);
|
|
228 |
Matrix.translateM(mViewMatrix, 0,-x, y, -z);
|
227 |
229 |
}
|
228 |
230 |
}
|
229 |
231 |
|
230 |
|
Matrix.translateM(viewMatrix, 0, mObjHalfX,-mObjHalfY, 0);
|
231 |
|
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, viewMatrix, 0);
|
|
232 |
Matrix.translateM(mViewMatrix, 0, mObjHalfX,-mObjHalfY, 0);
|
|
233 |
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mViewMatrix, 0);
|
232 |
234 |
|
233 |
235 |
GLES20.glUniform3f( mObjDH , mObjHalfX, mObjHalfY, mObjHalfZ);
|
234 |
236 |
GLES20.glUniform1f( mDepthH, dp.depth);
|
235 |
|
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, viewMatrix, 0);
|
236 |
|
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
|
|
237 |
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0);
|
|
238 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
|
237 |
239 |
}
|
238 |
240 |
|
239 |
241 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Minor stuff