(DirectX)生成旋转矩阵以匹配向量 [英] (DirectX) Generating a rotation matrix to match a vector

查看:188
本文介绍了(DirectX)生成旋转矩阵以匹配向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取一个向量并生成一个矩阵,该矩阵将沿着该向量旋转网格使其面向面?

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

特殊之处:

我希望播放器的模型能够旋转以面向相机所望的方向。现在,它总是指向开始的方向,而转弯只会使相机朝玩家的侧面看。

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.

我已经对D3DXMatrixYawPitchRoll进行了实验,但取得了部分成功。但是,我注意到完美对准的时间有些漂移,当我在偏航时尝试俯仰时,它存在一些奇怪的摆动问题。

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.

推荐答案

它的工作方式与我发布的答案几乎完全相同:

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

旋转球体,使其极点朝向相机

主要变化是,您要做的不是相机位置-对象原点,而是对象原点-摄像机位置。

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

这篇关于(DirectX)生成旋转矩阵以匹配向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