X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=freeglut-1.3%2Ffreeglut_geometry.c;h=23ba7d6a6e31260679b939316031da39c30c9c4a;hb=a351855ee6b2ec6f477635a367c745d733219c3e;hp=da722971febc10d5ed2f52d7040c1ed37643661c;hpb=a86a957ae87e1b07260edec971ebdf5a98ff3d54;p=freeglut diff --git a/freeglut-1.3/freeglut_geometry.c b/freeglut-1.3/freeglut_geometry.c index da72297..23ba7d6 100644 --- a/freeglut-1.3/freeglut_geometry.c +++ b/freeglut-1.3/freeglut_geometry.c @@ -32,37 +32,35 @@ #define G_LOG_DOMAIN "freeglut-geometry" #include "../include/GL/freeglut.h" -#include "../include/GL/freeglut_internal.h" +#include "freeglut_internal.h" /* * TODO BEFORE THE STABLE RELEASE: * - * Following functions have been contributed by Andreas Umbach. I modified - * them a bit to make them use GLib (for memory allocation). + * Following functions have been contributed by Andreas Umbach. * - * glutWireCube() -- could add normal vectors so that lighting works + * glutWireCube() -- looks OK * glutSolidCube() -- OK * glutWireSphere() -- OK * glutSolidSphere() -- OK * - * Following functions have been implemented by me: + * Following functions have been implemented by Pawel and modified by John Fay: * * glutWireCone() -- looks OK - * glutSolidCone() -- normals are missing, there are holes in the thing + * glutSolidCone() -- looks OK * - * Those functions need to be implemented, as nothing has been done yet. - * For now all of them draw a wire or solid cube, just to mark their presence. + * Those functions have been implemented by John Fay. * - * glutWireTorus() -- - * glutSolidTorus() -- - * glutWireDodecahedron() -- - * glutSolidDodecahedron() -- - * glutWireOctahedron() -- - * glutSolidOctahedron() -- - * glutWireTetrahedron() -- - * glutSolidTetrahedron() -- - * glutWireIcosahedron() -- - * glutSolidIcosahedron() -- + * glutWireTorus() -- looks OK + * glutSolidTorus() -- looks OK + * glutWireDodecahedron() -- looks OK + * glutSolidDodecahedron() -- looks OK + * glutWireOctahedron() -- looks OK + * glutSolidOctahedron() -- looks OK + * glutWireTetrahedron() -- looks OK + * glutSolidTetrahedron() -- looks OK + * glutWireIcosahedron() -- looks OK + * glutSolidIcosahedron() -- looks OK */ @@ -73,21 +71,23 @@ */ void FGAPIENTRY glutWireCube( GLdouble dSize ) { - float size = (float) dSize * 0.5f; + double size = dSize * 0.5; -# define V(a,b,c) glVertex3f( a size, b size, c size ); +# define V(a,b,c) glVertex3d( a size, b size, c size ); +# define N(a,b,c) glNormal3d( a, b, c ); /* * PWO: I dared to convert the code to use macros... */ - glBegin( GL_LINE_LOOP ); V(-,-,+); V(+,-,+); V(+,+,+); V(-,+,+); glEnd(); - glBegin( GL_LINE_LOOP ); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd(); - glBegin( GL_LINES ); - V(-,-,+); V(-,-,-); V(-,+,+); V(-,+,-); - V(+,-,+); V(+,-,-); V(+,+,+); V(+,+,-); - glEnd(); + glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd(); + glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd(); + glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd(); + glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd(); + glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd(); + glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd(); # undef V +# undef N } /* @@ -95,21 +95,21 @@ void FGAPIENTRY glutWireCube( GLdouble dSize ) */ void FGAPIENTRY glutSolidCube( GLdouble dSize ) { - float size = (float) dSize * 0.5f; + double size = dSize * 0.5; -# define V(a,b,c) glVertex3f( a size, b size, c size ); -# define N(a,b,c) glNormal3f( a, b, c ); +# define V(a,b,c) glVertex3d( a size, b size, c size ); +# define N(a,b,c) glNormal3d( a, b, c ); /* * PWO: Again, I dared to convert the code to use macros... */ glBegin( GL_QUADS ); - N( 1, 0, 0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); - N( 0, 1, 0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); - N( 0, 0, 1); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); - N(-1, 0, 0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); - N( 0,-1, 0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); - N( 0, 0,-1); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); + N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); + N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); + N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); + N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); + N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); + N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd(); # undef V @@ -121,17 +121,18 @@ void FGAPIENTRY glutSolidCube( GLdouble dSize ) */ void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks ) { - float radius = (float) dRadius, phi, psi, dpsi, dphi; - float* vertex; + double radius = dRadius, phi, psi, dpsi, dphi; + double *vertex; int i, j; + double cphi, sphi, cpsi, spsi ; /* * Allocate the vertices array */ - vertex = calloc( sizeof(float), 3 * slices * (stacks - 1) ); + vertex = calloc( sizeof(double), 3 * slices * (stacks - 1) ); glPushMatrix(); - glScalef( radius, radius, radius ); + glScaled( radius, radius, radius ); dpsi = M_PI / (stacks + 1); dphi = 2 * M_PI / slices; @@ -139,15 +140,19 @@ void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks ) for( j=0; j=0; i-- ) { - glNormal3fv(row + 3 * i); - glVertex3f( + glNormal3dv(row + 3 * i); + glVertex3d( radius * *(row + 3 * i + 0), radius * *(row + 3 * i + 1), - radius * *(row + 3 * i + 2) + radius * *(row + 3 * i + 2) ); } @@ -304,237 +316,734 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks ) */ void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks ) { - float alt = (float) height / (float) (stacks + 1); - float angle = (float) M_PI / (float) slices * 2.0f; - float slope = (float) tan( height / base ); - float* vertices = NULL; - int i, j; - - /* - * We need 'slices' points on a circle - */ - vertices = calloc( sizeof(float), 2 * (slices + 1) ); - - for( i=0; i