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 an object with a position matrix and a rotation matrix (derived from a quaternion, but I digress). I'm able to translate this object along world-relative vectors, but I'm trying to figure out how to translate it along local-relative vectors. So if the object is tilted 45 degrees around its Z-axis the vector (1, 0, 0) would make it move to the upper right.

For world-space translations I simply turn the movement vector into a matrix and multiply it by the position matrix: position_mat = translation_mat * position_mat. For local-space translations I'd think I'd have to use the rotation matrix into that formula, but I see the object spin around instead when I apply a translation over time no matter where I multiply the rotation matrix.

share|improve this question
up vote 4 down vote accepted

Just take the desired movement vector, multiply it by the object's rotation matrix, then use the result as before, i.e. convert it to a translation matrix and multiply it into the position_mat.

share|improve this answer
As far as I understand you, I want to do position_mat = (translation_mat * rotation_mat) * position_mat. I've tried this already but, as I said before, the translation doesn't go in a straight line. So if my object is tilted to the left and I try to translate it to go towards its local left (upper-left in world space) over a period of time, the object spins around instead. – Aaron Jul 5 '12 at 23:08
@Aaron, multiplying the matrices like that is not the same as what I said. You need to apply the rotation matrix to the translation vector, before converting it into a translation matrix. What you posted does something else: it also incorporates the rotation matrix into position_mat, applying the rotation to the whole object instead of just the translation vector. And since you do this every frame, of course the object spins around over time. – Nathan Reed Jul 5 '12 at 23:11
Thanks. I didn't realize the difference between the translation vector and the translation matrix. – Aaron Jul 6 '12 at 3:27

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.