OpenGL rotation of merry-go-round

This is a discussion on OpenGL rotation of merry-go-round within the Game Programming forums, part of the General Programming Boards category; I have rendered a merry-go-round in the following code. However, when I set rotation, it just gives me rotation of ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    7

    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();
    Last edited by cowcow8866; 02-07-2011 at 11:22 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    7
    Quote Originally Posted by tabstop View Post
    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.
    Last edited by cowcow8866; 02-07-2011 at 12:35 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by cowcow8866 View Post
    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. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    7
    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. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    First rotate, then translate.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  8. #8
    Registered User
    Join Date
    Jan 2011
    Posts
    31
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Object Rotation
    By Lesshardtofind in forum Game Programming
    Replies: 5
    Last Post: 09-30-2010, 02:52 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21