(DirectX) Generating a rotation matrix to match a

2019-07-14 14:31发布

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条回答
Fickle 薄情
2楼-- · 2019-07-14 15:21

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

查看更多
登录 后发表回答