Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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? – Christian Rau Sep 19 '11 at 21:43
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". :) – Nathan Reed Sep 19 '11 at 22:12
@Christian I guess Microsofts DX dev team is quirky then :P. – dcousens Sep 19 '11 at 22:38
@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. – Christian Rau Sep 19 '11 at 22:40
@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. :) – Nathan Reed Sep 20 '11 at 0:11
up vote 3 down vote accepted
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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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