0

我正在尝试将我的单目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_translated 0.032以创建视图矩阵。问题是立体偏离中心投影矩阵(我认为我需要)。所以我想我需要以某种方式这样做:http ://paulbourke.net/exhibition/vpac/theory2.gif 尝试了很多不同的计算,但不幸的是我得到了奇怪的结果..

已经研究了很多,这里的一些人正在成功地这样做http://www.gamedev.net/topic/597564-view-and-projection-matrices-for-vr-window-using-head-tracking/

// Window Size 1200x800, 3:2
// XMFLOAT3 Position = camera_->GetPosition();
// [Method 1] ------------------------------------------------------------
//float left = screenNear_ * (-3.f - position.x) / position.z;
//float right = screenNear_ * (3.f - position.x) / position.z;
//float bottom = screenNear_ * (-2.f - position.y) / position.z;
//float top = screenNear_ * (2.f - position.y) / position.z;

//XMMATRIX stereomatrix = XMMatrixPerspectiveOffCenterLH(left, right, bottom, top, screenNear_, screenDepth_);
//XMStoreFloat4x4(&stereoprojectionmatrix_, stereomatrix);

但是方法 1会导致奇怪的随机效应。我将我的相机移回 Z 轴,但在视觉上它只能进入 -z 轴以获得 -3.f 值,所有相机值 < -3.f 没有任何视觉效果。

此外,我还在阅读这篇论文:http ://www.google.at/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CCkQFjAB&url=http%3A%2F%2Fwww.marries.nl% 2Fwp-content%2Fuploads%2F2011%2F05%2FApplying-stereoscope-3D-in-games.pdf&ei=nAydVY6bBcL5UobagJgL&usg=AFQjCNEFhKttlYJYNbWF2-LptmcCi8bTZg&sig2=VOKBq9VE0k8nhHtA3gxN8g

并阅读NVIDIA 演示文稿http ://www.google.at/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCIQFjAA&url=http%3A%2F%2Fwww.nvidia.com%2Fcontent%2FGTC -2010%2Fpdfs%2F2010_GTC2010.pdf&ei=xA2dVZe3KYr8UMT6g5gL&usg=AFQjCNGeanxCoryAZvmxC1BDmf2itOgG0w&sig2=Ss2kN5gCYeoLsgJ66-442A&bvm=bv.96952980,d.d24

但我只是无法弄清楚我需要如何更改我的单目投影矩阵或如何正确设置两个离轴投影矩阵..

也许有人可以帮助我,我会很高兴的!

非常感谢!

4

1 回答 1

0

我只是回到这里来回答这个问题,即使它早就解决了。

我必须设置一个立体投影变换矩阵来实现这样的 3D 投影:

立体投影变换

为了将其写入代码,我设置了一个使用 Oculus SDK 的 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 的值(由 Oculus SDK 在第一行计算)复制到我自己的投影矩阵中。我们得到的是一个非常漂亮的 3D 效果,看起来应该是这样的 :)

干杯,

于 2016-03-11T17:26:43.370 回答