在 Android 上学习 OpenGL ES 2.0。使用模拟器,运行 Android 4.1。
从Android 开发者网站 / OpenGL复制和粘贴的片段
更新onDrawFrame
方法。贴在下面。添加Matrix.setIdentityM(mRotationMatrix, 0)
,因为它是一个空矩阵。将 mAngle 更改为角度(第 16 行)。
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Create a rotation transformation for the triangle
long time = SystemClock.uptimeMillis() % 4000L;
float angle = 0.090f * ((int) time);
Matrix.setIdentityM(mRotationMatrix, 0); //added
Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, 1.0f); //changed
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
// Draw shape
mTriangle.draw(mMVPMatrix);
}
并注释掉setRenderMode(RENDERMODE_WHEN_DIRTY);
然而绘制的三角形并没有旋转。我哪里做错了?