PDA

View Full Version : Closed cylinder



weber_ofir
09-18-2000, 07:31 AM
Is anyone know if there exist a function like auxSolidCylinder that generate a cylinder that have caps. I mean, a closed cylinder.

tdavie
09-20-2000, 07:23 AM
I don't think there is but you could try this:



glBegin (GL_QUAD_STRIP);
for (angle = 0; angle <= NumberOfPanels; angle ++)
{
glVertex3f (-CylinderLength,
sin (angle / NumberOfPanels * kPI) * CylinderCircumference,
cos (angle / NumberOfPanels * kPI) * CylinderCircumference);
glVertex3f (CylinderLength,
sin (angle / NumberOfPanels * kPI) * CylinderCircumference,
cos (angle / NumberOfPanels * kPI) * CylinderCircumference);
}
glVertex3f (-CylinderLength,
0, CylinderCircumference);
glVertex3f (CylinderLength,
0, CylinderCircumference);
glEnd ();
glBegin (GL_POLYGON);
for (angle = 0; angle <= NumberOfPanels; angle ++)
{
glVertex3f (-CylinderLength,
sin (angle / NumberOfPanels * kPI) * CylinderCircumference,
cos (angle / NumberOfPanels * kPI) * CylinderCircumference);
}
glVertex3f (-CylinderLength,
0, CylinderCircumference);
glEnd ();
glBegin (GL_POLYGON);
for (angle = 0; angle <= NumberOfPanels; angle ++)
{
glVertex3f (CylinderLength,
sin (angle / NumberOfPanels * kPI) * CylinderCircumference,
cos (angle / NumberOfPanels * kPI) * CylinderCircumference);
}
glVertex3f (CylinderLength,
0, CylinderCircumference);
glEnd ();


You would be better to precalculate all of the verticies and store them in a vertex array to make it run faster but the above should work. http://www.opengl.org/discussion_boards/ubb/biggrin.gif