如何找到给定方向向量和向上向量的 x、y 和 z 旋转角度?

发布于 2024-12-18 17:00:31 字数 400 浏览 4 评论 0 原文

我有一个超类对象,它代表场景中的模型。该对象包含一个 3D 向量、表示其位置的 position 以及三个变量 xyz 来描述其位置绕这些轴旋转。它的变换矩阵计算如下:

Matrix.CreateRotationX(x) *
Matrix.CreateRotationY(y) *
Matrix.CreateRotationZ(z) *
Matrix.CreateTranslation(position)

这一切都工作正常,除了在某些情况下我需要计算 xyz 的值> 基于归一化的方向向量和向上向量。我该怎么做?

I have a superclass object which represents a model in a scene. This object contains a 3D vector, position for its location and three variables x, y and z to describe its rotation around those axes. Its transformation matrix is calculated as follows:

Matrix.CreateRotationX(x) *
Matrix.CreateRotationY(y) *
Matrix.CreateRotationZ(z) *
Matrix.CreateTranslation(position)

This is all working fine, except in some circumstances I need to calculate the values for x, y and z based on a normalised directional vector and an up vector. How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

下壹個目標 2024-12-25 17:00:31

将矩阵转换为四元数:

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.

时间海 2024-12-25 17:00:31

我自己不知道如何进行数学计算,但 Matrix.CreateLookAt 不能满足您的需求吗?

Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(x, y, z), yourUpVector) 
* Matrix.CreateTranslation(position);

Don't know how to do the math myself but wouldn't Matrix.CreateLookAt satisfy your needs?

Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(x, y, z), yourUpVector) 
* Matrix.CreateTranslation(position);
韵柒 2024-12-25 17:00:31

与 ClassicThunder 的答案相同(具有相同的限制,它为您提供所需的矩阵,而不是角度),除了它比搞乱 CreateLookAt (这实际上是用于制作视图矩阵)要好一点。

Matrix.CreateWorld(position, direction, up);

(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).

Matrix.CreateWorld(position, direction, up);

(MSDN)

IMO, you should probably shouldn't be using or storing the Euler rotation of an object anyway. (see also)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文