我正在尝试围绕其中心(0、0、0)旋转一个三角形,然后将其平移(0.5、0.5、0)。但是,无论我将translateM命令放在rotateM命令之前还是之后,我仍然得到相同的结果,这是一个平移到所述位置的三角形,围绕 (0, 0, 0) 旋转(如果您愿意,可以绕行)。我在网上找了类似的帖子,但它们没有帮助。这是我的代码:
注意:我的三角形都以 (0, 0, 0) 为中心。
Matrix.setIdentityM(mModelMatrix, 0);
// *** transform shape before rendering
Matrix.setRotateM(mRotationMatrix, 0, rx, -1.0f, 0, 0);
Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate
Matrix.setRotateM(mRotationMatrix, 0, ry, 0, -1.0f, 0);
Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate
Matrix.setRotateM(mRotationMatrix, 0, rz, 0, 0, -1.0f);
Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate
Matrix.translateM(mModelMatrix, 0, tx, ty, tz); // translate
Matrix.multiplyMM(mvpMatrix, 0, mModelMatrix, 0, mvpMatrix, 0); // world view
// *** render
// Add program to OpenGL environment
GLES20.glUseProgram(mProgram);
// get handle to vertex shader's vPosition member
mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
// Enable a handle to the triangle vertices
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Prepare the triangle coordinate data
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
vertexStride, vertexBuffer);
// get handle to fragment shader's vColor member
mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
// Set color for drawing the triangle
GLES20.glUniform4fv(mColorHandle, 1, color, 0);
// get handle to shape's transformation matrix
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
MyGL20Renderer.checkGlError("glGetUniformLocation");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
MyGL20Renderer.checkGlError("glUniformMatrix4fv");
// Draw the triangle
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);
任何建议,将不胜感激。