作为 android 和 openGL 2.0 es 的初学者,我正在测试简单的东西并看看它是如何进行的。
我在以下位置下载了示例http://developer.android.com/training/graphics/opengl/touch.html http://developer.android.com/training/graphics/opengl/touch.html .
我更改了代码以检查是否可以设置相机围绕正方形中心 (0,0,0) 点旋转的动画。
所以我这样做了:
public void onDrawFrame(GL10 unused) {
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
// Set the camera position (View matrix)
long time = SystemClock.uptimeMillis() % 4000L;
float angle = ((float) (2*Math.PI)/ (float) 4000) * ((int) time);
Matrix.setLookAtM(mVMatrix, 0, (float) (3*Math.sin(angle)), 0, (float) (3.0f*Math.cos(angle)), 0 ,0, 0, 0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Draw square
mSquare.draw(mMVPMatrix);
}
I expected the camera to look always to the center of the square (the (0,0,0) point) but that's not what happens. The camera is indeed rotating around the square but the square does not stay in the center of the screen.. instead it is moving along the X axis...:
我还期望如果我们给 eyeX 和 eyeY 与 centerX 和 centerY 相同的值,如下所示:
Matrix.setLookAtM(mVMatrix, 0, 1, 1, -3, 1 ,1, 0, 0f, 1.0f, 0.0f);
正方形将保持其形状(我的意思是,您的视野将被拖动,但沿着与正方形平行的平面),但这也不是发生的情况:
这是我的投影矩阵:
float ratio = (float) width / height;
// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 2, 7);
这里发生了什么?