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

Types of formats of audio file formats, Types of Formats It is signific...

Types of Formats It is significant to distinguish among a file format and a codec. Although most audio file formats support merely one audio codec, a file format may assist mul

What is orthographic parallel projection, What is orthographic parallel pro...

What is orthographic parallel projection?  When the direction of the projection is normal (perpendicular) to the view plane then the projection is called as orthographic paral

Storing information structures in display memory, What is the major disadva...

What is the major disadvantages of storing information structures in display memory? A major disadvantage of storing information structures in display memory is that when color an

Normalization transformation, Find the normalization transformation N, whic...

Find the normalization transformation N, which uses the rectangle W(1, 1); X(5, 3); Y(4, 5) and Z(0, 3) as a window and the normalized deice screen as viewpoint.

Illustration of a clipping window - raster graphics, Illustration of a Clip...

Illustration of a Clipping window ABCD is placed as follows: A (100, 10), B (160, 10, C (160, 40), D (100, 40) By using Sutherland-Cohen clipping algorithm determine the vis

Prepare a cylinder, Question: (a) Write a short note on the dot syntax...

Question: (a) Write a short note on the dot syntax as used in actionScript. (b) A data type describes the kind of information a variable or ActionScript element can hold.

Matrix for orthographic projection, Matrix for Orthographic Projection ...

Matrix for Orthographic Projection Orthographic projections are projections into one of the coordinate planes x=0, y=0or z=0. The matrix for orthographic projection on the z=0

What is the standard video workflow, QUESTION 1. You are a consultant i...

QUESTION 1. You are a consultant in the field of video production and video editing. You haven been requested to participate in a debate over analog and digital video. Write

Polygon clipping algorithm, Write a polygon clipping algorithm to clip a po...

Write a polygon clipping algorithm to clip a polygon against rectangular clipping are. Read the vertices of polygon to be clipped. 2. Read the coordinates of the rectangular cl

Drawing program with object- oriented design, For this assignment, you will...

For this assignment, you will add to the drawing program new features that are similar to features that you already have. Apply object-oriented design concepts such as inheritance

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