Hello. I just tried to do rotation and i have problem. It rotates my object around all world, but i want that it rotates my object at its center. Im using glPushMatrix and glPopMatrix between object rendering and after glPushMatrix this: glRotatef(angle, 1, 0, 0); Here is little image about that:
(http://img88.imageshack.us/img88/3273/rotation.png)
Have the model centered on the origin, and rotate THEN translate it to the desired location.
Could you give me example with code? :-\
If I am thinking of this correctly, you are supposed to first glPushMatrix() in order to make a new matrix layer. Then, you do glTranslatef(x,y,z) in order to make the center of what you are creating. So say the center is at 0, 5, 5, you would put glTranslate(0,5,5), then you would do whatever rotation you want to put. Then lastly, you glPopMatrix() back to normal. Hopefully that works because I don't know for sure if that is what you do.
So:
glPushMatrix()
glTranslatef(x,y,z)
glRotate()
glPopMatrix()
Close, but not quite. For one thing, if you used that code and rendered the object directly afterwards, no translation or rotation would be used.
The code to use should be something like:
glPushMatrix();
glRotatef(/* rotational values */);
glTranslatef(/* translational values */);
// render the object!
myObject.render();
glPopMatrix();
Calling glPopMatrix() resets everything to when you last called glPushMatrix().