我有6个不同纹理的立方体。我写了smiple动画。当我旋转我的立方体时,每一件事都没问题,但在我的动画之后我的纹理会改变它们的位置。
在示例中。 我在左边旋转我的立方体。我看到右侧但前面有纹理(动画之后)。
当动画片中的立方体在动画中看到正确的纹理时,但在纹理从正面变为纹理之后。
这是我的立方体绘制方法代码。
public void draw(GL10 gl) {
gl.glFrontFace(GL10.GL_CCW);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuffer);
// front
gl.glPushMatrix();
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[front]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
gl.glPopMatrix();
// left
gl.glPushMatrix();
gl.glRotatef(270.0f, 0f, 1f, 0f);
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[left]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
gl.glPopMatrix();
// back
gl.glPushMatrix();
gl.glRotatef(180.0f, 0f, 1f, 0f);
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[back]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
gl.glPopMatrix();
// right
gl.glPushMatrix();
gl.glRotatef(90.0f, 0f, 1f, 0f);
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[right]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);
gl.glPopMatrix();
// top
gl.glPushMatrix();
gl.glRotatef(270.0f, 1f, 0f, 0f);
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[top]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
gl.glPopMatrix();
// bottom
gl.glPushMatrix();
gl.glRotatef(90.0f, 1f, 0f, 0f);
gl.glTranslatef(0f, 0f, cubeHalfSize);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[bottom]);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
gl.glPopMatrix();
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
这是我的更新方法
public void updateRotation(GL10 gl) {
if (currentProgress >= 1f) {
return;
}
long dt = System.currentTimeMillis() - getAnimStart();
currentProgress = dt / (float) animTime;
Log.d("progress", "" + currentProgress);
if (currentProgress > 1f) {
currentProgress = 1;
}
else if(currentProgress < 0){
currentProgress = 0;
}
currentProgress = interpolator.getInterpolation(currentProgress);
setCurrentRotX((initialRotX + (targetRotX - initialRotX) * currentProgress));
gl.glRotatef(-(float)((getCurrentRotX() * 180)/Math.PI), 1.0f, 0.0f, 0.0f);
setCurrentRotY(initialRotY + (targetRotY - initialRotY) * currentProgress);
gl.glRotatef(-(float)((getCurrentRotY() * 180)/Math.PI), 0.0f, 1.0f, 0.0f);
}