20
\$\begingroup\$

I am experiencing difficulties trying to figure out the correct multiplication order for a final transform matrix. I always get either strange movement or distorted geometry. My current model is explained below:

For a single node my multiplication order is:

L = S * R * T

where

L = local transformation matrix

S = local scale matrix

R = local rotation matrix

T = local translate matrix

For a node's world transformation:

W = P.W * L

where

W = world transformation matrix

P.W = parent world transformation matrix

L = the local transformation matrix calculated above

When rendering, for each node I calculate the matrix :

MV = Inv(C) * N.W

where

MV = the model view transformation matrix for a particular node

Inv(C) = the inverse camera transformation matrix

N.W = the node's world transformation matrix calculated above.

Finally, in the shader I have the fallowing transformation:

TVP = PRP * MV * VP

where

TVP = final transformed vertex position

PRP = perspective matrix

MV = the node's world transformation matrix calculated above

VP = untransformed vertex position.

With the current model, child nodes which have local rotation, rotate strangely when transforming the camera. Where did I go wrong with the multiplication order?

\$\endgroup\$
36
\$\begingroup\$

Any combination of the order S*R*T gives a valid transformation matrix. However, it is pretty common to first scale the object, then rotate it, then translate it:

L = T * R * S

If you do not do it in that order, then a non-uniform scaling will be affected by the previous rotation, making your object look skewed. And the rotation will be affected by the translation, making the final position of your object very different from what the value of the translation would make you expect.

\$\endgroup\$
  • \$\begingroup\$ Can you explain this a bit more? From what I am used to, the rotation can not be affected by a translation since it is a difference in orientation between two frames, independent of position. Instead, a translation can be affected by a rotation that happens before it, since it will translate on the newly defined axis of rotation. In L=TRS, the translation happens first, so it is not affected by the new vectors created by the rotation. \$\endgroup\$ – user-2147482637 Jun 15 '15 at 9:53
  • 4
    \$\begingroup\$ The confusion comes from the fact that you are talking about local transformations (where the frame remains linked to the object), whereas the transformations described here happen in world space (where there is only one fixed reference frame, the world). Conceptually, your way of seeing things is valid, and it is equivalent to applying transformations in reverse order. \$\endgroup\$ – sam hocevar Jun 15 '15 at 15:29

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.