74

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

Tetrad
  • 30,124
  • 12
  • 94
  • 143
Narf the Mouse
  • 935
  • 2
  • 8
  • 8

3 Answers3

94

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 its position.

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

liggiorgio
  • 4,636
  • 6
  • 25
  • 37
Raphael R.
  • 1,826
  • 14
  • 8
  • 13
    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. – Engineer Sep 01 '11 at 17:26
  • Found the notation confusing. Since all these elemental transforms are matrix operations, they have to be applied in right to left order: T * R * S – Matthias Jan 11 '16 at 09:07
  • 3
    @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. – bialpio May 16 '16 at 03:41
  • This answer is not always correct, as bialpo points out. In my control system, I've ended up with S * R * T giving the correct results. Because I'm using Column major in both engine & shader, I use M * v. It can get pretty complicated to line everything up through your engine and shaders. – Gavin Williams Nov 09 '22 at 10:13
  • So, in a context, it is T * R * S * vector ? or vector * T * R * S ? – Sandburg Sep 15 '23 at 08:22
-4

translation rotation and scaling is the sequence to perform operation

nil
  • 1
-6

I do believe it is Translation Rotation and Dialation

Jimmy
  • 1