# Quaternion understanding

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?

• 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. – deceleratedcaviar 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

Is there a straight forward way to create a quaternion from Position + Target vector