用于3D感知的DirectX立体投影变换

时间:2015-07-08 11:44:42

标签: directx projection-matrix stereoscopy

我正在尝试将我的 Monocular DirectX引擎更改为用于Oculus Rift的Stereoscopy Renderengine。缺少的是立体投影转换以实现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 用于创建View Matrix。问题是立体声偏离中心投影矩阵(我认为我需要)。所以我想我需要以某种方式做到这一点: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-stereoscopic-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

但我无法弄清楚我是如何改变我的单眼投影矩阵或如何正确设置两个离轴投影矩阵。

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

非常感谢!

1 个答案:

答案 0 :(得分:0)

我刚刚回到这里回答这个问题,即使它已经很久以前就已经解决了。

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

Stereo Projection Transformation

为了将其转化为代码,我设置了一个使用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效果,就像看起来像:)

欢呼声,

相关问题