Write a code to continuously rotate square about pivot point, Computer Graphics

Write a code to continuously rotate a square about a pivot point. 

  #include  

static GLfloat rotat=0.0;  

void init(void);

void display(void);

void reshape(int w, int h);

void rotate(void);  

int main()

{      

        glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);

        glutInitWindowSize(500,500);

        glutInitWindowPosition(100,100);

        glutCreateWindow("Moving squares");

        init();

        glutDisplayFunc(display);

        glutReshapeFunc(reshape);

        glutIdleFunc(rotate);

        glutMainLoop();

}  

void init(void){ 

glClearColour(0.0,0.0,0.0,0.0);

}  

void display(void)

{  glClear(GL_COLOUR_BUFFER_BIT);

   glPushMatrix(); //Push the transformation matrix to stack 

   glTranslatef(-50.0f,-50.0f,0.0); 

   //Translate the pivot point to origin

   glRotatef(rotat,0.0,0.0,1.0); // Rotate about origin

   glTranslatef(50.0f,50.0f,0.0); 

   //Translate pivot point back to its position

   glColour3f(0.0,0.0,1.0); //Set colour of square

   glRectf(-50.0,-50.0,50.0,50.0); //Draw square 

   glPopMatrix(); //Pop the matrix from stack

   glutSwapBuffers(); // Swap buffers

}  

void reshape(int w, int h)

{        glViewport(0,0,(GLsizei)w,(GLsizei)h);

        glMatrixMode(GL_PROJECTION);

        glLoadIdentity();

        glOrtho(-250.0,250.0,-250.0,250.0,-1.0,1.0);

        glMatrixMode(GL_MODELVIEW);

        glLoadIdentity();

}  

void rotate(void)

{     rotat+=0.1; //Continuously increse the rotation angle by 0.1

                if(rotat>360.0)

                        rotat-=360.0;

        glutPostRedisplay(); //send the current window for

redisplay

}

 

Posted Date: 4/26/2013 2:56:01 AM | Location : United States







Related Discussions:- Write a code to continuously rotate square about pivot point, Assignment Help, Ask Question on Write a code to continuously rotate square about pivot point, Get Answer, Expert's Help, Write a code to continuously rotate square about pivot point Discussions

Write discussion on Write a code to continuously rotate square about pivot point
Your posts are moderated
Related Questions
Objectives of Curves and surfaces - modeling and rendering After going through the section, you should be capable to: Implement the methods utilized to represent a pol

Explain about the Computer animation Computer animation is the art of creating moving images by computer software and hardware. For 3D animation, objects are designed on a

What is the major disadvantages of storing information structures in display memory? A major disadvantage of storing information structures in display memory is that when color an

Question 1) Encode the following string using HUFFMAN ENCODING:                            DO YOU LIKE TINKY WINKY OR EMPTY DUMPTY?     Empty spaces are considered.

Illustration: Find the normalization transformation N that uses the rectangle W (1, 1), X (5, 3), Y (4, 5) and Z (0, 3) as a window and also the normalized device screen like the

Three-Dimensional Viewing Three dimensional objects are created using modelling coordinate system. The modelled objects are then placed in locations specified in the scene with

explain in detail the application of computer graphics in education and training?

Determine the perspective transformation matrix upon to z = 5 plane, when the center of projection is at origin. Solution. As z = 5 is parallel to z = 0 plane, the normal is s

Sketch Line Segment That Joining By Using Bresenham Line Algorithm Example: Sketch line segment that joining (20, 10) and (25, 14) by using Bresenham line generation algorit

Define clipping and covering (exterior clipping)? Clipping is the process of cutting a graphics display to neatly fit a predefined graphics region or the view port.  This is