Question: **COMPUTER GRAPHICS** Please fill in the missing code and complete the program so that 1. [10 points] the window size is 450 x 450 pixel,
**COMPUTER GRAPHICS**
Please fill in the missing code and complete the program so that
1.[10 points] the window size is 450 x 450 pixel, and the window name is your name. The left corner of the window is located at the location of (50, 50).
2.[25 points] it has one 3D object in the 3D world, and user can use keys x, y, and z to rotate the object around x-, y-, and z- axis, respectively. When user hits Esc key, the program exterminates.
3.[25 points] Add a mouse callback function so that every left-mouse-key click rotates the object around z-axis 5 degree counter-clockwise and every right-mouse-key click rotates the object 5 degree around z-axis clockwise.
4.[20 points] Add a special key callback function, so that hitting left-arrow key rotates the object along x-axis counter-clockwise, and hitting right-arrow key rotates the object along x-axis clockwise.
5. [20 points] Install a timer in the program so that the timer rotates the 3D object around y-axis 1 degrees per second.
**FILL IN CODE TEMPLATE BELOW**
//Your work: Add necessary headers below //Global variable float degree_x = 0; //degrees to be rotated around x axis float degree_y = 0; float degree_z = 0; void setLight(void) //don't change this function { GLfloat ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f }; GLfloat position[]= { 10.0f, 5.0f, 10.0f, 0.0f }; GLfloat lmodel_ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; GLfloat local_view[] = { 0.0f}; glClearColor(0.25f, 0.25f, 0.56f, 0.0f); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); } void setMaterial() //don't change this function { float specular1[]={0.7f, 0.0f, 0.1f, 1.0f}; float diffuse1[] ={0.8f, 0.0f, 0.1f, 1.0f}; float ambient1[] ={0.2f, 0.2f, 0.2f, 1.0f}; float shininess1[]={100.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT, ambient1); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse1); glMaterialfv(GL_FRONT, GL_SPECULAR, specular1); glMaterialfv(GL_FRONT, GL_SHININESS, shininess1); } //Your work: create a regular key callback function //Your work: create a special key callback function //Your work: careat a mouse callback function //Your work: create a timer function //Don't change this function void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0, (GLfloat) w / (GLfloat) h, 1.0, 100.0); //50 , 5 gluLookAt(0.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(degree_x, 1.0, 0.0, 0.0); glRotatef(degree_y, 0.0, 1.0, 0.0); glRotatef(degree_z, 0.0, 0.0, 1.0); //Your work: draw a 3D object here, like teapot..... glPopMatrix(); glutSwapBuffers(); } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB| GLUT_DEPTH); //Your work: create a window with size of 450 x 450 pixels. //Also set the name of the window to be "your name'. The window locats at (50,50). //Don't change this two sentences setLight(); setMaterial(); //Your work: register the keyboard callback function below }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
