Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 3 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
1  
@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
add comment

Your Answer

 
discard

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.