簡體   English   中英

C ++ DirectX FPS相機怪異

[英]C++ DirectX FPS Camera Weirdness

嘿,最近我一直在嘗試用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文件。 exe文件 ,如果你想代碼,請讓我知道。 謝謝。

您甚至可以為fps輕松使用D3DXMatrixLookAtLHdoc )。 角色的眼睛位置為pEye。 為了旋轉視圖,您可以保存一個向量,其中包含視圖方向的標准化向量。 您可以使用您的旋轉矩陣進行變換,然后將其添加到pEye的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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM