# Translate along local axis

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.

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.
• 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. Jul 5, 2012 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. Jul 5, 2012 at 23:11