/* Demo of two cones. One is done using glutSolidCone, and the other with gluCylinder (via twCylinder). glutSolidCone has the base drawn, but gluCylinder does not, so if you want an "open" cone (like a desk lamp or a megaphone), you have to use cylinders. The result looks a little like a witch's hat. Implemented Fall 2007 Scott D. Anderson */ #include #include #include void display(void) { twDisplayInit(); twCamera(); // Lighting is not enabled in the program, but if you enable it // interactively via the menu, you can see lighting effects on both // cones, which means both have normals defined. GLfloat lightpos[] = { 1, 1, 0, 0 }; twGrayLight(GL_LIGHT0,lightpos, 0.1, 1, 1 ); // The following draws the z=0 plane, which confirms that the base of // each cone lies on that plane. if(false) { twColorName(TW_CYAN); glBegin(GL_QUADS); glVertex3f(-10,-10,0); glVertex3f(+10,-10,0); glVertex3f(+10,+10,0); glVertex3f(-10,+10,0); glEnd(); } // Mark the origin glPointSize(5); twColorName(TW_MAGENTA); glBegin(GL_POINTS); glVertex3f(0,0,0); glEnd(); twColorName(TW_MAROON); const GLfloat cylHeight = 2; const GLfloat cylCutoff = 65; const GLfloat cylBase = cylHeight*tan(cylCutoff*M_PI/180); twCylinder(cylBase,0,cylHeight,8,1); twColorName(TW_BROWN); const GLfloat coneHeight = 10; const GLfloat coneCutoff = 15; const GLfloat coneBase = coneHeight*tan(coneCutoff*M_PI/180); glutSolidCone(coneBase,coneHeight,8,1); glFlush(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-10,10,-10,10,-10,10); twMainInit(); glutMainLoop(); return 0; }