四元旋转矩阵意外有相反的含义
我有一些有关四元的问题。
为了让我的世界对象以正确的方式旋转,我需要在刷新对象世界矩阵时将其季节旋转倒置。
我使用此代码创建对象旋转:
Rotation = Quaternion.RotationMatrix(
Matrix.LookAtRH(Position,
Position + new Vector3(_moveDirection.X, 0, _moveDirection.Y),
Vector3.Up)
);
并刷新像这样的对象世界矩阵:
Object.World = Matrix.RotationQuaternion(Rotation)
* Matrix.Translation(Position);
这是不起作用的;它使物体以相反的方式旋转!
使我的对象正确旋转的方式是:
Object.World = Matrix.RotationQuaternion(Quaternion.invert(Rotation))
* Matrix.Translation(Position);
为什么我必须倒转对象旋转?
I have some understanding problem concerning quaternions.
In order to have my world object rotate in the correct way, I need to invert their quaternion rotation while refreshing the object world matrix.
I create the object rotation with this code:
Rotation = Quaternion.RotationMatrix(
Matrix.LookAtRH(Position,
Position + new Vector3(_moveDirection.X, 0, _moveDirection.Y),
Vector3.Up)
);
and refresh the object World matrix like this:
Object.World = Matrix.RotationQuaternion(Rotation)
* Matrix.Translation(Position);
This is not working; it makes the object rotate in the opposite way compared to what it should!
The is the way that makes my object rotate correctly:
Object.World = Matrix.RotationQuaternion(Quaternion.invert(Rotation))
* Matrix.Translation(Position);
Why do I have to invert the object rotation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是一个问题问题,而是您正在使用的DirectX调用的用法和/或文档问题。呼叫给出的转换是当您移动相机时发生的转换。如果您要保持相机固定并移动世界,那么您将交换正在移动和固定的内容。这些坐标转换是彼此的反向,这就是为什么将逆向您的逆向。
但是,您不需要显式倒数。只需交换前两个参数的顺序即可。
This isn't a quaternion problem so much as it is a usage and/or documentation issue with the DirectX call you're using. The transformation the call gives is the one that happens when you move the camera. If you're keeping the camera fixed and moving the world, you're swapping what's moving and what's fixed. These coordinate transformations are inverses of each other, which is why taking the inverse works for you.
You don't need to take an explicit inverse, though. Just swap the order of the first two arguments.