我正试图将我的单目 DirectX Engine 转换为Oculus Rift的立体镜 Renderengine。缺少的是立体投影变换来实现三维感知。
现在,我仍然使用我的标准单目投影矩阵:
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-stereoscopic-3D-in-games.pdf&ei=nAydVY6bBcL5UobagJgL&usg=AFQjCNEFhKttlYJYNbWF2-LptmcCi8bTZg&sig2=VOKBq9VE0k8nhHtA3gxN8g
并阅读NVIDIA演示文稿:GTC2010.pdf&ei=xA2dVZe3KYr8UMT6g5gL&usg=AFQjCNGeanxCoryAZvmxC1BDmf2itOgG0w&sig2=Ss2kN5gCYeoLsgJ66-442A&bvm=bv.96952980,d.d24
但我不知道该如何改变我的单目投影矩阵,或者如何正确地设置两个离轴投影矩阵。
也许有人能帮我,我会很高兴的!
非常感谢!
发布于 2016-03-11 17:26:43
我只是回来回答这个问题,即使这个问题早就解决了。
我必须建立一个立体投影变换矩阵来实现像这样的三维投影:
立体投影变换
为了将其转化为代码,我设置了一个使用OculusHMD的OculusHMD实例。有了Oculus,就有可能计算这样一个非常适合hmd的立体投影转换。尽管以前有必要配置Oculus设备,这意味着配置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];
}之后我所要做的就是将立体投影矩阵的值--它是由Oculus在第一行中计算的--复制到我自己的投影矩阵中。我们得到的是一个非常好的3D效果,就像它应该看起来:)
干杯,
https://stackoverflow.com/questions/31291657
复制相似问题