C++ DirectX FPS 相机怪异

标签 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如果您想要代码,请告诉我。谢谢。

最佳答案

即使是 fps,您也可以轻松使用 D3DXMatrixLookAtLH ( doc )。角色的眼睛位置是 pEye。对于 View 的旋转,您可以持有一个 vector ,其中包含您的视角方向的归一化 vector 。您可以使用旋转矩阵对其进行转换,并将其添加到 pAt 的 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);

关于C++ DirectX FPS 相机怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13792772/

相关文章:

c++ - boost 目录迭代器

c++ - 读取数据时如何处理不同版本的格式?

c++ - 获取投影图像像素位置

wpf - Olive (Mono) 如何实现 (W)PF?

固定大小的 C++ 数组获取垃圾值

c++ - 初始化和赋值,从引用传递

javascript - 如何将 datauri 元素转换为可以通过 React 上传的文件?

android - 打开手电筒

directx - 如何在 D3D 窗口应用程序中启用 VSYNC?

opengl - DirectX 与 OpenGL 游戏开发