version bumps
[freeglut] / freeglut-1.3 / freeglut_geometry.c
index da72297..23ba7d6 100644 (file)
 #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
  */
 
 
  */
 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<stacks-1; j++ )
     {
-        phi = 0;
+        cpsi = cos ( psi ) ;
+        spsi = sin ( psi ) ;
+        phi = 0.0;
 
         for( i=0; i<slices; i++ )
         {
-            *(vertex + 3 * j * slices + 3 * i + 0) = sin( phi ) * sin( psi );
-            *(vertex + 3 * j * slices + 3 * i + 1) = cos( phi ) * sin( psi );
-            *(vertex + 3 * j * slices + 3 * i + 2) = cos( psi );
+          int offset = 3 * ( j * slices + i ) ;
+          cphi = cos ( phi ) ;
+          sphi = sin ( phi ) ;
+            *(vertex + offset + 0) = sphi * spsi ;
+            *(vertex + offset + 1) = cphi * spsi ;
+            *(vertex + offset + 2) = cpsi ;
             phi += dphi;
-            glVertex3fv( vertex + 3 * j * slices + 3 * i );
         }
 
         psi += dpsi;
@@ -156,17 +161,18 @@ void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks )
     for( i=0; i<slices; i++ )
     {
         glBegin( GL_LINE_STRIP );
-        glNormal3f( 0, 0, 1 );
-        glVertex3f( 0, 0, 1 );
+        glNormal3d( 0, 0, 1 );
+        glVertex3d( 0, 0, 1 );
 
         for( j=0; j<stacks - 1; j++ )
         {
-            glNormal3fv( vertex + 3 * j * slices + 3 * i );
-            glVertex3fv( vertex + 3 * j * slices + 3 * i );
+          int offset = 3 * ( j * slices + i ) ;
+            glNormal3dv( vertex + offset );
+            glVertex3dv( vertex + offset );
         }
 
-        glNormal3f(0, 0, -1);
-        glVertex3f(0, 0, -1);
+        glNormal3d(0, 0, -1);
+        glVertex3d(0, 0, -1);
         glEnd();
     }
 
@@ -176,8 +182,9 @@ void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks )
 
         for( i=0; i<slices; i++ )
         {
-            glNormal3fv( vertex + 3 * j * slices + 3 * i );
-            glVertex3fv( vertex + 3 * j * slices + 3 * i );
+          int offset = 3 * ( j * slices + i ) ;
+            glNormal3dv( vertex + offset );
+            glVertex3dv( vertex + offset );
         }
 
         glEnd();
@@ -192,15 +199,16 @@ void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks )
  */
 void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
 {
-    float  radius = (float) dRadius, phi, psi, dpsi, dphi;
-    float *next, *tmp, *row;
+    double  radius = dRadius, phi, psi, dpsi, dphi;
+    double *next, *tmp, *row;
     int    i, j;
+    double cphi, sphi, cpsi, spsi ;
 
     glPushMatrix();
-    //glScalef( radius, radius, radius );
+    /* glScalef( radius, radius, radius ); */
 
-    row  = calloc( sizeof(float), slices * 3 );
-    next = calloc( sizeof(float), slices * 3 );
+    row  = calloc( sizeof(double), slices * 3 );
+    next = calloc( sizeof(double), slices * 3 );
 
     dpsi = M_PI / (stacks + 1);
     dphi = 2 * M_PI / slices;
@@ -209,8 +217,8 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
 
     /* init first line + do polar cap */
     glBegin( GL_TRIANGLE_FAN );
-    glNormal3f( 0, 0, 1 );
-    glVertex3f( 0, 0, radius );
+    glNormal3d( 0.0, 0.0, 1.0 );
+    glVertex3d( 0.0, 0.0, radius );
 
     for( i=0; i<slices; i++ )
     {
@@ -218,24 +226,26 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
         row[ i * 3 + 1 ] = cos( phi ) * sin( psi );
         row[ i * 3 + 2 ] = cos( psi );
 
-        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)
            );
        
         phi += dphi;
     }
 
