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

Touch panels - input and output devices, Touch Panels - Input and output de...

Touch Panels - Input and output devices It allows displayed screen or object positions to be selected along with the touch of the finger and is also termed as Touch Sensitive

Modal create, morgen wants to sign up for an account on doggobook, the worl...

morgen wants to sign up for an account on doggobook, the world''s thrid - best social network for dog enthusiasts. she enters her email address and a password into the sign-up form

What colour depths are basically used, Q. What Colour depths are basically ...

Q. What Colour depths are basically used? Basically the number of colours are an exponential power of 2 as for Colour Depth n, colours can be showed. The most popular colour mo

Jpeg graphics, JPEG Graphics: Another graphic file format usually utilized...

JPEG Graphics: Another graphic file format usually utilized on the Web to minimize graphics file sizes is the Joint Photographic Experts Group that is JPEG compression scheme. Not

Single point perspective transformation, Single Point Perspective Transform...

Single Point Perspective Transformation - Viewing Transformations In order to derive the particular point perspective transformations beside the x and y-axes, we construct fi

Relationships between scaling and wavelet function spaces, QUESTION (a)...

QUESTION (a) Median filters do not cater for a dynamic range of pixels in a given area, S. Thus to ensure that no loss of image details occur in S, adaptive median filters coul

Rotation about the origin - 2-d and 3-d transformations, Rotation about the...

Rotation about the origin - 2-d and 3-d transformations Specified a 2-D point P(x,y), which we need to rotate, along with respect to the origin O. The vector OP has a length '

Objectives-multimedia, Objectives-Multimedia After going through this s...

Objectives-Multimedia After going through this section, you should be capable to: explain hypertext and hypermedia ideas, illustrate how multimedia applications are

Simple graphical user interface, The RIA should consist of: i) A simple ...

The RIA should consist of: i) A simple Graphical User Interface (GUI) constructed from a simple navigation system (comprising of around 5 key frames) making use of the Flash tim

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