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.

Assume DirectX as the platform, if that is important. (Pretty sure it isn't)

Assuming I have a proper scale, rotation and translation matrix, in what order do I multiply them to result in a proper world matrix and why?

By "proper", I mean "I could throw them straight into DirectX and get the most commonly-used 3D frame."

share|improve this question
    
Here is an explanation of "rotate then translate" (spinning) vs "translate then rotate" (orbiting) –  bobobobo May 13 '13 at 15:14

1 Answer 1

up vote 30 down vote accepted

Usually it is scale * rotation * translation. However, if you want to rotate an object around a certain point, then it is scale * point_translation * rotation * object_translation.

Why: First you want to scale the object so that the translations work properly. Then you rotate the axes so the translation takes place on the adjusted axes. Finally you translate the object to it's position.

In OpenGL you can use gluLookAt to get a full camera transformation in one call. There is likely a similar call for DirectX.

share|improve this answer
6  
And remember, if you want to transform around the centre, then you first have to translate to offset the centre to be on the origin, then do as user392858 has stated, then translate it back again away from the origin by the same amount. Generally though, this is only necessary in 2D, where you have some sprite that has it's top left at the origin. –  Nick Wiggill Sep 1 '11 at 17:26
    
Great. :) Now I just have to figure out why my model is now inverting in a horizontal view and needs the dot product on the directional light reversed in a vertical view. It didn't used to do that, then I fixed some math... –  Narf the Mouse Sep 1 '11 at 17:55
    
Just let it be noted, I Hate mis-placed negative signs. Anyway, thanks, and you can consider this question done with. :) –  Narf the Mouse Sep 1 '11 at 17:58
    
No problem, always glad to help. –  Raphael R. Sep 1 '11 at 18:06
    
Just wondering, it's fine to swap around scale and rotation, right? Since rotation is independent of the scale of the object.. just making sure.. but anyway it seems it's better to do the scaling first, as it stays consistent with the second version. –  Thomas Oct 22 '13 at 6:14

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.