/* Rotating hexagon with HSV color wheel on front. Each vertex is given a hue based on its angle. The whole hexagon has the same intensity (V=1). Thus, we convert from HSV to RGB to specify the color at each vertex. First written by Scott D. Anderson, February, 1999 Updated to use TW Summer, 2003 */ #include #include #include #include // ================================================================ // Cone has this radius and height const float CONE_HEIGHT = 3; const float CONE_RADIUS = 2; /* *********************************************************************** Information about each vertex of the cone. The avoids having to calculate the color and position information four times. */ typedef struct { twTriple position; twTriple rgbColor; twTriple hsvColor; } Vinfo; Vinfo Center; // special vertex for center Vinfo Apex; // special vertex for apex Vinfo* Vertices; // dynamically allocated int NumWedges = 6; // Create a cone with a circular base on the z=0 plane with center at // origin and tip at (0,0,-height). void initVertexInfo() { twTripleInit(Center.position,0,0,0); twTripleInit(Center.rgbColor,1,1,1); twTripleInit(Center.hsvColor,0,0,1); twTripleInit(Apex.position,0,0,-CONE_HEIGHT); twTripleInit(Apex.rgbColor,0,0,0); twTripleInit(Apex.hsvColor,0,0,0); Vertices = (Vinfo*) malloc(NumWedges*sizeof(Vinfo)); int i; GLfloat angle; for(i=0; irgbColor); glVertex3fv(v->position); } void drawColorHexCone(void) { int i; /* First, the circular base. Do it as a triangle fan rather than one big polygon, otherwise OpenGL doesn't interpolate the colors correctly. */ glBegin(GL_TRIANGLE_FAN); drawVertex(&Center); for(i=0; i