diff --git a/freeglut/freeglut/include/GL/freeglut_ext.h b/freeglut/freeglut/include/GL/freeglut_ext.h index 04ec79d..0f5ff00 100644 --- a/freeglut/freeglut/include/GL/freeglut_ext.h +++ b/freeglut/freeglut/include/GL/freeglut_ext.h @@ -97,6 +97,8 @@ FGAPI void FGAPIENTRY glutWireRhombicDodecahedron( void ); FGAPI void FGAPIENTRY glutSolidRhombicDodecahedron( void ); FGAPI void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale ) ; FGAPI void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale ) ; +FGAPI void FGAPIENTRY glutWireCylinder( GLdouble radius, GLdouble height, GLint slices, GLint stacks); +FGAPI void FGAPIENTRY glutSolidCylinder( GLdouble radius, GLdouble height, GLint slices, GLint stacks); /* * Extension functions, see freeglut_ext.c diff --git a/freeglut/freeglut/src/freeglut_geometry.c b/freeglut/freeglut/src/freeglut_geometry.c index 98f2046..36f6a78 100644 --- a/freeglut/freeglut/src/freeglut_geometry.c +++ b/freeglut/freeglut/src/freeglut_geometry.c @@ -30,6 +30,8 @@ #endif #include "../include/GL/freeglut.h" + + #include "freeglut_internal.h" /* @@ -39,13 +41,6 @@ * * glutWireCube() -- looks OK * glutSolidCube() -- OK - * glutWireSphere() -- OK - * glutSolidSphere() -- OK - * - * Following functions have been implemented by Pawel and modified by John Fay: - * - * glutWireCone() -- looks OK - * glutSolidCone() -- looks OK * * Those functions have been implemented by John Fay. * @@ -59,6 +54,14 @@ * glutSolidTetrahedron() -- looks OK * glutWireIcosahedron() -- looks OK * glutSolidIcosahedron() -- looks OK + * + * The Following functions have been updated by Nigel Stewart, based + * on FreeGLUT 2.0.0 implementations: + * + * glutWireSphere() -- looks OK + * glutSolidSphere() -- looks OK + * glutWireCone() -- looks OK + * glutSolidCone() -- looks OK */ @@ -115,284 +118,205 @@ void FGAPIENTRY glutSolidCube( GLdouble dSize ) } /* - * Draws a wire sphere. Code contributed by Andreas Umbach + * Compute lookup table of cos and sin values forming a cirle + * + * Notes: + * It is the responsibility of the caller to free these tables + * The size of the table is (n+1) to form a connected loop + * The last entry is exactly the same as the first + * The sign of n can be flipped to get the reverse loop */ -void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks ) + +static void circleTable(double **sint,double **cost,const int n) { - double radius = dRadius, phi, psi, dpsi, dphi; - double *vertex; - int i, j; - double cphi, sphi, cpsi, spsi ; + int i; - /* - * Allocate the vertices array - */ - vertex = (double *)calloc( sizeof(double), 3 * slices * (stacks - 1) ); + /* Table size, the sign of n flips the circle direction */ - glPushMatrix(); - glScaled( radius, radius, radius ); + const int size = abs(n); - dpsi = M_PI / (stacks + 1); - dphi = 2 * M_PI / slices; - psi = dpsi; + /* Determine the angle between samples */ - for( j=0; j=0; j--) + { + glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 ); + glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius); } - glNormal3d(0, 0, -1); - glVertex3d(0, 0, -1); + glEnd(); + + /* Cover each stack with a quad strip, except the top and bottom stacks */ + + for( i=1; i - */ -void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks ) -{ - double radius = dRadius, phi, psi, dpsi, dphi; - double *next, *tmp, *row; - int i, j; - double cphi, sphi, cpsi, spsi ; - - glPushMatrix(); - /* glScalef( radius, radius, radius ); */ - - row = (double *)calloc( sizeof(double), slices * 3 ); - next = (double *)calloc( sizeof(double), slices * 3 ); - - dpsi = M_PI / (stacks + 1); - dphi = 2 * M_PI / slices; - psi = dpsi; - phi = 0; - - /* init first line + do polar cap */ - glBegin( GL_TRIANGLE_FAN ); - glNormal3d( 0.0, 0.0, 1.0 ); - glVertex3d( 0.0, 0.0, radius ); - - for( i=0; i=0; i-- ) - { - glNormal3dv(row + 3 * i); - glVertex3d( - radius * *(row + 3 * i + 0), - radius * *(row + 3 * i + 1), - radius * *(row + 3 * i + 2) - ); - } - - glEnd(); - - free(row); - free(next); - glPopMatrix(); -} - -/* - * Draws a wire cone - */ -void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ) -{ - double alt = height / (double) (stacks + 1); - double angle = M_PI / (double) slices * 2.0; - double slope = ( height / base ); - double sBase = base ; - double sinNormal = ( base / sqrt ( height * height + base * base )); - double cosNormal = ( height / sqrt ( height * height + base * base )); - - double *vertices = NULL; - int i, j; - - /* - * We need 'slices' points on a circle - */ - vertices = (double *)calloc( sizeof(double), 2 * (slices + 1) ); - - for( j=0; 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); +} + +/* + * Draws a wire cylinder + */ +void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks) +{ + int i,j; + + /* Step in z and radius as stacks are drawn. */ + + double z = 0.0; + const double zStep = height/stacks; + + /* Pre-computed circle */ + + double *sint,*cost; + circleTable(&sint,&cost,-slices); + + /* Draw the stacks... */ + + for (i=0; i<=stacks; i++) + { + if (i==stacks) + z = height; + + glBegin(GL_LINE_LOOP); + + for( j=0; j