我正在使用默认的 android 示例代码 http://developer.android.com/training/graphics/opengl/touch.html 在此示例中,我们可以通过 toucht 事件旋转三角形。
我只想添加 x,y 轴的运动以进行测试。三角形行为并不像我预期的那样。我做错了什么?
教程中的代码突出显示了我的新行:
public void onDrawFrame(GL10 unused) {
// Draw 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);
// Draw square
mSquare.draw(mMVPMatrix);
**//Translating this matrix 'brakes' triangle
-> Matrix.translateM(mMVPMatrix, 0, 0, pos, -1.0f);
//NOTHING happens here: ??? Why?
-> Matrix.translateM(mRotationMatrix, 0, pos, 0, -1.0f);**
// Create a rotation for the triangle
// long time = SystemClock.uptimeMillis() % 4000L;
// float angle = 0.090f * ((int) time);
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);
// Draw triangle
mTriangle.draw(mMVPMatrix);
}
默认行为:
用我的代码: