我知道openGL ES 1.0可以popmatrix
,并推送矩阵。但在ES 2.0中,我不知道该怎么做。当我trans
或rotate
我的对象时,它也会影响其他对象。我想解决这个问题,谢谢:)
这是我的示例代码:
//lego
Matrix.translateM(modelViewMatrix, 0, step_w, step_h, 0);
Matrix.setRotateM(rotationMatrix, 0, angle, 0.0f, 0.0f, 1.0f);
Matrix.multiplyMM(modelViewMatrix, 0, modelViewMatrix, 0, rotationMatrix, 0);
Matrix.setRotateM(rotationMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
Matrix.multiplyMM(modelViewMatrix, 0, modelViewMatrix, 0, rotationMatrix, 0);
Matrix.multiplyMM(modelViewProjectionScaled, 0, projectionMatrix, 0, modelViewMatrix, 0);
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT, false, 0, (FloatBuffer) verticeBuffers.get(0));
GLES20.glVertexAttribPointer(textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, (FloatBuffer) textureBuffers.get(0));
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, thisTexture.mTextureID[0]);
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjectionScaled, 0);
GLES20.glUniform1i(texSampler2DHandle, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mObj.getNumObjectVertex(0));
//tomato
Matrix.translateM(modelViewMatrix, 0, -30, -30, 0);
Matrix.setRotateM(rotationMatrix, 0, 90, 0.0f, 0.0f, 1.0f);
Matrix.multiplyMM(modelViewMatrix, 0, modelViewMatrix, 0, rotationMatrix, 0);
Matrix.setRotateM(rotationMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
Matrix.multiplyMM(modelViewMatrix, 0, modelViewMatrix, 0, rotationMatrix, 0);
Matrix.multiplyMM(modelViewProjectionScaled, 0, projectionMatrix, 0, modelViewMatrix, 0);
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
false, 0, (FloatBuffer) verticeBuffers_to.get(0));
GLES20.glVertexAttribPointer(textureCoordHandle, 2, GLES20.GL_FLOAT,
false, 0, (FloatBuffer) textureBuffers_to.get(0));
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, toTexture.mTextureID[0]);
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjectionScaled, 0);
GLES20.glUniform1i(texSampler2DHandle, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mObj_to.getNumObjectVertex(0));
如果我试图改变乐高,番茄也会移动。