Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


GLM rotation isn't working right?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 3DModelerMan   Members   -  Reputation: 1165

Like
0Likes
Like

Posted 04 February 2014 - 11:52 AM

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?

 



Sponsor:

#2 uglybdavis   Members   -  Reputation: 1050

Like
1Likes
Like

Posted 04 February 2014 - 12:53 PM

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, 04 February 2014 - 12:57 PM.


#3 Buckeye   GDNet+   -  Reputation: 10634

Like
1Likes
Like

Posted 04 February 2014 - 01:18 PM

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.


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#4 3DModelerMan   Members   -  Reputation: 1165

Like
0Likes
Like

Posted 04 February 2014 - 02:20 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS