【问题标题】:Rotate camera in own coord using gluLookat and glMultMatrixf使用 gluLookat 和 glMultMatrixf 以自己的坐标旋转相机
【发布时间】:2016-06-15 10:49:23
【问题描述】:

我必须更改使用gluLookatglMultmatrixf 构建的相机实现。

实现的相机是一个轨迹球相机,相机围绕一个点旋转。

相机的方向是由

//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);

然后是

glMultMatrixf(transformViewMatrix);

围绕点移动相机,其中transformViewMatrix是根据鼠标坐标计算的


我必须将 Oculus Rift 与相机集成,以便相机可以原地旋转而不是围绕一个点旋转。

我可以从 Oculus 传感器获得一个旋转矩阵,rotOculus

我尝试将transforViewMatrixrotOculus 相乘。

glMultMatrixf(transformViewMatrix*rotOculus);

但要知道我正在看的对象是原地旋转而不是相机

然后我尝试将transformViewMatrix 分配给rotOculus,但这与使用鼠标进行轨迹球旋转相同,只是更改为Oculus。

我认为为了现场旋转相机,我需要将相机转换为原点pCamera,然后glMultMatrixf(rotOculus)

但我无法访问如何订购 glTranslategluLookAtglMultMatrixf 方法,因为这些方法是在 dll 中实现的,我只能更改 pCamerapTargetupviewTransformMatrix.

谁能指出我在这种情况下如何现场旋转相机? 谢谢。

【问题讨论】:

    标签: opengl rotation matrix-multiplication oculus glulookat


    【解决方案1】:

    您想要移动观察向量,它是 pCamera 和 pTarget 之间的线。你没有指定你正在使用什么类型,但代码应该是这样的

    // 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多