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

Curve segment - properties of bezier curves, Curve segment - properties of ...

Curve segment - properties of bezier curves Note : 1) The joining point on the curve along w.r.t. the parameter based upon second derivates of Q(t) is the acceleration. Wh

Two modes of operation of tablets - cad and cam, Two Modes of Operation of ...

Two Modes of Operation of Tablets Tablets typically sustain two modes of operation as: 1)  Digitizer Mode: creates a one-for-one connection between screen and tablet.

Find out average unit normal vector at each polygon vertex, To find out ave...

To find out average unit normal vector at each polygon vertex At each polygon vertex as demonstrated by point V in the figure above, the normal vector is acquired by averaging

Principal vanishing point write respect to y-axis, Principal vanishing poin...

Principal vanishing point write respect to y-axis By the 2nd Row of the matrix as in Equation, the principal vanishing point w.r.t y-axis will as: (0, 5/√2, 0, 1/√2) in hom

Audio and video, AUDIO AND VIDEO: Audio and video are working as eye and e...

AUDIO AND VIDEO: Audio and video are working as eye and ear of multimedia. Both of them are heavily contributing to any type of multimedia application. Here we discuss something r

Ray tracing - polygon rendering and ray tracing methods, Ray Tracing - Poly...

Ray Tracing - Polygon Rendering and Ray Tracing Methods Basically Ray tracing is an exercise that is performed to attain the realism in a scene. In easy way Ray Tracing is a w

Homogeneous coordinate systems - 2-d and 3-d transformations, Homogeneous C...

Homogeneous Coordinate Systems - 2-d and 3-d transformations Suppose P(x,y) be any point in 2-D Euclidean (Cartesian) system. In HC System, we add a third coordinate to a poin

Hypermedia, Hypermedia: it is a superset of hypertext. Hypermedia document...

Hypermedia: it is a superset of hypertext. Hypermedia documents comprise links not only to the other pieces of text, although also to other forms of media: sounds and images and m

Bezier curves - modeling and rendering, Bezier Curves - Modeling and Render...

Bezier Curves - Modeling and Rendering Bezier curves are utilized in computer graphics to turn out curves which display reasonably smooth at all scales. Such spline approximat

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