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

Assignment Help:

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

}

 


Related Discussions:- Write a code to continuously rotate square about pivot point

Phong shading or normal vector interpolation shading, Phong shading OR Norm...

Phong shading OR Normal Vector Interpolation Shading In Gouraud shading we were doing direct interpolation of intensities although a more exact method for rendering a polygon

Use of interactive multimedia in education, Use of Interactive Multimedia i...

Use of Interactive Multimedia in Education Virtual reality, where 3-D experimental training can simulate real situations. Computer simulations of things too expensive,

What is 2-dimensional transformation, 2-DIMENSIONAL TRANSFORMATION Mode...

2-DIMENSIONAL TRANSFORMATION Modeling transformation is the mechanism to compose an image from modeling  primitives. The modeling primitives are defined in their own coordinate

Objects - polygon rendering and ray tracing methods, Objects - polygon rend...

Objects - polygon rendering and ray tracing methods Objects could be any state of material as solid, liquid. Gas and plasma. Though ray tracers can merely assist objects whic

Other curves - parabola and hyperbola, Other curves - parabola and hyperbol...

Other curves - parabola and hyperbola Conic sections such as parabola and hyperbola are used in many instances such as in motion planning along a trajectory or in modelling the

Algorithm scan-line, Algorithm (scan-line): For each scan line perform ...

Algorithm (scan-line): For each scan line perform from step (1) to (3). 1) For all pixels on a scan-line, arrange depth [x]=1.0 i.e. max value and Intensity [x] = background

Cad-cam systems management, Assignment Task Your task is to review and...

Assignment Task Your task is to review and compare the current cad/cam software systems available with the intention to make a recommendation in the form of a written report f

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd