For theoretical understanding you'd have to dig a little deeper in how matrix transformations work in 3D space and how they affect the 3D coordinate basis. The simple answer is the following:
Matrix multiplication is not commutative. Changing the order of multiplication changes the result and the assumption that multiplications are happening at the same time means they should yield the same result is not correct.
More illustrative answer:
When you want to apply a rotation to your object, the end result you are expecting is for it to change the direction "it is looking at". This works if you use a rotation transform such as $$R=\begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix}.$$ This transformation will rotate the object by \$θ\$ degrees around the \$z\$ axis and this is what's important here. Which \$z\$ axis are we talking about exactly? In this specific case we're talking about the axis of the rotated object's coordinate basis i.e. the normal vector \$\vec{z} = (0,0,1)\$.
Translating the object also moves it based on its coordinate basis. The same for a combination of those transformations. But why does changing the order change the result? Because matrix multiplication is not commutative as mentioned in the beginning. Changing the order of multiplication changes the result.
Let's assume you are rotating a sphere as in your example.
If you do Rotate->Translate
:
- The object is rotated around the \$\vec{z}\$ basis vector. The rotation "pivot" of the sphere in this case is its center i.e. the point \$(0,0,0)\$ which means it rotates like the earth around its own axis.
- Translation moves the sphere to a designated position in 3D space. Let's say at \$(3,2,0)\$
If you do Translate->Rotate
:
- The sphere moves to a designated position in 3D space. Its center point is now \$(3,2,0)\$
- The object is rotated around the \$\vec{z}=(0,0,1)\$ basis vector of that same coordinate basis. The pivot of the rotation remains the same as previously at \$(0,0,0)\$ but the sphere center is now at \$(3,2,0)\$. It now goes all the way around like the earth rotates around the sun.
It is important to understand that a transformation doesn't change the "pivot" point. Everything is expressed based on the object's coordinate basis. If you want to change that you have to actually do a change of basis operation. This is what the localToWorld
matrix operations actually do.