Sign in to follow this  
PhiberOptic

glTranslate / glScale/glRotate

Recommended Posts

Hi! I have a model I want to scale/rotate (around itself) and of course, translate. I use the glPushMatrix() and glPopMatrix() around the code to get a new matrix like: glPushMatrix() glLoadIdentity() glTranslate(...) glScale(...) glRotate(...) glBegin(...) ... ... ... glEnd() glPopMatrix() I get different result if I alter the way in which translate/scale/rotate are called. What is the "correct" order to call them in my case?

Share this post


Link to post
Share on other sites
Matrix multiplications, which glTranslate/glRotate/glWhatever basically are, are not commutative, meaning that order of multiplication does matter. If A and B are matrices, then A*B != B*A.

Which order is correct depends entirely on what result you want. If you want the result as obtained by translating before rotating, then that is, obviously, the ocrrect order. There is no universal correct way of doing it, but there is a way of doing it that gives YOU the desired result for YOUR particular case.

Just remember that scaling and rotating always occur raltive the origin. Meaning, if you translate the object, it is no longer at the origin, and rotation and scaling will not do the "intuitive" thing. So what you're probably after is to scale first, then rotate, and last translate. That is, call them in the following order.

glTranslate(...);
glRotate(...);
glScale(...);

Hope i got that right [rolleyes].

Share this post


Link to post
Share on other sites
Of course it makes a difference where the scaling is put; it affects translation. It'll affect rotation, too, if it's a non-uniform scaling.

Share this post


Link to post
Share on other sites
Yes, it matters very much where you scale, just as much where you rotate and translate. If you scale a rotated coordinates system, scaling will occur along the world axes, which may not be the same as the local axes. Just like translation occurs along the world axes, which may, again, not be the same as the local axes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this