Skip to content

Instantly share code, notes, and snippets.

@jchain
Created June 30, 2012 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchain/3022588 to your computer and use it in GitHub Desktop.
Save jchain/3022588 to your computer and use it in GitHub Desktop.
xxx
/***************************************************
** Draw a cone **
***************************************************/
void DrawCone()
{
float angle;
float weight;
float red_component;
float blue_component;
// Draw conical part, including 40+ triangles
glBegin( GL_TRIANGLE_FAN );
// The tip of the cone is green
glColor3f( 0.0, 1.0, 0.0 );
// The tip of the cone at (0,0,2)
glVertex3f( 0.0, 0.0, 2.0 );
for ( int i = 0; i < 40; i++ ) {
angle = i*2*PI / 39;
if ( i < 21 ) {
weight = i / 20.0;
}
else {
weight = 1.0 - ( i - 20 ) / 20.0;
}
red_component = 1.0 * weight;
blue_component = 1.0 * ( 1.0 - weight );
glColor3f( red_component, 0.0, blue_component );
glVertex3f( cos( angle ), sin( angle ), 0.0 );
}
glEnd();
// Draw base part, including 40+ triangles
glBegin( GL_TRIANGLE_FAN );
// The tip of the cone is green
//glColor3f( 0.0, 1.0, 0.0 );
// The tip of the cone at (0,0,0)
glVertex3f( 0.0, 0.0, 0.0 );
for ( int i = 0; i < 40; i++ ) {
angle = i*2*PI / 39;
if ( i < 21 ) {
weight = i / 20.0;
}
else {
weight = 1.0 - ( i - 20 ) / 20.0;
}
red_component = 1.0 * weight;
blue_component = 1.0 * ( 1.0 - weight );
glColor3f( red_component, 0.0, blue_component );
glVertex3f( cos( angle ), sin( angle ), 0.0 );
}
glEnd();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment