Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;DirectX FPS照相机的怪异之处_C++_Camera_Directx_Direct3d_Frame Rate - Fatal编程技术网

C++ C++;DirectX FPS照相机的怪异之处

C++ C++;DirectX FPS照相机的怪异之处,c++,camera,directx,direct3d,frame-rate,C++,Camera,Directx,Direct3d,Frame Rate,嘿,最近我一直在尝试在DirectX 9中制作一个工作良好的相机,但我遇到了一些问题。让我给你看看我的一些代码 我不使用D3DXMatrixLookAtLH功能,因为我也想旋转相机 D3DXMATRIX matView, matVTranslate, matVYaw, matVPitch, matVRoll; D3DXTranslation(&matVTranslate, x, y, z); D3D

嘿,最近我一直在尝试在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。如果你想知道密码,请告诉我。谢谢。

即使对于fps,您也可以轻松使用
D3DXMatrixLookAtLH
()。角色的眼睛位置是pEye。对于视图的旋转,可以保留一个向量,其中包含viewdirection的规格化向量。这一个你可以用你的旋转矩阵变换,然后把它添加到拍的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);

即使对于fps,您也可以轻松使用
D3DXMatrixLookAtLH
()。角色的眼睛位置是pEye。对于视图的旋转,可以保留一个向量,其中包含viewdirection的规格化向量。这一个你可以用你的旋转矩阵变换,然后把它添加到拍的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);

谢谢,但是你能在代码中给我看一下吗?因为我每天做太多的研究,我已经厌倦了。谢谢。我添加了一些示例代码。我还没有测试过它,但总的想法应该很清楚,希望:)这不是很好,你能用一个物体和一个完美的相机写一个简单的程序吗。如果你不想写这个简单的模板,我可以帮你做吗?我忘了在示例中将lookdir添加到cameraposition中,以获取at。希望它现在能起作用。通常我用另一种语言编码C++,所以我不能测试代码或编写一个简单的程序。谢谢。您是否愿意向我解释此函数的作用
D3DXVec3TransformCoord(&lookdir,&lookdir,&matLook)D3DXVec3TransformCoord(&lookdir,&lookdir,&matLook)