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
Multimedia Business: Even fundamental office applications as a MS word processing package or a MS Excel spreadsheet tool turns into a powerful tool along with the aid of mult

Cases for Subdivisions of Polygon No additional subdivisions of a particular area are desired, if one of the subsequent conditions is true as: Case 1: All the polygons ar

Draw the five regular polyhedras using physics-based modeling method. Implement a fractal algorithm with possible personal extensions. Also, specify the extensions.

explainapplication of coherence in visible surface detection method

Sprite animation interactive, may be non rectangular (Computer games) In its simplest form it is a 2-D graphic object which moves across the display. Sprites frequently can hav


QUESTION a) Explain with the help of a diagram, how a thermal inkjet printer works. b) Briefly explain the term density range. c) Distinguish between scaling and resampli

QUESTION a) Once a print job is accepted by the print service provider, it will be assigned a job number and this information will become part of a printed job ticket, which wi

Multimedia Entertainment: The field of entertainment uses multimedia extensively. One of the earliest and the most popular applications of multimedia are for games. Multimedi

Translation - 2-d and 3-d Transformations It is the process of changing the position of an object. Suppose an object point P(x,y)=xI+yJ be moved to P'(x',y') by the specified