I've read a dozen articles online about the correct order of rotation, translation and scale matrix multiplication in OpenGL. However, now that I started implementing it myself, I came to the point where I'm really confused.
Let's assume that in my code I'm calculating the transformation matrix, and I'm passing it to the shader as a one result matrix:
shader.SetUniform("u_Matrix", scale * rotation * translation);
And in the vertex shader I'm multiplying the vertices by this matrix:
gl_Position = u_Matrix * vec4(a_Position, 0.0, 1.0);
Now, in this order (scale * rotation * translation) I'm getting exactly what I want: I rotate the object, then I move it to the specific point, and then I scale it. Can someone explain me why this is the correct order?
I always thought that all the transformations were applied "from the vector side".
For example, if we "expand" the multiplication:
gl_Position = scale * rotation * translation * vec4(a_Position, 0.0, 1.0);
then first the translation should be applied, then the rotation and the scale after that. Everything would seem ok to me, if it wasn't for the order of translation and rotation. If we don't want to rotate around a certain point, we should first rotate and then translate, which isn't the case here.
Why does this transformation work as intended?