# Thread: OpenGL rotation of merry-go-round

1. ## 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);
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);
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);

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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
glPopMatrix();
glPopMatrix();
glPopMatrix();```

2. 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".

3. 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.

4. 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.

5. 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.

6. 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.)

7. First rotate, then translate.

8. 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