(DirectX) Generating a rotation matrix to match a vector

纵然是瞬间 提交于 2020-01-04 14:03:28

问题


How can I take a vector and generate a matrix that will rotate a mesh to face along that vector?

Specifics:

I want the model for my player to rotate to face the direction that the camera is looking. Right now, it always points in the direction it started in, and turning just makes the camera look at the player's side.

I have experimented with D3DXMatrixYawPitchRoll, with partial success. However, I noticed some drift in time from perfect alignment, and it had some strange wobbly issues when I tried pitching while yawing.


回答1:


It will work in almost exactly the same way as this answer I've posted:

Rotate a sphere so that its pole heads towards the camera

The main change is that instead of "camera position" - "object origin" you do "object origin" - "camera position".



来源:https://stackoverflow.com/questions/6204583/directx-generating-a-rotation-matrix-to-match-a-vector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!