旋转矩阵,使 Up 向量等于另一个向量
我想调整矩阵的方向,使向上向量与另一个向量面向相同的方向。向前和向右向量的方向并不重要。
例如:
matrix4 m; // m.Up = 0, 1, 0
vector3 v = V3(1,0,0);
// Then I think I have to get the rotation from m.Up and v
// And then rotate the matrix accordingly
但我不知道该怎么做,我可能是错的。
I want to orient my matrix so that the Up vector it facing the same direction as another vector. The orientation of the Forward and Right vectors do not matter.
For example:
matrix4 m; // m.Up = 0, 1, 0
vector3 v = V3(1,0,0);
// Then I think I have to get the rotation from m.Up and v
// And then rotate the matrix accordingly
But I don't know how todo this and I may be wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是矩阵特别有用的旋转问题之一
。首先,将矩阵拆分为三个分量向量(向上、向前和向右)。
将您的向上向量设置为您想要的值。然后,调整前向和右向向量,使它们成直角,一个简单的方法是使用叉积。
例如:
之后,将向量插回到矩阵中,瞧:D。
This is one of the rotation problems that matricies are particularly useful for
First, split your matrix into the three component vectors (up, forward, and right).
Set your up vector to what you want it to be. Then, adjust your forward and right vectors so that they are at right angles, an easy way to do this would be through the use of cross products.
For example:
After that, plug your vectors back into the matrix and voila :D.
如果我理解正确,只需将矩阵中的轴设置为您选择的向量即可。正如您所说,前向和右向矢量并不重要,请将它们设置为任何值,只要它们与新的上轴正交即可。
If I understand correctly, simply set your up axis in the matrix to your chosen vector. As you say that the forward and right vectors do not matter, set them to anything as long as they are orthonormal to your new up axis.