Monday, September 21, 2015

What is the correct order to multiply scale, rotation and translation matrices for a proper world matrix?


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



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...