开发者

Quaternion rotation matrix unexpectedly has the opposite sense

开发者 https://www.devze.com 2023-04-06 12:32 出处:网络
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 matr

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 ref开发者_JS百科resh 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消