我正在尝试将我的单目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 没有任何视觉效果。
但我只是无法弄清楚我需要如何更改我的单目投影矩阵或如何正确设置两个离轴投影矩阵..
也许有人可以帮助我,我会很高兴的!
非常感谢!