• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

### #Actual_Slin_

Posted 18 February 2013 - 04:09 PM

glTranslatef(position.x, position.y, position.z);
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);

just do it the other way around:
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);
glTranslatef(position.x, position.y, position.z);

Edit: The idea is, that your objects vertices have positions relative to your objects center. Without transformation, this center will be the same as the worlds center. glTranslate and glRotate always transform relative to the worlds center. This means if you first translate, your object will be placed at a different position in the world, now if you rotate, that new position+your vertex positions will be rotate around the worlds center. If you rotate first, your object is rotated around the worlds center, which is also its own center and then it is moved to its final position. This explanation is probably not mathematically perfect, but should give a basic feeling for correct transformation orders. If you want to understand this in more detail, check out rotation and translation matrices and matrix multiplication, especially homogeneous matrices.

### #1_Slin_

Posted 18 February 2013 - 03:53 PM

glTranslatef(position.x, position.y, position.z);
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);

just do it the other way around:
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);
glTranslatef(position.x, position.y, position.z);

PARTNERS