62
\$\begingroup\$

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."

\$\endgroup\$
  • 6
    \$\begingroup\$ Here is an explanation of "rotate then translate" (spinning) vs "translate then rotate" (orbiting) \$\endgroup\$ – bobobobo May 13 '13 at 15:14
  • \$\begingroup\$ the link is good, but with a small error. its should be rolling effect and not spinning, becaiuse the sphere tends to move away from its position ( remaining on the axis ) by translating . \$\endgroup\$ – infoclogged Apr 16 '18 at 19:49
77
\$\begingroup\$

Usually it is scale, then rotation and lastly translation. With matrix denotation (i.e. T for translation matrix, R for the rotation matrix and S for the scaling matrix) that would be:

T * R * S

However, if you want to rotate an object around a certain point, then it is scale, point translation, rotation and lastly 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.

\$\endgroup\$
  • 11
    \$\begingroup\$ 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. \$\endgroup\$ – Engineer Sep 1 '11 at 17:26
  • \$\begingroup\$ 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... \$\endgroup\$ – Narf the Mouse Sep 1 '11 at 17:55
  • \$\begingroup\$ Just let it be noted, I Hate mis-placed negative signs. Anyway, thanks, and you can consider this question done with. :) \$\endgroup\$ – Narf the Mouse Sep 1 '11 at 17:58
  • \$\begingroup\$ No problem, always glad to help. \$\endgroup\$ – Raphael R. Sep 1 '11 at 18:06
  • 2
    \$\begingroup\$ @Matthias As far as I know, that depends how you then multiply by the vector that you want to transform. If you multiply M*v then yes, answer has reversed order. \$\endgroup\$ – bialpio May 16 '16 at 3:41
-4
\$\begingroup\$

translation rotation and scaling is the sequence to perform operation

\$\endgroup\$
-5
\$\begingroup\$

I do believe it is Translation Rotation and Dialation

\$\endgroup\$
  • 2
    \$\begingroup\$ This doesn't provide any more explanation than the existing answers. \$\endgroup\$ – DMGregory Jan 24 '18 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.