Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COMPUTER GRAPHICS OPENGL (GLUT) VISUAL STUDIOS CODE TEMPLATE: //Your work: Add your name and program description below //Date: //Your work: Add necessary headers below //Global

image text in transcribed

COMPUTER GRAPHICS OPENGL (GLUT) VISUAL STUDIOS

CODE TEMPLATE:

//Your work: Add your name and program description below //Date: //Your work: Add necessary headers below //Global variable float degree_x = 0; //degrees to be rotated around x axis float degree_y = 0; //degrees to be rotated around y axis float degree_z = 0; //degrees to be rotated around z axis 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 cube..... 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 your callback functions below }
Pcal i ng code and complcte the program so that 1. [10 points] the window size is 500 x 500 pixel, and name the window (title) after your name. The left-top corner of the window is located at the location of (150, 150) 2. [25 points] Add a solid cube to the 3D world. User should be able to use keys 'x', y' and 'z' to rotate the object around x-, y-, and z- axis, respectively. User hits "Esc" key to terminate the program. Set the cube size appropriately (not too big and also not too small). 3. [25 points] Add a mouse callback function so that every left-mouse-key click rotates the object around x-axis 10 degree counter-clockwise and every right-mouse-key click rotates the object 10 degree around x-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. 4. [20 points] Setup a timer in the program so that the timer rotates the 3D object around y-axis 10 degrees per second. Turn in: One manila envelope with the following two items: 1) The hardcopy of your source code The soft copy of the source code (stored in a USB memory stick) 2) Pcal i ng code and complcte the program so that 1. [10 points] the window size is 500 x 500 pixel, and name the window (title) after your name. The left-top corner of the window is located at the location of (150, 150) 2. [25 points] Add a solid cube to the 3D world. User should be able to use keys 'x', y' and 'z' to rotate the object around x-, y-, and z- axis, respectively. User hits "Esc" key to terminate the program. Set the cube size appropriately (not too big and also not too small). 3. [25 points] Add a mouse callback function so that every left-mouse-key click rotates the object around x-axis 10 degree counter-clockwise and every right-mouse-key click rotates the object 10 degree around x-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. 4. [20 points] Setup a timer in the program so that the timer rotates the 3D object around y-axis 10 degrees per second. Turn in: One manila envelope with the following two items: 1) The hardcopy of your source code The soft copy of the source code (stored in a USB memory stick) 2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions