Thread: OpenGL rotation of merry-go-round

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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, 01:52 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12: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, 03: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