# OpenGL rotation of merry-go-round

• 02-07-2011
cowcow8866
OpenGL rotation of merry-go-round
I have rendered a merry-go-round in the following code. However, when I set rotation, it just gives me rotation of the whole thing around the y-axis but not a self-rotation. My question is how can I change the following code to give self-rotation (either clockwise or counter-clockwise) but not rotation of the whole thing around the y-axis.
The code that gives rotation is in the third paragraph in the line glRotatef(angle,0.0f, 1.0f, 0.0f); The idle function is just let the angle +1 degree. If the angle exceeds 360 degrees, then minus 360 degrees.
Than You.
Code:

```        glPushMatrix();                glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(0.0f, -100.0f, 70.0f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 5.0f,5.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(0.0f, -85.0f, 70.0f);         glutSolidSphere(5.0f, 20, 20);         glPopMatrix();         double xx =0.003f;         glPushMatrix();         glRotatef(angle,0.0f, 1.0f, 0.0f);         for(double i=-85.0; i>-88.0; i-=0.1f){                 glPushMatrix();         glColor3f(0.25f+xx, 0.206f+xx, 0.747f+xx);         glTranslatef(0.0f, i, 70.0f);                         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluDisk(quadric, 0, 50.0f, 60, 10);         glPopMatrix();         xx+=0.005f;         }                 //right long         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(40.0f, -85.0f, 70.0f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);                 gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //right short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(10.0f, -85.0f, 70.0f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(40.0f, -65.0f, 70.0f);         glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);         glRotatef(18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();                                 //left long         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(-40.0f, -85.0f, 70.0f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //left short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(-10.0f, -85.0f, 70.0f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(-10.0f, -75.0f, 70.0f);         glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);         glRotatef(-18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();         //inner left right         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(-20.0f, -85.0f, 35.4f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //inner left short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(-5.0f, -85.0f, 61.3f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(-5.0f, -75.0f, 61.30f);         glRotatef(210.0f, 0.0f, 1.0f, 0.0f);         glRotatef(-18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();         //inner right long         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(20.0f, -85.0f, 35.4f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //inner right short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(5.0f, -85.0f, 61.3f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(5.0f, -75.0f, 61.30f);         glRotatef(150.0f, 0.0f, 1.0f, 0.0f);         glRotatef(-18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();         //outer left long         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(-20.0f, -85.0f, 105.4f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //outer left short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(-5.0f, -85.0f, 78.7f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(-5.0f, -75.0f, 78.7f);         glRotatef(-30.0f, 0.0f, 1.0f, 0.0f);         glRotatef(-18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();         //outer right long         glPushMatrix();         glColor3f(0.05f, 0.09f, 0.77f);         glTranslatef(20.0f, -85.0f, 105.4f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 20, 20, 20);         glPopMatrix();         //outer right short         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.77f);         glTranslatef(5.0f, -85.0f, 78.7f);         glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 10, 20, 20);         glPopMatrix();         glPushMatrix();         glColor3f(0.95f, 0.09f, 0.07f);         glTranslatef(5.0f, -75.0f, 78.7f);         glRotatef(30.0f, 0.0f, 1.0f, 0.0f);         glRotatef(-18.43f, 1.0f, 0.0f, 0.0f);         gluCylinder(quadric, 1.0f,1.0f, 31.62f, 20, 20);         glPopMatrix();         glPopMatrix();         glPopMatrix();```
• 02-07-2011
tabstop
I'm not sure what you mean by "self-rotation". Do you want some of the individual cylinders to rotate too? Then you'll have to make those rotation angles variable as well, just as you have the main rotation use the variable "angle".
• 02-07-2011
cowcow8866
Quote:

Originally Posted by tabstop
I'm not sure what you mean by "self-rotation". Do you want some of the individual cylinders to rotate too? Then you'll have to make those rotation angles variable as well, just as you have the main rotation use the variable "angle".

Self rotation means the whole thing does not move(no relative movement to the ground) and only the cylinders and the circular disk rotates,the desired rotation just like the real merry go round in the park.
• 02-07-2011
tabstop
Quote:

Originally Posted by cowcow8866
Self rotation means the whole thing does not move(no relative movement to the ground) and only the cylinders and the circular disk rotates,the desired rotation just like the real merry go round in the park.

So draw the stuff that doesn't move before you do the rotation.
• 02-08-2011
cowcow8866
Sorry, I know I did not express clearly.

In simple, I need the merry-go-round (disk and cylidners) to rotate around the center of the disk rather than the disk and cylinders rotate around the y-axis. However I do not know which parts should be modified in order to do this effect.
• 02-08-2011
tabstop
You'll need to translate the center of the disk to the origin before you rotate around the y-axis then. (You're only allowed to rotate around axes that go through the origin.)
• 02-08-2011
MWAAAHAAA
First rotate, then translate.
• 02-09-2011
JohnLeeroy
Okay, lets use the solar system as an example.

You have the sun which for our example rotates on its local Y axis.

glPush
rotate on Y
Draw Sun
glPop

Now we have planets that revolve around the sun.
glPush
Translate away from sun
Rotate on Y
Draw
glPop