X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_geometry.c;h=0b177935763f4da667b7e3100ff5814ca6ce9de9;hb=a14928fc505633d395e18db84ce7dbfd7386fa5f;hp=3184fa981e9a40575e7bdc9a8074621a69c86350;hpb=3c1e1a5baed46b7efd6b6a499f500651535aa24f;p=freeglut diff --git a/src/freeglut_geometry.c b/src/freeglut_geometry.c index 3184fa9..0b17793 100644 --- a/src/freeglut_geometry.c +++ b/src/freeglut_geometry.c @@ -25,10 +25,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include "freeglut_internal.h" @@ -72,6 +68,8 @@ void FGAPIENTRY glutWireCube( GLdouble dSize ) { double size = dSize * 0.5; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" ); + # define V(a,b,c) glVertex3d( a size, b size, c size ); # define N(a,b,c) glNormal3d( a, b, c ); @@ -94,6 +92,8 @@ void FGAPIENTRY glutSolidCube( GLdouble dSize ) { double size = dSize * 0.5; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" ); + # define V(a,b,c) glVertex3d( a size, b size, c size ); # define N(a,b,c) glNormal3d( a, b, c ); @@ -180,6 +180,9 @@ void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks) double *sint1,*cost1; double *sint2,*cost2; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" ); + fghCircleTable(&sint1,&cost1,-slices); fghCircleTable(&sint2,&cost2,stacks*2); @@ -265,6 +268,9 @@ void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks) double *sint1,*cost1; double *sint2,*cost2; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" ); + fghCircleTable(&sint1,&cost1,-slices ); fghCircleTable(&sint2,&cost2, stacks*2); @@ -339,6 +345,9 @@ void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLi /* Pre-computed circle */ double *sint,*cost; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" ); + fghCircleTable(&sint,&cost,-slices); /* Cover the circular base with a triangle fan... */ @@ -423,6 +432,9 @@ void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLin /* Pre-computed circle */ double *sint,*cost; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" ); + fghCircleTable(&sint,&cost,-slices); /* Draw the stacks... */ @@ -480,6 +492,9 @@ void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices /* Pre-computed circle */ double *sint,*cost; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" ); + fghCircleTable(&sint,&cost,-slices); /* Cover the base and top */ @@ -541,6 +556,9 @@ void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, /* Pre-computed circle */ double *sint,*cost; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" ); + fghCircleTable(&sint,&cost,-slices); /* Draw the stacks... */ @@ -591,6 +609,9 @@ void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLi double *vertex, *normal; int i, j; double spsi, cpsi, sphi, cphi ; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" ); + if ( nSides < 1 ) nSides = 1; if ( nRings < 1 ) nRings = 1; @@ -669,6 +690,9 @@ void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GL double *vertex, *normal; int i, j; double spsi, cpsi, sphi, cphi ; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" ); + if ( nSides < 1 ) nSides = 1; if ( nRings < 1 ) nRings = 1; @@ -738,6 +762,8 @@ void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GL */ void FGAPIENTRY glutWireDodecahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" ); + /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of * of a cube. The coordinates of the points are: * (+-x,0, z); (+-1, 1, 1); (0, z, x ) @@ -789,6 +815,8 @@ void FGAPIENTRY glutWireDodecahedron( void ) */ void FGAPIENTRY glutSolidDodecahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" ); + /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of * of a cube. The coordinates of the points are: * (+-x,0, z); (+-1, 1, 1); (0, z, x ) @@ -840,6 +868,8 @@ void FGAPIENTRY glutSolidDodecahedron( void ) */ void FGAPIENTRY glutWireOctahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" ); + #define RADIUS 1.0f glBegin( GL_LINE_LOOP ); glNormal3d( 0.577350269189, 0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, RADIUS, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); @@ -859,6 +889,8 @@ void FGAPIENTRY glutWireOctahedron( void ) */ void FGAPIENTRY glutSolidOctahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" ); + #define RADIUS 1.0f glBegin( GL_TRIANGLES ); glNormal3d( 0.577350269189, 0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, RADIUS, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); @@ -900,6 +932,8 @@ static GLint tet_i[4][3] = /* Vertex indices */ */ void FGAPIENTRY glutWireTetrahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" ); + glBegin( GL_LINE_LOOP ) ; glNormal3d ( -tet_r[0][0], -tet_r[0][1], -tet_r[0][2] ) ; glVertex3dv ( tet_r[1] ) ; glVertex3dv ( tet_r[3] ) ; glVertex3dv ( tet_r[2] ) ; glNormal3d ( -tet_r[1][0], -tet_r[1][1], -tet_r[1][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[2] ) ; glVertex3dv ( tet_r[3] ) ; @@ -913,6 +947,8 @@ void FGAPIENTRY glutWireTetrahedron( void ) */ void FGAPIENTRY glutSolidTetrahedron( void ) { + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" ); + glBegin( GL_TRIANGLES ) ; glNormal3d ( -tet_r[0][0], -tet_r[0][1], -tet_r[0][2] ) ; glVertex3dv ( tet_r[1] ) ; glVertex3dv ( tet_r[3] ) ; glVertex3dv ( tet_r[2] ) ; glNormal3d ( -tet_r[1][0], -tet_r[1][1], -tet_r[1][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[2] ) ; glVertex3dv ( tet_r[3] ) ; @@ -924,18 +960,50 @@ void FGAPIENTRY glutSolidTetrahedron( void ) /* * */ -double icos_r[12][3] = { { 1.0, 0.0, 0.0 }, - { 0.447213595500, 0.894427191000, 0.0 }, { 0.447213595500, 0.276393202252, 0.850650808354 }, { 0.447213595500, -0.723606797748, 0.525731112119 }, { 0.447213595500, -0.723606797748, -0.525731112119 }, { 0.447213595500, 0.276393202252, -0.850650808354 }, - { -0.447213595500, -0.894427191000, 0.0 }, { -0.447213595500, -0.276393202252, 0.850650808354 }, { -0.447213595500, 0.723606797748, 0.525731112119 }, { -0.447213595500, 0.723606797748, -0.525731112119 }, { -0.447213595500, -0.276393202252, -0.850650808354 }, - { -1.0, 0.0, 0.0 } } ; -int icos_v [20][3] = { { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 5 }, { 0, 5, 1 }, - { 1, 8, 2 }, { 2, 7, 3 }, { 3, 6, 4 }, { 4, 10, 5 }, { 5, 9, 1 }, - { 1, 9, 8 }, { 2, 8, 7 }, { 3, 7, 6 }, { 4, 6, 10 }, { 5, 10, 9 }, - { 11, 9, 10 }, { 11, 8, 9 }, { 11, 7, 8 }, { 11, 6, 7 }, { 11, 10, 6 } } ; +static double icos_r[12][3] = { + { 1.0, 0.0, 0.0 }, + { 0.447213595500, 0.894427191000, 0.0 }, + { 0.447213595500, 0.276393202252, 0.850650808354 }, + { 0.447213595500, -0.723606797748, 0.525731112119 }, + { 0.447213595500, -0.723606797748, -0.525731112119 }, + { 0.447213595500, 0.276393202252, -0.850650808354 }, + { -0.447213595500, -0.894427191000, 0.0 }, + { -0.447213595500, -0.276393202252, 0.850650808354 }, + { -0.447213595500, 0.723606797748, 0.525731112119 }, + { -0.447213595500, 0.723606797748, -0.525731112119 }, + { -0.447213595500, -0.276393202252, -0.850650808354 }, + { -1.0, 0.0, 0.0 } +}; + +static int icos_v [20][3] = { + { 0, 1, 2 }, + { 0, 2, 3 }, + { 0, 3, 4 }, + { 0, 4, 5 }, + { 0, 5, 1 }, + { 1, 8, 2 }, + { 2, 7, 3 }, + { 3, 6, 4 }, + { 4, 10, 5 }, + { 5, 9, 1 }, + { 1, 9, 8 }, + { 2, 8, 7 }, + { 3, 7, 6 }, + { 4, 6, 10 }, + { 5, 10, 9 }, + { 11, 9, 10 }, + { 11, 8, 9 }, + { 11, 7, 8 }, + { 11, 6, 7 }, + { 11, 10, 6 } +}; void FGAPIENTRY glutWireIcosahedron( void ) { int i ; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" ); + for ( i = 0; i < 20; i++ ) { double normal[3] ; @@ -958,6 +1026,8 @@ void FGAPIENTRY glutSolidIcosahedron( void ) { int i ; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" ); + glBegin ( GL_TRIANGLES ) ; for ( i = 0; i < 20; i++ ) { @@ -977,23 +1047,59 @@ void FGAPIENTRY glutSolidIcosahedron( void ) /* * */ -double rdod_r[14][3] = { { 0.0, 0.0, 1.0 }, - { 0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, 0.707106781187, 0.5 }, { -0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, -0.707106781187, 0.5 }, - { 0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, -0.707106781187, 0.0 }, { 0.707106781187, -0.707106781187, 0.0 }, - { 0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, 0.707106781187, -0.5 }, { -0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, -0.707106781187, -0.5 }, - { 0.0, 0.0, -1.0 } } ; -int rdod_v [12][4] = { { 0, 1, 5, 2 }, { 0, 2, 6, 3 }, { 0, 3, 7, 4 }, { 0, 4, 8, 1 }, - { 5, 10, 6, 2 }, { 6, 11, 7, 3 }, { 7, 12, 8, 4 }, { 8, 9, 5, 1 }, - { 5, 9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ; -double rdod_n[12][3] = { - { 0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, -0.353553390594, 0.5 }, { 0.353553390594, -0.353553390594, 0.5 }, - { 0.000000000000, 1.000000000000, 0.0 }, { -1.000000000000, 0.000000000000, 0.0 }, { 0.000000000000, -1.000000000000, 0.0 }, { 1.000000000000, 0.000000000000, 0.0 }, - { 0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, { 0.353553390594, -0.353553390594, -0.5 } - } ; +static double rdod_r[14][3] = { + { 0.0, 0.0, 1.0 }, + { 0.707106781187, 0.000000000000, 0.5 }, + { 0.000000000000, 0.707106781187, 0.5 }, + { -0.707106781187, 0.000000000000, 0.5 }, + { 0.000000000000, -0.707106781187, 0.5 }, + { 0.707106781187, 0.707106781187, 0.0 }, + { -0.707106781187, 0.707106781187, 0.0 }, + { -0.707106781187, -0.707106781187, 0.0 }, + { 0.707106781187, -0.707106781187, 0.0 }, + { 0.707106781187, 0.000000000000, -0.5 }, + { 0.000000000000, 0.707106781187, -0.5 }, + { -0.707106781187, 0.000000000000, -0.5 }, + { 0.000000000000, -0.707106781187, -0.5 }, + { 0.0, 0.0, -1.0 } +} ; + +static int rdod_v [12][4] = { + { 0, 1, 5, 2 }, + { 0, 2, 6, 3 }, + { 0, 3, 7, 4 }, + { 0, 4, 8, 1 }, + { 5, 10, 6, 2 }, + { 6, 11, 7, 3 }, + { 7, 12, 8, 4 }, + { 8, 9, 5, 1 }, + { 5, 9, 13, 10 }, + { 6, 10, 13, 11 }, + { 7, 11, 13, 12 }, + { 8, 12, 13, 9 } +}; + +static double rdod_n[12][3] = { + { 0.353553390594, 0.353553390594, 0.5 }, + { -0.353553390594, 0.353553390594, 0.5 }, + { -0.353553390594, -0.353553390594, 0.5 }, + { 0.353553390594, -0.353553390594, 0.5 }, + { 0.000000000000, 1.000000000000, 0.0 }, + { -1.000000000000, 0.000000000000, 0.0 }, + { 0.000000000000, -1.000000000000, 0.0 }, + { 1.000000000000, 0.000000000000, 0.0 }, + { 0.353553390594, 0.353553390594, -0.5 }, + { -0.353553390594, 0.353553390594, -0.5 }, + { -0.353553390594, -0.353553390594, -0.5 }, + { 0.353553390594, -0.353553390594, -0.5 } +}; void FGAPIENTRY glutWireRhombicDodecahedron( void ) { int i ; + + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" ); + for ( i = 0; i < 12; i++ ) { glBegin ( GL_LINE_LOOP ) ; @@ -1013,6 +1119,8 @@ void FGAPIENTRY glutSolidRhombicDodecahedron( void ) { int i ; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" ); + glBegin ( GL_QUADS ) ; for ( i = 0; i < 12; i++ ) { @@ -1030,6 +1138,8 @@ void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], G { int i, j ; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" ); + if ( num_levels == 0 ) { @@ -1048,7 +1158,7 @@ void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], G glEnd () ; } } - else + else if ( num_levels > 0 ) { GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ num_levels -- ; @@ -1067,6 +1177,8 @@ void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], { int i, j ; + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" ); + if ( num_levels == 0 ) { glBegin ( GL_TRIANGLES ) ; @@ -1085,7 +1197,7 @@ void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], glEnd () ; } - else + else if ( num_levels > 0 ) { GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */ num_levels -- ;