• 14
• 12
• 9
• 10
• 9

# [help]Need a quick example on rotation

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

## Recommended Posts

hiya! I'm a tad confused about the rotations in opengl. I'm fine with Nehe's rotation tutorial. However, I need some extra help on rotations. Can anyone show me a quick example on how to rotate an object around its own axis, as well as a globally specified axis? Actually, I'm trying to animate several objects by themselves, then combine them into a scene and animate the whole scene. So I thought a simple example would really help me. Thanks!!

##### Share on other sites
And your not the only one confused by openGL rotations.
Most of the time you have to do these things on a trial&error basis.
a few hints, Open gl allways rotates around what it sees as origo.
because of this the order of any rotation and translation is important, if the object or orbiting the origo instead of rotating on it's own axis then switch the order of the rotation and translation.

to rotate around it's own axis it should be just rotate(axis) translate then rotate(orbit) again, but the gl rotations are not that forgiving.
either way, i find it easier to just do all that myself and not bother with glTranslate and glRotate that mutch for complex stuff

##### Share on other sites
thanks for the reply. But still, I wanna know how to use both glTranslate and glRotate. Got quite a bit of question about them. Like how come, if I rotate, then translate (rotate about origin, then move to position), it ends up rotating about the position of the camera.

Anyway, can some one just help me with the following code? What do I need to change/add/remove? Thanks!

void someDrawFunction(float px, float py, float pz){    static float r = 0.0;    glLoadIdentity(); // Do I put this here?    glTranslatef(px,py,pz);    glRotatef(r+=speed, rx,ry,rz);    glBegin();    ...    glEnd();}void displayFunction(){    /*    Need help here. The functions should draw 2 same object     that is rotating about its own axis. But say I want to     rotate BOTH object as well around a specific point, how do I do that?    */    glLoadIdentity();    // Do I need this?    someDrawFunction(px-1, py, pz-5);    someDrawFunction(px+1, py, pz-5);}

see, I need to create multiple self animating models, then combine them together in a larger composition that will rotate/move as well. But putting that aside, I need to hammer this basic concept in me head first. Just need a working example, and I can pretty much figure out what I'm doing wrong/missing. More help please? Thanks!