用于三维感知的DirectX立体投影变换

用于三维感知的DirectX立体投影变换,directx,projection-matrix,stereoscopy,Directx,Projection Matrix,Stereoscopy,我正在尝试将我的单眼DirectX引擎更改为Oculus Rift的立体图像渲染引擎。缺少的是实现3D感知的立体投影变换。 现在,我仍然使用我的标准单目投影矩阵: 1.50888 0 0 0 0 2.41421 0 0 0 0 1.0001 -0.10001 0 0 1 0 // Setup the projection matrix. fieldOfView = (float)XM_PI / 4.0f; screenAspect = (float)screenWidth / (float)s

我正在尝试将我的单眼DirectX引擎更改为Oculus Rift的立体图像渲染引擎。缺少的是实现3D感知的立体投影变换。

现在,我仍然使用我的标准单目投影矩阵:

1.50888 0 0 0
0 2.41421 0 0
0 0 1.0001 -0.10001
0 0 1 0

// Setup the projection matrix.
fieldOfView = (float)XM_PI / 4.0f;
screenAspect = (float)screenWidth / (float)screenHeight;

// Create the [Monoscope]projection matrix for 3D rendering.
XMMATRIX projectionMatrix_XmMat = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);
XMStoreFloat4x4(&projectionmatrix_, projectionMatrix_XmMat);
我已经将左眼相机平移了-0.032以创建视图矩阵,将我的右眼x_平移了0.032以创建视图矩阵。问题是立体声偏心投影矩阵(我想我需要它)。所以我想我需要以某种方式做到这一点: 我尝试了很多不同的计算,但不幸的是我得到了奇怪的结果

已经做了很多研究,这里的一些人正在成功地做到这一点:

但是方法1会产生奇怪的随机效应。我正在将相机移回Z轴,但从视觉上看,它可以进入-Z轴,获得-3.f值,所有小于-3.f的相机值都没有任何视觉效果

此外,我还通读了这篇论文:

并通过NVIDIA演示文稿阅读:

但是我不知道我需要如何改变我的单目投影矩阵,或者如何正确设置两个离轴投影矩阵

也许有人能帮我,我会很高兴的


非常感谢

我只是回来给这个问题一个答案,尽管这个问题很久以前就已经解决了

我必须建立一个立体投影变换矩阵,以实现如下3D投影:

为了将其转化为代码,我设置了一个使用oculussdk的OculusHMD实例。使用Oculus SDK,可以计算出这样一种非常适合hmd的立体投影变换。尽管之前必须配置Oculus HMD设备,这意味着需要配置eyRenderDesc、screenNear和screenDepth等

  void GraphicsAPI::StereoProjectionTransformation(int camID)
  {
    Matrix4f proj = ovrMatrix4f_Projection(OculusHMD::instance()->eyeRenderDesc_[camID-1].Fov, screenNear_, screenDepth_, false);

    stereoprojectionmatrix_._11 = proj.M[0][0];
    stereoprojectionmatrix_._21 = proj.M[0][1];
    stereoprojectionmatrix_._31 = proj.M[0][2];
    stereoprojectionmatrix_._41 = proj.M[0][3];

    stereoprojectionmatrix_._12 = proj.M[1][0];
    stereoprojectionmatrix_._22 = proj.M[1][1];
    stereoprojectionmatrix_._32 = proj.M[1][2];
    stereoprojectionmatrix_._42 = proj.M[1][3];

    stereoprojectionmatrix_._13 = proj.M[2][0];
    stereoprojectionmatrix_._23 = proj.M[2][1];
    stereoprojectionmatrix_._33 = proj.M[2][2];
    stereoprojectionmatrix_._43 = proj.M[2][3]; 

    stereoprojectionmatrix_._14 = proj.M[3][0];
    stereoprojectionmatrix_._24 = proj.M[3][1];
    stereoprojectionmatrix_._34 = proj.M[3][2];
    stereoprojectionmatrix_._44 = proj.M[3][3];
}
之后我所要做的就是将Stereoprojectionmatrix的值复制到我自己的投影矩阵中,Stereoprojectionmatrix是由Oculus SDK在第一行中计算的。我们得到的是一个非常好的3D效果,看起来应该是:)

干杯

  void GraphicsAPI::StereoProjectionTransformation(int camID)
  {
    Matrix4f proj = ovrMatrix4f_Projection(OculusHMD::instance()->eyeRenderDesc_[camID-1].Fov, screenNear_, screenDepth_, false);

    stereoprojectionmatrix_._11 = proj.M[0][0];
    stereoprojectionmatrix_._21 = proj.M[0][1];
    stereoprojectionmatrix_._31 = proj.M[0][2];
    stereoprojectionmatrix_._41 = proj.M[0][3];

    stereoprojectionmatrix_._12 = proj.M[1][0];
    stereoprojectionmatrix_._22 = proj.M[1][1];
    stereoprojectionmatrix_._32 = proj.M[1][2];
    stereoprojectionmatrix_._42 = proj.M[1][3];

    stereoprojectionmatrix_._13 = proj.M[2][0];
    stereoprojectionmatrix_._23 = proj.M[2][1];
    stereoprojectionmatrix_._33 = proj.M[2][2];
    stereoprojectionmatrix_._43 = proj.M[2][3]; 

    stereoprojectionmatrix_._14 = proj.M[3][0];
    stereoprojectionmatrix_._24 = proj.M[3][1];
    stereoprojectionmatrix_._34 = proj.M[3][2];
    stereoprojectionmatrix_._44 = proj.M[3][3];
}