# GLM rotation isn't working right?

This topic is 1450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using GLM to calculate my object's world matrices. I've got a whole bunch of objects with different rotations, and they are all attached to a parent object with only an identity transform matrix. I use this code to update the transformation matrices for my objects.

void CGameObject::updateTransform()
{
m_localTransform = glm::scale(glm::mat4x4(), m_scale);
m_localTransform *= glm::eulerAngleYXZ(m_rot.y, m_rot.x, m_rot.z);
m_localTransform *= glm::translate(glm::mat4x4(), m_pos);

CGameObject* parent = getParent();
if ( !parent )
{
m_worldTransform = m_localTransform;
}
else
{
m_worldTransform = parent->m_worldTransform*m_localTransform;
}
}


The weird thing that's happening though, is that when I try to rotate objects, they behave like I translated and then rotated. The objects rotate around the world's origin even though I have the transformations done in the right order. I thought for sure the order was scale, rotate, and translate so that you scale the object around its origin, rotate it around its origin, and then translate it to wherever. Is there something I'm doing wrong here?

##### Share on other sites

Scale it, Rotate it, Translate it. Correct.

OpenGL's (and glm) matrix multiplication works in reverse.

This is because the matrix is column major.

Scale, Translate, Rotate = rotate * translate * scale

Model, View, Projection = projection * model * view

Edited by uglybdavis

##### Share on other sites

In DirectX, in addition to reversing the order of OpenGL matrix mults, you'll want to reverse the order of the child transform mults. I.e., worldXform = childXform*parentsXform.

You might want to consider just using D3DXMATRIX, it's extensions, and D3DXMatrix... functions, and using SRT throughout.

##### Share on other sites

Thanks. It works perfectly now. Btw the reason I don't use XNAMath is because I GLM is more portable.