8,303
社区成员
发帖
与我相关
我的任务
分享
/*
* Draws a solid cylinder
*/
void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
{
int i,j;
/* Step in z and radius as stacks are drawn. */
double z0,z1;
const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
/* Pre-computed circle */
double *sint,*cost;
FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
fghCircleTable(&sint,&cost,-slices);
/* Cover the base and top */
glBegin(GL_TRIANGLE_FAN);
glNormal3d(0.0, 0.0, -1.0 );
glVertex3d(0.0, 0.0, 0.0 );
for (j=0; j<=slices; j++)
glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
glEnd();
glBegin(GL_TRIANGLE_FAN);
glNormal3d(0.0, 0.0, 1.0 );
glVertex3d(0.0, 0.0, height);
for (j=slices; j>=0; j--)
glVertex3d(cost[j]*radius, sint[j]*radius, height);
glEnd();
/* Do the stacks */
z0 = 0.0;
z1 = zStep;
for (i=1; i<=stacks; i++)
{
if (i==stacks)
z1 = height;
glBegin(GL_QUAD_STRIP);
for (j=0; j<=slices; j++ )
{
glNormal3d(cost[j], sint[j], 0.0 );
glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
}
glEnd();
z0 = z1; z1 += zStep;
}
/* Release sin and cos tables */
free(sint);
free(cost);
}