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
Other File Formats BMP/DIB/RLE File Formats These are termed as device independent bitmap files. They exist in two various type formats: a) OS2 format and b) Windows

Suppose here, one allows 256 depth value levels to be employed. Approximately how much memory would a 512x512 pixel display necessitate to store z-buffer? Solution : A system w



explain cohen sutherland line clipping algorithm

1. For the polygon shown in Figure on the next page, how many times will the vertex V 1 appear in the set of intersection points for the scan line passing through that point?  How

structure of display file

Points and Lines - Graphic primitives In the previous section, we have seen to draw primitive objects; one has to firstly scan convert the objects. This concern to the operat

Visible-Surface Detection For the generation of realistic graphics display you know that hidden surfaces and hidden lines should be identified for removing. For this reason we

Differentiate among interpolation spline and approximation spline?  When the spline curve passes by all the control points then it is known as interpolate. When the curve is