T.R.S.(Translation, Rotation, Scale) to transformation matrix
14:21 12 Sep 2026

I implemented translation rotation and scaling in my 3D rendering software. A transformation matrix of an enttity is computed using the TRS. I get wrong results at the moment.

I use Y up system:
Y up system

Here what i get when rotating around the y axis(A)

https://youtu.be/QRdCBzVa738

Here what i expect:

https://youtu.be/G5xlBh_PYj4

The corresponding code:


inline void updateMatrix() 
{
    m_matrix = Math::Mat4();
    m_matrix = glm::scale(m_matrix, m_scale);
    m_matrix = glm::rotate(m_matrix, m_rotation[0].getValue(), Math::Vec3(1.0f, 0.0f, 0.0f));
    m_matrix = glm::rotate(m_matrix, m_rotation[1].getValue(), Math::Vec3(0.0f, 1.0f, 0.0f));
    m_matrix = glm::rotate(m_matrix, m_rotation[2].getValue(), Math::Vec3(0.0f, 0.0f, 1.0f));

    m_matrix[3] = Math::Vec4(m_position.x, m_position.y, m_position.z, 1.0f);
}

So this is wrong. Google assistant suggested me to do the following(B):

   inline void updateMatrix() 
{
    glm::mat4 T = glm::translate(glm::mat4(1.0f), m_position);

    glm::mat4 R = glm::eulerAngleYXZ(m_rotation[1].toRadian().getValue(), m_rotation[0].toRadian().getValue(), m_rotation[2].toRadian().getValue());

    glm::mat4 S = glm::scale(glm::mat4(1.0f), m_scale);

    m_matrix = T * R * S;
}

With that i get the Y-rotation right and non uniform scaling rotates properly.

But rotating around the Z axis(blue) gives the same result than rotating around the Y axis(green):

https://youtu.be/peuTokj2Ako

So it is not over yet. What should I do?

math matrix rotation transformation