/*TODO: expand according to assignment 2 specs*/ void draw_object(int shape) { switch(shape) { case HOUSE: draw_house(); break; case CUBE: draw_cube_brute(); break; case CYLINDER: draw_cylinder(crt_rs, crt_vs); break; case SPHERE: draw_sphere(crt_rs, crt_vs); break; case TORUS: /*TODO EC: call your function here*/ ; break; case MESH: /*TODO EC: call your function here*/ ; break; default: break; } }
/*TODO: expand according to assignment 2 specs*/ void draw_object(int shape) { switch(shape){ case HOUSE: draw_house(); break; case CUBE: draw_cube_brute(); break; case CYLINDER: case SPHERE: case CONE: case TORUS: draw(crt_rs,crt_vs) ; break; default: break; } }
/*TODO: expand according to assignment 3 specs*/ void draw_object(int shape) { switch(shape){ case HOUSE: draw_house(); break; case CUBE: break; case CYLINDER: break; case SPHERE: break; case TORUS: ; break; case MESH: ; break; //case CONE: ; break; default: break; } }
/* * OpenGL (GLUT) calls this routine to display the scene */ void display(){ float cylinder_color_a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; float cylinder_color_b[3][3] = {{252.0/255.0, 141.0/255.0, 89/255.0}, {1, 1, 191/255.0}, {145/255.0, 207/255.0, 96/255.0}}; // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Undo previous transformations glLoadIdentity(); // Set view angle // MAKE the projection transformations after loading the identity matrix if (mode){ double Ex = -2*dim*Sin(th)*Cos(ph); double Ey = +2*dim *Sin(ph); double Ez = +2*dim*Cos(th)*Cos(ph); gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0); } // Orthogonal - set world orientation else{ glRotatef(ph,1,0,0); glRotatef(th,0,1,0); } // cylinder one glPushMatrix(); glRotatef(cylinder_rotation, 1, 0, 0); glRotatef(cylinder_rotation/0.5, 0, 1, 0); glScaled(0.9, 0.78, 0.4); draw_cylinder(0, 0, 0, 500, cylinder_color_a); glPopMatrix(); // cylinder two glPushMatrix(); glScaled(0.5, 0.5, 0.5); draw_cylinder(2, 2, 2, 500, cylinder_color_b); glPopMatrix(); // house one glPushMatrix(); draw_house(-2, -2, -2, cylinder_color_b); glPopMatrix(); // house two glPushMatrix(); draw_house(0.5, -.8, -2, cylinder_color_b); glPopMatrix(); // house 3 glPushMatrix(); draw_house(house_x, house_y, house_z, cylinder_color_a); glPopMatrix(); // White glColor3f(1,1,1); // Draw axes if (axes){ glBegin(GL_LINES); glVertex3d(0.0,0.0,0.0); glVertex3d(dim-0.5,0.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,dim-0.5,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,0.0,dim-0.5); glEnd(); // Label axes glRasterPos3d(dim-0.5,0.0,0.0); Print("X"); glRasterPos3d(0.0,dim-0.5,0.0); Print("Y"); glRasterPos3d(0.0,0.0,dim-0.5); Print("Z"); } // Five pixels from the lower left corner of the window glWindowPos2i(5,5); // Print the text string Print("Angle=%d,%d Dim=%.1f FOV=%d Projection=%s",th,ph,dim,fov,mode?"Perpective":"Orthogonal"); // Render the scene glFlush(); // Make the rendered scene visible glutSwapBuffers(); }
/* * OpenGL (GLUT) calls this routine to display the scene */ void display(){ const double len=4.5; // Length of axes float cylinder_color_a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; float cylinder_color_b[3][3] = {{252.0/255.0, 141.0/255.0, 89/255.0}, {1, 1, 191/255.0}, {145/255.0, 207/255.0, 96/255.0}}; // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Undo previous transformations glLoadIdentity(); // Set view angle glRotatef(ph,1,0,0); glRotatef(th,0,1,0); // cylinder one glPushMatrix(); glRotatef(cylinder_rotation, 1, 0, 0); glRotatef(cylinder_rotation/0.5, 0, 1, 0); glScaled(0.9, 0.78, 0.4); draw_cylinder(0, 0, 0, 500, cylinder_color_a); glPopMatrix(); // cylinder two glPushMatrix(); glScaled(0.5, 0.5, 0.5); draw_cylinder(2, 2, 2, 500, cylinder_color_b); glPopMatrix(); // house one glPushMatrix(); draw_house(-2, -2, -2, cylinder_color_b); glPopMatrix(); // house two glPushMatrix(); draw_house(0.5, -.8, -2, cylinder_color_b); glPopMatrix(); glPushMatrix(); draw_house(house_x, house_y, house_z, cylinder_color_a); glPopMatrix(); // White glColor3f(1,1,1); // Draw axes if (axes) { glBegin(GL_LINES); glVertex3d(0.0,0.0,0.0); glVertex3d(len,0.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,len,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,0.0,len); glEnd(); // Label axes glRasterPos3d(len,0.0,0.0); Print("X"); glRasterPos3d(0.0,len,0.0); Print("Y"); glRasterPos3d(0.0,0.0,len); Print("Z"); } // Five pixels from the lower left corner of the window glWindowPos2i(5,5); // Print the text string Print("Angle=%d,%d",th,ph); // Render the scene glFlush(); // Make the rendered scene visible glutSwapBuffers(); }