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

Sprite animation interactive may be non rectangular, Sprite animation inter...

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

Physics - based modeling, Draw the five regular polyhedras using physics-ba...

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

Points and lines - graphic primitives, Points and Lines - Graphic primitive...

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

Rigid body or non-rigid body transformations, Rigid body or Non-Rigid body ...

Rigid body or Non-Rigid body Transformations 2D transformations can be classified as rigid body or non-rigid body transformations. Rigid body transformations keep the shape and

Transformation for 3-d shearing, Transformation for 3-D Shearing 2-dim...

Transformation for 3-D Shearing 2-dimensional xy-shearing transformation, as explained in equation, can also be simply extended to 3-dimensional case. All coordinates are tran

Write a c-code for a user to draw a polygon object, Write a C-code for an i...

Write a C-code for an interactive program which allows a user to draw a polygon object in a window and then gives various choices of geometric transformations on the polygon.  Once

Dv encoder type 1, DV Encoder Type 1 : The video and audio streams are tog...

DV Encoder Type 1 : The video and audio streams are together interfaces by standard DV bit stream. Such format is fully supported through DirectShow which accepts this interleaved

Categories of reflection - ray tracing methods , Categories of Reflection -...

Categories of Reflection - Ray Tracing Methods In order to achieve realism, such phenomenon of reflection, which occurs because of interaction of light and surface, is require

Utility purpose of display processor in the graphic system, Explain the uti...

Explain the utility and purpose of display processor in the graphic system.  The purpose of the display processor is to free the CPU from the graphics chores. A major task of the d

Computer arthcther, How many 128 x 8 RAM chips are needed to provide a memo...

How many 128 x 8 RAM chips are needed to provide a memory capacity of 4096 16 bits?

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