-    glNormal3fv( row );
-    glVertex3f( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
+    glNormal3dv( row );
+    glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
     glEnd();
 
     for( j=0; j<stacks-1; j++ )
     {
-        phi = 0;
+        phi = 0.0;
         psi += dpsi;
+        cpsi = cos ( psi ) ;
+        spsi = sin ( psi ) ;
 
         /* get coords */
         glBegin( GL_QUAD_STRIP );
@@ -243,19 +253,21 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
         /* glBegin(GL_LINE_LOOP); */
         for( i=0; i<slices; i++ )
         {
-            next[ i * 3 + 0 ] = sin( phi ) * sin( psi );
-            next[ i * 3 + 1 ] = cos( phi ) * sin( psi );
-            next[ i * 3 + 2 ] = cos( psi );
-
-            glNormal3fv( row + i * 3 );
-            glVertex3f(
+          cphi = cos ( phi ) ;
+          sphi = sin ( phi ) ;
+            next[ i * 3 + 0 ] = sphi * spsi ;
+            next[ i * 3 + 1 ] = cphi * spsi ;
+            next[ i * 3 + 2 ] = cpsi ;
+
+            glNormal3dv( row + i * 3 );
+            glVertex3d(
                 radius * *(row + 3 * i + 0),
                 radius * *(row + 3 * i + 1),
                        radius * *(row + 3 * i + 2)
                    );
 
-            glNormal3fv( next + i * 3 );
-            glVertex3f(
+            glNormal3dv( next + i * 3 );
+            glVertex3d(
                 radius * *(next + 3 * i + 0),
                 radius * *(next + 3 * i + 1),
                 radius * *(next + 3 * i + 2)
@@ -264,10 +276,10 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
             phi += dphi;
         }
 
-        glNormal3fv( row );
-        glVertex3f( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
-        glNormal3fv( next );
-        glVertex3f( radius * *(next + 0), radius * *(next + 1), radius * *(next + 2) );
+        glNormal3dv( row );
+        glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
+        glNormal3dv( next );
+        glVertex3d( radius * *(next + 0), radius * *(next + 1), radius * *(next + 2) );
         glEnd();
 
         tmp = row;
@@ -277,18 +289,18 @@ void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
 
     /* south pole */
     glBegin( GL_TRIANGLE_FAN );
-    glNormal3f( 0, 0, -1 );
-    glVertex3f( 0, 0, -radius );
-    glNormal3fv( row );
-    glVertex3f( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
+    glNormal3d( 0.0, 0.0, -1.0 );
+    glVertex3d( 0.0, 0.0, -radius );
+    glNormal3dv( row );
+    glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
 
     for( i=slices-1; i>=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<slices+1; i++ )
+  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 = calloc( sizeof(double), 2 * (slices + 1) );
+
+  for( j=0; j<slices+1; j++ )
+  {
+    vertices[ j*2 + 0 ] = cos( angle * j );
+    vertices[ j*2 + 1 ] = sin( angle * j );
+  }
+
+  /*
+   * First the cone's bottom...
+   */
+  for( j=0; j<slices; j++ )
+  {
+    glBegin( GL_LINE_LOOP );
+      glNormal3d( 0.0, 0.0, -1.0 );
+      glVertex3d( vertices[ (j+0)*2+0 ] * sBase, vertices[ (j+0)*2+1 ] * sBase, 0 );
+      glVertex3d( vertices[ (j+1)*2+0 ] * sBase, vertices[ (j+1)*2+1 ] * sBase, 0 );
+      glVertex3d( 0.0, 0.0, 0.0 );
+    glEnd();
+  }
+
+  /*
+   * Then all the stacks between the bottom and the top
+   */
+  for( i=0; i<stacks; i++ )
+  {
+    double alt_a = i * alt, alt_b = (i + 1) * alt;
+    double scl_a = (height - alt_a) / slope;
+    double scl_b = (height - alt_b) / slope;
+
+    for( j=0; j<slices; j++ )
     {
-        vertices[ i*2 + 0 ] = cos( angle * i );
-        vertices[ i*2 + 1 ] = sin( angle * i );
+      glBegin( GL_LINE_LOOP );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
+        glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
+      glEnd();
+
+      glBegin( GL_LINE_LOOP );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
+        glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
+        glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
+      glEnd();
     }
+  }
+
+  /*
+   * Finally have the top part drawn...
+   */
+  for( j=0; j<slices; j++ )
+  {
+    double scl = alt / slope;
+
+    glBegin( GL_LINE_LOOP );
+      glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+      glVertex3d( vertices[ (j+0)*2+0 ] * scl, vertices[ (j+0)*2+1 ] * scl, height - alt );
+      glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+      glVertex3d( vertices[ (j+1)*2+0 ] * scl, vertices[ (j+1)*2+1 ] * scl, height - alt );
+      glVertex3d( 0, 0, height );
+    glEnd();
+  }
+}
 
-    /*
-     * First the cone's bottom...
-     */
-    for( i=0; i<slices; i++ )
+/*
+ * Draws a solid cone
+ */
+void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
+{
+  double  alt   = height / (double) (stacks + 1);
+  double  angle = M_PI / (double) slices * 2.0f;
+  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 = calloc( sizeof(double), 2 * (slices + 1) );
+
+  for( j=0; j<slices+1; j++ )
+  {
+    vertices[ j*2 + 0 ] = cos( angle * j );
+    vertices[ j*2 + 1 ] = sin( angle * j );
+  }
+
+  /*
+   * First the cone's bottom...
+   */
+  for( j=0; j<slices; j++ )
+  {
+    double scl = height / slope;
+
+    glBegin( GL_TRIANGLES );
+      glNormal3d( 0.0, 0.0, -1.0 );
+      glVertex3d( vertices[ (j+0)*2+0 ] * sBase, vertices[ (j+0)*2+1 ] * sBase, 0 );
+      glVertex3d( vertices[ (j+1)*2+0 ] * sBase, vertices[ (j+1)*2+1 ] * sBase, 0 );
+      glVertex3d( 0.0, 0.0, 0.0 );
+    glEnd();
+  }
+
+  /*
+   * Then all the stacks between the bottom and the top
+   */
+  for( i=0; i<stacks; i++ )
+  {
+    double alt_a = i * alt, alt_b = (i + 1) * alt;
+    double scl_a = (height - alt_a) / slope;
+    double scl_b = (height - alt_b) / slope;
+
+    for( j=0; j<slices; j++ )
     {
-        float scl = height / slope;
-
-        glBegin( GL_LINE_LOOP );
-            glNormal3f( 0, 0, -1 );
-            glVertex3f( vertices[ (i+0)*2+0 ] * scl, vertices[ (i+0)*2+1 ] * scl, 0 );
-            glVertex3f( vertices[ (i+1)*2+0 ] * scl, vertices[ (i+1)*2+1 ] * scl, 0 );
-            glVertex3f( 0, 0, 0 );
-        glEnd();
+      glBegin( GL_TRIANGLES );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
+        glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
+      glEnd();
+
+      glBegin( GL_TRIANGLES );
+        glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
+        glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+        glVertex3d( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
+        glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
+      glEnd();
     }
+  }
+
+  /*
+   * Finally have the top part drawn...
+   */
+  for( j=0; j<slices; j++ )
+  {
+    double scl = alt / slope;
+
+    glBegin( GL_TRIANGLES );
+      glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
+      glVertex3d( vertices[ (j+0)*2+0 ] * scl, vertices[ (j+0)*2+1 ] * scl, height - alt );
+      glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
+      glVertex3d( vertices[ (j+1)*2+0 ] * scl, vertices[ (j+1)*2+1 ] * scl, height - alt );
+      glVertex3d( 0, 0, height );
+    glEnd();
+  }
+}
 
-    /*
-     * Then all the stacks between the bottom and the top
-     *
-     * ekhm jak wektor normalny z trojkata?
-     */
-    for( i=0; i<stacks; i++ )
+/*
+ *
+ */
+void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
+{
+  double  iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
+  double *vertex, *normal;
+  int    i, j;
+  double spsi, cpsi, sphi, cphi ;
+
+  /*
+   * Allocate the vertices array
+   */
+  vertex = calloc( sizeof(double), 3 * nSides * nRings );
+  normal = calloc( sizeof(double), 3 * nSides * nRings );
+
+  glPushMatrix();
+
+  dpsi = 2.0 * M_PI / (double)nRings ;
+  dphi = 2.0 * M_PI / (double)nSides ;
+  psi  = 0.0;
+
+  for( j=0; j<nRings; j++ )
+  {
+    cpsi = cos ( psi ) ;
+    spsi = sin ( psi ) ;
+    phi = 0.0;
+
+    for( i=0; i<nSides; i++ )
     {
-        float alt_a = i * alt, alt_b = (i + 1) * alt;
-        float scl_a = (height - alt_a) / slope;
-        float scl_b = (height - alt_b) / slope;
-
-        for( j=0; j<slices; j++ )
-        {
-            glBegin( GL_LINE_LOOP );
-                glVertex3f( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
-                glVertex3f( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
-                glVertex3f( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
-            glEnd();
-
-            glBegin( GL_LINE_LOOP );
-                glVertex3f( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
-                glVertex3f( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
-                glVertex3f( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
-            glEnd();
-        }
+      int offset = 3 * ( j * nSides + i ) ;
+      cphi = cos ( phi ) ;
+      sphi = sin ( phi ) ;
+      *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
+      *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
+      *(vertex + offset + 2) =                    sphi * iradius   ;
+      *(normal + offset + 0) = cpsi * cphi ;
+      *(normal + offset + 1) = spsi * cphi ;
+      *(normal + offset + 2) =        sphi ;
+      phi += dphi;
     }
 
-    /*
-     * Finally have the top part drawn...
-     */
-    for( i=0; i<slices; i++ )
+    psi += dpsi;
+  }
+
+  for( i=0; i<nSides; i++ )
+  {
+    glBegin( GL_LINE_LOOP );
+
+    for( j=0; j<nRings; j++ )
     {
-        float scl = alt / slope;
+      int offset = 3 * ( j * nSides + i ) ;
+      glNormal3dv( normal + offset );
+      glVertex3dv( vertex + offset );
+    }
 
-        glBegin( GL_LINE_LOOP );
-            glVertex3f( vertices[ (i+0)*2+0 ] * scl, vertices[ (i+0)*2+1 ] * scl, height - alt );
-            glVertex3f( vertices[ (i+1)*2+0 ] * scl, vertices[ (i+1)*2+1 ] * scl, height - alt );
-            glVertex3f( 0, 0, height );
-        glEnd();
+    glEnd();
+  }
+
+  for( j=0; j<nRings; j++ )
+  {
+    glBegin(GL_LINE_LOOP);
+
+    for( i=0; i<nSides; i++ )
+    {
+      int offset = 3 * ( j * nSides + i ) ;
+      glNormal3dv( normal + offset );
+      glVertex3dv( vertex + offset );
     }
+
+    glEnd();
+  }
+
+  free ( vertex ) ;
+  free ( normal ) ;
+  glPopMatrix();
 }
 
 /*
- * Draws a solid cone
+ *
  */
-void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
+void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
 {
-    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<slices+1; i++ )
+  double  iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
+  double *vertex, *normal;
+  int    i, j;
+  double spsi, cpsi, sphi, cphi ;
+
+  /*
+   * Increment the number of sides and rings to allow for one more point than surface
+   */
+  nSides ++ ;
+  nRings ++ ;
+
+  /*
+   * Allocate the vertices array
+   */
+  vertex = calloc( sizeof(double), 3 * nSides * nRings );
+  normal = calloc( sizeof(double), 3 * nSides * nRings );
+
+  glPushMatrix();
+
+  dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
+  dphi = 2.0 * M_PI / (double)(nSides - 1) ;
+  psi  = 0.0;
+
+  for( j=0; j<nRings; j++ )
+  {
+    cpsi = cos ( psi ) ;
+    spsi = sin ( psi ) ;
+    phi = 0.0;
+
+    for( i=0; i<nSides; i++ )
     {
-        vertices[ i*2 + 0 ] = cos( angle * i );
-        vertices[ i*2 + 1 ] = sin( angle * i );
+      int offset = 3 * ( j * nSides + i ) ;
+      cphi = cos ( phi ) ;
+      sphi = sin ( phi ) ;
+      *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
+      *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
+      *(vertex + offset + 2) =                    sphi * iradius   ;
+      *(normal + offset + 0) = cpsi * cphi ;
+      *(normal + offset + 1) = spsi * cphi ;
+      *(normal + offset + 2) =        sphi ;
+      phi += dphi;
     }
 
-    /*
-     * First the cone's bottom...
-     */
-    for( i=0; i<slices; i++ )
-    {
-        float scl = height / slope;
-
-        glBegin( GL_TRIANGLES );
-            glNormal3f( 0, 0, -1 );
-            glVertex3f( vertices[ (i+0)*2+0 ] * scl, vertices[ (i+0)*2+1 ] * scl, 0 );
-            glVertex3f( vertices[ (i+1)*2+0 ] * scl, vertices[ (i+1)*2+1 ] * scl, 0 );
-            glVertex3f( 0, 0, 0 );
-        glEnd();
-    }
+    psi += dpsi;
+  }
 
-    /*
-     * Then all the stacks between the bottom and the top
-     *
-     * ekhm jak wektor normalny z trojkata?
-     */
-    for( i=0; i<stacks; i++ )
+    glBegin( GL_QUADS );
+  for( i=0; i<nSides-1; i++ )
+  {
+    for( j=0; j<nRings-1; j++ )
     {
-        float alt_a = i * alt, alt_b = (i + 1) * alt;
-        float scl_a = (height - alt_a) / slope;
-        float scl_b = (height - alt_b) / slope;
-
-        for( j=0; j<slices; j++ )
-        {
-            glBegin( GL_TRIANGLES );
-                glVertex3f( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
-                glVertex3f( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
-                glVertex3f( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
-            glEnd();
-
-            glBegin( GL_TRIANGLES );
-                glVertex3f( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
-                glVertex3f( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
-                glVertex3f( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
-            glEnd();
-        }
+      int offset = 3 * ( j * nSides + i ) ;
+      glNormal3dv( normal + offset );
+      glVertex3dv( vertex + offset );
+      glNormal3dv( normal + offset + 3 );
+      glVertex3dv( vertex + offset + 3 );
+      glNormal3dv( normal + offset + 3 * nSides + 3 );
+      glVertex3dv( vertex + offset + 3 * nSides + 3 );
+      glNormal3dv( normal + offset + 3 * nSides );
+      glVertex3dv( vertex + offset + 3 * nSides );
     }
+  }
 
-    /*
-     * Finally have the top part drawn...
-     */
-    for( i=0; i<slices; i++ )
-    {
-        float scl = alt / slope;
+  glEnd();
 
-        glBegin( GL_TRIANGLES );
-            glVertex3f( vertices[ (i+0)*2+0 ] * scl, vertices[ (i+0)*2+1 ] * scl, height - alt );
-            glVertex3f( vertices[ (i+1)*2+0 ] * scl, vertices[ (i+1)*2+1 ] * scl, height - alt );
-            glVertex3f( 0, 0, height );
-        glEnd();
-    }
+  free ( vertex ) ;
+  free ( normal ) ;
+  glPopMatrix();
 }
 
 /*
  *
  */
-void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
+void FGAPIENTRY glutWireDodecahedron( void )
 {
-    glutWireSphere( dOuterRadius, 5, 5 );
+  /* 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 )
+   * where x = 0.61803398875 and z = 1.61803398875.
+   */
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.0,  0.525731112119,  0.850650808354 ) ; glVertex3d (  0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( -0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d (  0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.0,  0.525731112119, -0.850650808354 ) ; glVertex3d (  0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d (  0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.0, -0.525731112119,  0.850650808354 ) ; glVertex3d (  0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d (  0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.0, -0.525731112119, -0.850650808354 ) ; glVertex3d (  0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( -0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d (  0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.850650808354,  0.0,  0.525731112119 ) ; glVertex3d (  0.61803398875,  0.0,  1.61803398875 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d (  1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d (  1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d ( -0.850650808354,  0.0,  0.525731112119 ) ; glVertex3d ( -0.61803398875,  0.0,  1.61803398875 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.850650808354,  0.0, -0.525731112119 ) ; glVertex3d (  0.61803398875,  0.0, -1.61803398875 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d (  1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d (  1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d ( -0.850650808354,  0.0, -0.525731112119 ) ; glVertex3d ( -0.61803398875,  0.0, -1.61803398875 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.525731112119,  0.850650808354,  0.0 ) ; glVertex3d (  1.61803398875,  0.61803398875,  0.0 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d ( 0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d ( 0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d (  0.525731112119, -0.850650808354,  0.0 ) ; glVertex3d (  1.61803398875, -0.61803398875,  0.0 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d ( 0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d ( 0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d ( -0.525731112119,  0.850650808354,  0.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875,  0.0 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( 0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d ( 0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_LINE_LOOP ) ;
+  glNormal3d ( -0.525731112119, -0.850650808354,  0.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875,  0.0 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( 0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d ( 0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
 }
 
 /*
  *
  */
-void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
+void FGAPIENTRY glutSolidDodecahedron( void )
 {
-    glutSolidSphere( dOuterRadius, 5, 5 );
+  /* 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 )
+   * where x = 0.61803398875 and z = 1.61803398875.
+   */
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.0,  0.525731112119,  0.850650808354 ) ; glVertex3d (  0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( -0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d (  0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.0,  0.525731112119, -0.850650808354 ) ; glVertex3d (  0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d (  0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.0, -0.525731112119,  0.850650808354 ) ; glVertex3d (  0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d (  0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0,  1.61803398875 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.0, -0.525731112119, -0.850650808354 ) ; glVertex3d (  0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( -0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d (  0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.850650808354,  0.0,  0.525731112119 ) ; glVertex3d (  0.61803398875,  0.0,  1.61803398875 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d (  1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d (  1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d ( -0.850650808354,  0.0,  0.525731112119 ) ; glVertex3d ( -0.61803398875,  0.0,  1.61803398875 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.850650808354,  0.0, -0.525731112119 ) ; glVertex3d (  0.61803398875,  0.0, -1.61803398875 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d (  1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d (  1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d ( -0.850650808354,  0.0, -0.525731112119 ) ; glVertex3d ( -0.61803398875,  0.0, -1.61803398875 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875, 0.0 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.525731112119,  0.850650808354,  0.0 ) ; glVertex3d (  1.61803398875,  0.61803398875,  0.0 ) ; glVertex3d (  1.0,  1.0, -1.0 ) ; glVertex3d ( 0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d ( 0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d (  1.0,  1.0,  1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d (  0.525731112119, -0.850650808354,  0.0 ) ; glVertex3d (  1.61803398875, -0.61803398875,  0.0 ) ; glVertex3d (  1.0, -1.0,  1.0 ) ; glVertex3d ( 0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d ( 0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d (  1.0, -1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d ( -0.525731112119,  0.850650808354,  0.0 ) ; glVertex3d ( -1.61803398875,  0.61803398875,  0.0 ) ; glVertex3d ( -1.0,  1.0,  1.0 ) ; glVertex3d ( 0.0,  1.61803398875,  0.61803398875 ) ; glVertex3d ( 0.0,  1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0,  1.0, -1.0 ) ;
+  glEnd () ;
+  glBegin ( GL_POLYGON ) ;
+  glNormal3d ( -0.525731112119, -0.850650808354,  0.0 ) ; glVertex3d ( -1.61803398875, -0.61803398875,  0.0 ) ; glVertex3d ( -1.0, -1.0, -1.0 ) ; glVertex3d ( 0.0, -1.61803398875, -0.61803398875 ) ; glVertex3d ( 0.0, -1.61803398875,  0.61803398875 ) ; glVertex3d ( -1.0, -1.0,  1.0 ) ;
+  glEnd () ;
 }
 
 /*
  *
  */
-void FGAPIENTRY glutWireDodecahedron( void )
+void FGAPIENTRY glutWireOctahedron( void )
 {
-    glutWireSphere( 1.0, 5, 5 );
+#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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+  glEnd();
+#undef RADIUS
 }
 
 /*
  *
  */
-void FGAPIENTRY glutSolidDodecahedron( void )
+void FGAPIENTRY glutSolidOctahedron( void )
 {
-    glutSolidSphere( 1.0, 5, 5 );
+#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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+    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 );
+  glEnd();
+#undef RADIUS
 }
 
 /*
  *
  */
-void FGAPIENTRY glutWireOctahedron( void )
+void FGAPIENTRY glutWireTetrahedron( void )
 {
-    glutWireSphere( 1.0, 5, 5 );
+  /* Magic Numbers:  r0 = ( 1, 0, 0 )
+   *                 r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
+   *                 r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
+   *                 r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
+   * |r0| = |r1| = |r2| = |r3| = 1
+   * Distance between any two points is 2 sqrt(6) / 3
+   *
+   * Normals:  The unit normals are simply the negative of the coordinates of the point not on the surface.
+   */
+
+  double r0[3] = {             1.0,             0.0,             0.0 } ;
+  double r1[3] = { -0.333333333333,  0.942809041582,             0.0 } ;
+  double r2[3] = { -0.333333333333, -0.471404520791,  0.816496580928 } ;
+  double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
+
+  glBegin( GL_LINE_LOOP ) ;
+    glNormal3d (           -1.0,             0.0,             0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
+    glNormal3d ( 0.333333333333, -0.942809041582,             0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
+    glNormal3d ( 0.333333333333,  0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
+    glNormal3d ( 0.333333333333,  0.471404520791,  0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
+  glEnd() ;
 }
 
 /*
  *
  */
-void FGAPIENTRY glutSolidOctahedron( void )
+void FGAPIENTRY glutSolidTetrahedron( void )
 {
-    glutSolidSphere( 1.0, 5, 5 );
+  /* Magic Numbers:  r0 = ( 1, 0, 0 )
+   *                 r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
+   *                 r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
+   *                 r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
+   * |r0| = |r1| = |r2| = |r3| = 1
+   * Distance between any two points is 2 sqrt(6) / 3
+   *
+   * Normals:  The unit normals are simply the negative of the coordinates of the point not on the surface.
+   */
+
+  double r0[3] = {             1.0,             0.0,             0.0 } ;
+  double r1[3] = { -0.333333333333,  0.942809041582,             0.0 } ;
+  double r2[3] = { -0.333333333333, -0.471404520791,  0.816496580928 } ;
+  double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
+
+  glBegin( GL_TRIANGLES ) ;
+    glNormal3d (           -1.0,             0.0,             0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
+    glNormal3d ( 0.333333333333, -0.942809041582,             0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
+    glNormal3d ( 0.333333333333,  0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
+    glNormal3d ( 0.333333333333,  0.471404520791,  0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
+  glEnd() ;
 }
 
 /*
  *
  */
-void FGAPIENTRY glutWireTetrahedron( 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 } } ;
+
+void FGAPIENTRY glutWireIcosahedron( void )
 {
-    glutWireSphere( 1.0, 5, 5 );
+  int i ;
+  for ( i = 0; i < 20; i++ )
+  {
+    double normal[3] ;
+    normal[0] = ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) - ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) ;
+    normal[1] = ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) - ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) ;
+    normal[2] = ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) - ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) ;
+    glBegin ( GL_LINE_LOOP ) ;
+      glNormal3dv ( normal ) ;
+      glVertex3dv ( icos_r[icos_v[i][0]] ) ;
+      glVertex3dv ( icos_r[icos_v[i][1]] ) ;
+      glVertex3dv ( icos_r[icos_v[i][2]] ) ;
+    glEnd () ;
+  }
 }
 
 /*
  *
  */
-void FGAPIENTRY glutSolidTetrahedron( void )
+void FGAPIENTRY glutSolidIcosahedron( void )
 {
-    glutSolidSphere( 1.0, 5, 5 );
+  int i ;
+
+  glBegin ( GL_TRIANGLES ) ;
+  for ( i = 0; i < 20; i++ )
+  {
+    double normal[3] ;
+    normal[0] = ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) - ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) ;
+    normal[1] = ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) - ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) ;
+    normal[2] = ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) - ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) ;
+      glNormal3dv ( normal ) ;
+      glVertex3dv ( icos_r[icos_v[i][0]] ) ;
+      glVertex3dv ( icos_r[icos_v[i][1]] ) ;
+      glVertex3dv ( icos_r[icos_v[i][2]] ) ;
+  }
+
+  glEnd () ;
 }
 
 /*
  *
  */
-void FGAPIENTRY glutWireIcosahedron( 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 }
+  } ;
+
+void FGAPIENTRY glutWireRhombicDodecahedron( void )
 {
-    glutWireSphere( 1.0, 5, 5 );
+  int i ;
+  for ( i = 0; i < 12; i++ )
+  {
+    glBegin ( GL_LINE_LOOP ) ;
+      glNormal3dv ( rdod_n[i] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
+    glEnd () ;
+  }
 }
 
 /*
  *
  */
-void FGAPIENTRY glutSolidIcosahedron( void )
+void FGAPIENTRY glutSolidRhombicDodecahedron( void )
 {
-    glutSolidSphere( 1.0, 5, 5 );
+  int i ;
+
+  glBegin ( GL_QUADS ) ;
+  for ( i = 0; i < 12; i++ )
+  {
+      glNormal3dv ( rdod_n[i] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
+      glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
+  }
+
+  glEnd () ;
 }
 
+#define NUM_FACES     4
+
+static GLdouble tetrahedron_v[4][3] =  /* Vertices */
+{
+  { -0.5, -0.288675134595, -0.144337567297 },
+  {  0.5, -0.288675134595, -0.144337567297 },
+  {  0.0,  0.577350269189, -0.144337567297 },
+  {  0.0,  0.0,             0.672159013631 }
+} ;
+
+static GLint tetrahedron_i[4][3] =  /* Vertex indices */
+{
+  { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 1, 3, 2 }
+} ;
+
+static GLdouble tetrahedron_n[4][3] =  /* Normals */
+{
+  {  0.0,             0.0,            -1.0 },
+  { -0.816496580928,  0.471404520791,  0.333333333333 },
+  {  0.0,            -0.942809041582,  0.333333333333 },
+  {  0.816496580928,  0.471404520791,  0.333333333333 }
+} ;
+
+void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
+{
+  int i, j ;
+
+  if ( num_levels == 0 )
+  {
+
+    for ( i = 0 ; i < NUM_FACES ; i++ )
+    {
+      glBegin ( GL_LINE_LOOP ) ;
+      glNormal3dv ( tetrahedron_n[i] ) ;
+      for ( j = 0; j < 3; j++ )
+      {
+        double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
+        double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
+        double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
+        glVertex3d ( x, y, z ) ;
+      }
+
+      glEnd () ;
+    }
+  }
+  else
+  {
+    GLdouble local_offset[3] ;  /* Use a local variable to avoid buildup of roundoff errors */
+    num_levels -- ;
+    scale /= 2.0 ;
+    local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
+    local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
+    local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
+    glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[0] += scale ;
+    glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[0] -= 0.5            * scale ;
+    local_offset[1] += 0.866025403784 * scale ;
+    glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[1] -= 0.577350269189 * scale ;
+    local_offset[2] += 0.816496580928 * scale ;
+    glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
+  }
+}
+
+void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
+{
+  int i, j ;
+
+  if ( num_levels == 0 )
+  {
+    glBegin ( GL_TRIANGLES ) ;
+
+    for ( i = 0 ; i < NUM_FACES ; i++ )
+    {
+      glNormal3dv ( tetrahedron_n[i] ) ;
+      for ( j = 0; j < 3; j++ )
+      {
+        double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
+        double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
+        double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
+        glVertex3d ( x, y, z ) ;
+      }
+    }
+
+    glEnd () ;
+  }
+  else
+  {
+    GLdouble local_offset[3] ;  /* Use a local variable to avoid buildup of roundoff errors */
+    num_levels -- ;
+    scale /= 2.0 ;
+    local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
+    local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
+    local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
+    glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[0] += scale ;
+    glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[0] -= 0.5            * scale ;
+    local_offset[1] += 0.866025403784 * scale ;
+    glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
+    local_offset[1] -= 0.577350269189 * scale ;
+    local_offset[2] += 0.816496580928 * scale ;
+    glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
+  }
+}
+
+#undef NUM_FACES
+
 /*** END OF FILE ***/