-->

(DirectX) Generating a rotation matrix to match a

2019-07-14 15:17发布

问题:

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".