X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_geometry.c;h=b81a05ff6b7dadbf0f80d9f7e50c9f51bbb9af01;hb=65e03872c287ab34ae76bd1831a3786d5e986b72;hp=98f2046f6955c4bc997b1ef600ed5675dfd5fdf3;hpb=98ea79ef777bea593a87aef9600ee3d4fda6e110;p=freeglut diff --git a/src/freeglut_geometry.c b/src/freeglut_geometry.c index 98f2046..b81a05f 100644 --- a/src/freeglut_geometry.c +++ b/src/freeglut_geometry.c @@ -29,7 +29,7 @@ #include "config.h" #endif -#include "../include/GL/freeglut.h" +#include #include "freeglut_internal.h" /* @@ -39,13 +39,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 +52,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,374 +116,475 @@ 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 */ + + const int size = abs(n); - glPushMatrix(); - glScaled( radius, radius, radius ); + /* Determine the angle between samples */ - dpsi = M_PI / (stacks + 1); - dphi = 2 * M_PI / slices; - psi = dpsi; + const double angle = 2*M_PI/(double)n; - 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); + } + + glEnd(); + + /* Cover each stack with a quad strip, except the top and bottom stacks */ + + for( i=1; i + * Draws a solid cone */ -void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks ) +void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ) { - double radius = dRadius, phi, psi, dpsi, dphi; - double *next, *tmp, *row; - int i, j; - double cphi, sphi, cpsi, spsi ; + int i,j; - glPushMatrix(); - /* glScalef( radius, radius, radius ); */ + /* Step in z and radius as stacks are drawn. */ - row = (double *)calloc( sizeof(double), slices * 3 ); - next = (double *)calloc( sizeof(double), slices * 3 ); + double z0,z1; + double r0,r1; - dpsi = M_PI / (stacks + 1); - dphi = 2 * M_PI / slices; - psi = dpsi; - phi = 0; + const double zStep = height/stacks; + const double rStep = base/stacks; - /* init first line + do polar cap */ - glBegin( GL_TRIANGLE_FAN ); - glNormal3d( 0.0, 0.0, 1.0 ); - glVertex3d( 0.0, 0.0, radius ); + /* Scaling factors for vertex normals */ - for( i=0; i=0; i-- ) + /* Draw the stacks... */ + + for (i=0; i=0; j--) + glVertex3d(cost[j]*radius, sint[j]*radius, height); + glEnd(); + + /* Do the stacks */ - for( j=0; j