3
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ We sure need to know more of you transformation framework. Do you use matrix * column-vector convention or some strange row-vector * matrix convention? Maybe your Lookat function is intended for cameras and therefore does the inverse transformation to what you actually want. Also in a matrix*vector convention your combined transformation first translates the object and then rotates it. Is this even intended? \$\endgroup\$ – Chris says Reinstate Monica Sep 19 '11 at 21:43
  • 2
    \$\begingroup\$ I'm not sure what quaternions are gaining you here. You seem to be generating a matrix, converting it to a quaternion, and then converting it straight back to a matrix? Does the inversion issue still occur if you forget the quaternion and simply keep it as a matrix the whole time? BTW, @ChristianRau, row-vector convention is standard for some people, it's not "strange". :) \$\endgroup\$ – Nathan Reed Sep 19 '11 at 22:12
  • \$\begingroup\$ @Christian I guess Microsofts DX dev team is quirky then :P. \$\endgroup\$ – deceleratedcaviar Sep 19 '11 at 22:38
  • 1
    \$\begingroup\$ @Nathan I was educated with column-vectors. I have never seen vectors treated as 1-row matrices in any mathematical context. The fact that some frameworks use row-vectors and that there isn't that much difference in practice, doesn't give them a mathematical justification. But maybe the latter is not that important for you. \$\endgroup\$ – Chris says Reinstate Monica Sep 19 '11 at 22:40
  • 2
    \$\begingroup\$ @ChristianRau, there's no "mathematical justification" either way. It's just a convention. It would be nice if it was universally one way or the other, but unfortunately both conventions are in widespread use. Column vectors are dominant in pure math, but row vectors are used quite often in applied contexts...but maybe the latter is not that important for you. :) \$\endgroup\$ – Nathan Reed Sep 20 '11 at 0:11
3
\$\begingroup\$
Is there a straight forward way to create a quaternion from Position + Target vector

Yes, you will also need the up-vector though. look at my answer here

\$\endgroup\$
2
\$\begingroup\$

take a look to my answer about use of quaternions to rotate objects. You can find a way to compute the quaternion based rotation matrix after the [edit] section

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.