Matrix 虚拟现实中的变换矩阵问题

Matrix 虚拟现实中的变换矩阵问题,matrix,transformation,virtual-reality,openvr,Matrix,Transformation,Virtual Reality,Openvr,我对OpenVR api中的矩阵变换有一个问题 m_compositor->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); 在openvr提供的演示中: const Matrix4 & matDeviceToTracking = m_rmat4DevicePose[ unTrackedDevice ]; Matrix4 matMVP = GetCurren

我对OpenVR api中的矩阵变换有一个问题

m_compositor->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0);
在openvr提供的演示中:

const Matrix4 & matDeviceToTracking = m_rmat4DevicePose[ unTrackedDevice ];
        Matrix4 matMVP = GetCurrentViewProjectionMatrix( nEye ) * matDeviceToTracking;
        glUniformMatrix4fv( m_nRenderModelMatrixLocation, 1, GL_FALSE, matMVP.get() );
其中GetCurrentViewProjectionMatrix是使用

Matrix4 CMainApplication::GetCurrentViewProjectionMatrix( vr::Hmd_Eye nEye )
{
    Matrix4 matMVP;
    if( nEye == vr::Eye_Left )
    {
        matMVP = m_mat4ProjectionLeft * m_mat4eyePosLeft * m_mat4HMDPose;
    }
    else if( nEye == vr::Eye_Right )
    {
        matMVP = m_mat4ProjectionRight * m_mat4eyePosRight *  m_mat4HMDPose;
    }

    return matMVP;
}
问题是:

1、matDeviceToTracking从哪个空间转换到哪个空间

2、如果我已经有了modelview矩阵,并且已经可以使用hmd进行旋转,那么如何正确渲染渲染模型?我试着使用投影*modelview*m_-rmat4Device[unTrackedDevice],但没有效果。

1

在示例代码中,
matDeviceToTracking
是对
m_-rmat4DevicePose[unTrackedDevice]
的引用,它是从
TrackedDevicePose::mDeviceToAbsoluteTracking
复制而来的。这是从模型空间到世界空间的模型矩阵映射

不过,有一个陷阱。如果在示例中包含了
updatehmdmdmmatrixpose()
函数,则此函数会在更新
m_-mat4HMDPose
的值时,将
m_-mat4HMDPose[0]
从世界空间映射到模型/Hmd视图空间,与数组中的其他矩阵正好相反

二,

如果已经有模型视图矩阵,则只需将投影矩阵乘以它即可获得MVP矩阵。要渲染到HMD中,请分别对左眼和右眼使用
m_mat4ProjectionLeft*m_mat4eyePosLeft*模型视图
m_mat4ProjectionRight*m_mat4eyePosRight*模型视图
。对于在监视器上渲染,可以生成自己的视锥体并将其乘以模型视图矩阵。关于如何创建投影矩阵,以下网站是一个很好的参考:

嗨,谢谢你的回答。首先,在openvr集成之前,我已经有了一个从world到view的摄像头矩阵。因此,集成任务是支持hmd在视图矩阵中的旋转;第二项任务是支持渲染游戏中的两个控制器。@user2240897在这种情况下,通常使用相机矩阵的位置组件作为HMD空间的原点。要呈现控制器,只需参考示例代码。