public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
mBoneMatHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "a_Bone");
BindMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_BindShapeMatrix");
IBMHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_InverseBindShape");
// public int BindMatrixHandle;
//mBoneMat = animations[0];
//mBoneMat ={1, 0, 0, 5, 0, 1, 0, 5, 0 , 0, 1, 0, 0, 0, 0, 1};
long time = SystemClock.uptimeMillis() % 10000L;
LastTime = ThisTime;
ThisTime = SystemClock.elapsedRealtime();
// ElapsedTime = ThisTime - LastTime;
GameTime += ThisTime;
RealTime = ThisTime/1000;
// Log.d("Time", Float.toString(ThisTime));
// for(int i = 0; i<11; i++)
// {
for(int j = 0; j<16; j++)
{
CombinedBone[j] = Bone[j] * animations[animCounter][j];
}
animCounter++;
if(animCounter == 11)
animCounter = 0;
// Log.d("Counter", Integer.toString(animCounter));
//}
// Log.d("Time", Float.toString(GameTime));
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Calculate position of the light. Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -15.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
Matrix.translateM(mLightModelMatrix, 0,-15.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
Matrix.setIdentityM(mModelMatrix, 0);
drawCube();
}
private void drawCube()
{
mVertices.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mVertices);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
0, mColors);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
// (which now contains model * view * projection).
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
//Matrix.multiplyMM(Bone, 0, controllerMat, 0, Bone,0);
//Matrix.multiplyMM(Bone, 0, mBindMatrix, 0, Bone, 0);
GLES20.glUniformMatrix4fv(mBoneMatHandle, 1, false, Identity, 0);
Matrix.setIdentityM(Identity, 0);
GLES20.glUniformMatrix4fv(IBMHandle, 1, false, Identity, 0);
GLES20.glUniformMatrix4fv(BindMatrixHandle, 1, false, mBindMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0,72);
}