Rotate camera in own coord using gluLookat and glMultMatrixf
我必须更改使用
实现的相机是一个弧形球相机,其中相机围绕一个点旋转。
相机的方向是
1 2 3 4 5 6 7 8 9 10 | //set projection glMatrixMode(GL_PROJECTION); gluPerspective (..); //modelview glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(pCamera.x, pCamera.y, pCamera.z, pTarget.x, pTarget.y, pTarget.z, up.x, up.y, up.z); |
然后是
1 | glMultMatrixf(transformViewMatrix); |
使相机绕点移动,根据鼠标坐标计算
我必须将Oculus Rift与相机集成在一起,以便相机可以在原地旋转,而不是围绕某个点旋转。
我可以从Oculus传感器
我尝试将
1 | glMultMatrixf(transformViewMatrix*rotOculus); |
但是得到的是我正在看的物体是在原地旋转而不是在旋转
然后我尝试用
我想为了现场旋转摄像机,我需要先按
但是我无法访问如何订购
在这种情况下,谁能指出我该如何现场旋转相机?
谢谢。
您要移动查找向量,它是pCamera和pTarget之间的线。 您没有指定要使用的类型,但是代码应如下所示
1 2 3 4 5 6 7 8 9 10 11 12 | // Get the lookat vector vec3 lookAtVector = pTarget - pCamera; // Rotate by the HMD orientation lookAtVector = rotOculus * lookAtVector; // Add back the camera vector to get the worldspace target vec3 newTarget = lookAtVector + pCamera; // Upload the view matrix to GL gluLookAt(pCamera.x, pCamera.y, pCamera.z, newTarget.x, newTarget.y, newTarget.z, up.x, up.y, up.z); |