如何找到给定方向向量和向上向量的 x、y 和 z 旋转角度?
我有一个超类对象,它代表场景中的模型。该对象包含一个 3D 向量、表示其位置的 position
以及三个变量 x
、y
和 z
来描述其位置绕这些轴旋转。它的变换矩阵计算如下:
Matrix.CreateRotationX(x) *
Matrix.CreateRotationY(y) *
Matrix.CreateRotationZ(z) *
Matrix.CreateTranslation(position)
这一切都工作正常,除了在某些情况下我需要计算 x
、y
和 z
的值> 基于归一化的方向向量和向上向量。我该怎么做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将矩阵转换为四元数:
Quaternion q = Quaternion.CreateFromRotationMatrix(matrix);
,然后复制并粘贴在此页面上找到的最后一个方法并通过它运行您的四元数。
Convert the matrix to a quaternion:
Quaternion q = Quaternion.CreateFromRotationMatrix(matrix);
then copy and paste the last method found on this page and run your quaternion through it.
我自己不知道如何进行数学计算,但 Matrix.CreateLookAt 不能满足您的需求吗?
Don't know how to do the math myself but wouldn't Matrix.CreateLookAt satisfy your needs?
与 ClassicThunder 的答案相同(具有相同的限制,它为您提供所需的矩阵,而不是角度),除了它比搞乱
CreateLookAt
(这实际上是用于制作视图矩阵)要好一点。(MSDN)
IMO,你可能不应该使用或无论如何存储对象的欧拉旋转。 (另请参阅)
Same as ClassicThunder's answer (with the same limitation that it gives you the matrix you want, rather than the angles), except it's a bit nicer than messing with
CreateLookAt
(which is really for making a view matrix).(MSDN)
IMO, you should probably shouldn't be using or storing the Euler rotation of an object anyway. (see also)