【发布时间】:2012-08-12 16:57:30
【问题描述】:
作为 android 和 openGL 2.0 es 的初学者,我正在测试一些简单的东西,看看效果如何。
我在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);
}
我希望相机始终注视正方形的中心((0,0,0) 点),但事实并非如此。相机确实在围绕正方形旋转,但正方形并没有停留在屏幕的中心......而是沿着 X 轴移动......:
我还期望如果我们给 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);
这是怎么回事?
【问题讨论】: