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
Graphic Interchange Format (GIF): The Graphic Interchange Format is an efficient implies to transmit images across data networks. In the early 1990 year the original designers of

3Dstudio - Softwares for computer animation 3DStudio is a 3-D computer graphics programmed. 3DStudio runs on personal computers. This is relatively simple to use. Several schoo

Q. Why are all resolutions in ratio of 4:3? The bad news is that almost every monitor can only display upto a maximum of 262,144 colours (i.e.  18 bits/pixel Colour Depth). The

Advantages and Deficiencies of Gourand Shading Advantages of Gourand Shading: this eliminates the intensity discontinuities related with the constant shading model. Defi

AVI CODEC Formats: Various AVI file formats other than the DV Types 1 and 2 formats are there discussed earlier. All such the other formats involve the utilization of Compressor o

Positive Accelerations - Computer Animation So as to incorporate increasing speed in an animation the time spacing among the frames should increase, hence greater change in th

Perspective Distortion - Polygon Rendering and Ray Tracing Methods Anomalies are introduced since interpolation is performed after perspective transformation in the 3-D scree

what is zooming and panning in computer graph please explan??

Discuss various Techniques for Character Generation

Describe interactive model of computer graphics and application areas of interactive computer graphics.