在我的程序中,我在投影矩阵中定义了一个不对称平截头体,它根据用户的位置而变化。对于所有 z 值都在同一位置的平面,我的程序可以正常工作。但是,如果观察平面有点旋转(沿 Y 方向旋转),然后我通过执行矩阵glRotate
中的操作来旋转相机。ModelView
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(topLeftX, bottomRightX, bottomRightY, topLeftY, camNear, camFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(xHeadPosition, yHeadPosition, zHead, xHeadPosition, yHeadPosition, zHead -1 , 0, 1, 0);
glTranslatef(400, 0); //Rotating with the right side of the plane as the pivot
glRotatef(yRotation, 0, 1, 0);
glTranslatef(-400, 0);
但是,我想在投影中做同样的事情以保持 MV 矩阵的清洁。我尝试执行以下操作:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(400, 0); // Pre-multiplication here as opposed to post-mulitplication in MV matrix
glRotatef(yRotation, 0, 1, 0);
glTranslatef(-400, 0);
glFrustum(topLeftX, bottomRightX, bottomRightY, topLeftY, camNear, camFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(xHeadPosition, yHeadPosition, zHead, xHeadPosition, yHeadPosition, zHead -1 , 0, 1, 0);
但是,以上内容并没有给我所需的输出,并且似乎没有旋转投影平面以使观察平面垂直于用户/相机。如何旋转投影平面以使其垂直于用户?