C ++ DirectX FPS相机怪异

时间:2012-12-09 22:57:40

标签: c++ camera directx direct3d frame-rate

嘿,最近我一直试图在DirectX 9中制作一个好的工作相机,但我遇到了问题。所以,让我告诉你一些我的代码。

我不使用D3DXMatrixLookAtLH功能,因为我也想旋转相机。

D3DXMATRIX matView,
           matVTranslate,
           matVYaw,
           matVPitch,
           matVRoll;

D3DXTranslation(&matVTranslate, x, y, z);
D3DXRotationY(&matVYaw, yaw);
D3DXRotationX(&matVPitch, pitch);
D3DXRotationZ(&matVRoll, roll);

matView = matVTranslate * (matVPitch * matVYaw * matVRoll);

d3ddev->SetTransform(D3DTS_VIEW, &matView);

它会产生非常奇怪的效果。有没有更好的方法来创建一个fps相机?如果您想运行该程序,这是exe。 The Exe如果您需要该代码,请告诉我们。谢谢。

1 个答案:

答案 0 :(得分:3)

即使是fps,您也可以轻松使用D3DXMatrixLookAtLHdoc)。角色的眼睛位置是pEye。对于视图的旋转,您可以保存一个向量,该向量包含viewdirection的标准化向量。您可以使用您的旋转矩阵进行转换,将其添加到pE的pEye中。

D3DXMATRIX matView,
           matLook;

D3DXMatrixRotationYawPitchRoll(&matLook,pitch,yaw,roll);

D3DXVector3 lookdir;
// yaw,pitch,roll are assumed to be absolute, for deltas you must save the lookdir
lookdir = D3DXVector3(0.0,0.0,1.0);
D3DXVec3TransformCoord(&lookdir,&lookdir,&matLook);

D3DXVector3 at;
at = camerapos + lookdir;

D3DXMatrixLookAtLH(&matView,&camerapos,&at,&up);

d3ddev->SetTransform(D3DTS_VIEW, &matView);
相关问题