X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_geometry.c;h=66659a46f1b7725f46de1a6bb871a7043e735d34;hb=4bb957b58beb8c268b37549e8d6d4fa4b925f858;hp=2ecf63c96b90aa2bd9ff2c2255114305be4260de;hpb=fae58eb47e5976cda391bd022fef7214ff05e11d;p=freeglut diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 2ecf63c..66659a4 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -61,8 +61,7 @@ */ -/* - * General function for drawing geometry. As for all geometry we have no +/* General function for drawing geometry. As for all geometry we have no * redundancy (or hardly any in the case of cones and cylinders) in terms * of the vertex/normal combinations, we just use glDrawArrays. * useWireMode controls the drawing of solids (false) or wire frame @@ -92,6 +91,35 @@ static void fghDrawGeometry(GLenum vertexMode, double* vertices, double* normals } } +static void fghGenerateGeometry(int numFaces, int numVertPerFace, GLdouble *vertices, GLubyte* vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut) +{ + int i,j; + /* + * Build array with vertices from vertex coordinates and vertex indices + * Do same for normals. + * Need to do this because of different normals at shared vertices + * (and because normals' coordinates need to be negated). + */ + for (i=0; i - */ -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 ); - - /* PWO: I dared to convert the code to use macros... */ - 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 -} - -/* - * Draws a solid cube. Code contributed by Andreas Umbach - */ -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 ); - - /* PWO: Again, I dared to convert the code to use macros... */ - glBegin( GL_QUADS ); - 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 -# undef N -} - /* * Draws a solid sphere @@ -1263,7 +1315,19 @@ void FGAPIENTRY glutSolidRhombicDodecahedron( void ) /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ - +/* + * Draws a wireframed cube. + */ +void FGAPIENTRY glutWireCube( GLdouble dSize ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" ); + fghCube( dSize, TRUE ); +} +void FGAPIENTRY glutSolidCube( GLdouble dSize ) +{ + FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" ); + fghCube( dSize, FALSE ); +} void FGAPIENTRY glutWireTetrahedron( void ) {