Make "gcc -Wall -pedantic -Werror" happy.
[freeglut] / src / freeglut_geometry.c
1 /*
2  * freeglut_geometry.c
3  *
4  * Freeglut geometry rendering methods.
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Creation date: Fri Dec 3 1999
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
34
35 /*
36  * TODO BEFORE THE STABLE RELEASE:
37  *
38  * Following functions have been contributed by Andreas Umbach.
39  *
40  *      glutWireCube()          -- looks OK
41  *      glutSolidCube()         -- OK
42  *
43  * Those functions have been implemented by John Fay.
44  *
45  *      glutWireTorus()         -- looks OK
46  *      glutSolidTorus()        -- looks OK
47  *      glutWireDodecahedron()  -- looks OK
48  *      glutSolidDodecahedron() -- looks OK
49  *      glutWireOctahedron()    -- looks OK
50  *      glutSolidOctahedron()   -- looks OK
51  *      glutWireTetrahedron()   -- looks OK
52  *      glutSolidTetrahedron()  -- looks OK
53  *      glutWireIcosahedron()   -- looks OK
54  *      glutSolidIcosahedron()  -- looks OK
55  *
56  *  The Following functions have been updated by Nigel Stewart, based
57  *  on FreeGLUT 2.0.0 implementations:
58  *
59  *      glutWireSphere()        -- looks OK
60  *      glutSolidSphere()       -- looks OK
61  *      glutWireCone()          -- looks OK
62  *      glutSolidCone()         -- looks OK
63  */
64
65
66 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
67
68 /*
69  * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
70  */
71 void FGAPIENTRY glutWireCube( GLdouble dSize )
72 {
73     double size = dSize * 0.5;
74
75 #   define V(a,b,c) glVertex3d( a size, b size, c size );
76 #   define N(a,b,c) glNormal3d( a, b, c );
77
78     /* PWO: I dared to convert the code to use macros... */
79     glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
80     glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
81     glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
82     glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
83     glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
84     glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
85
86 #   undef V
87 #   undef N
88 }
89
90 /*
91  * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
92  */
93 void FGAPIENTRY glutSolidCube( GLdouble dSize )
94 {
95     double size = dSize * 0.5;
96
97 #   define V(a,b,c) glVertex3d( a size, b size, c size );
98 #   define N(a,b,c) glNormal3d( a, b, c );
99
100     /* PWO: Again, I dared to convert the code to use macros... */
101     glBegin( GL_QUADS );
102         N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+);
103         N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+);
104         N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+);
105         N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-);
106         N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+);
107         N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-);
108     glEnd();
109
110 #   undef V
111 #   undef N
112 }
113
114 /*
115  * Compute lookup table of cos and sin values forming a cirle
116  *
117  * Notes:
118  *    It is the responsibility of the caller to free these tables
119  *    The size of the table is (n+1) to form a connected loop
120  *    The last entry is exactly the same as the first
121  *    The sign of n can be flipped to get the reverse loop
122  */
123
124 static void fghCircleTable(double **sint,double **cost,const int n)
125 {
126     int i;
127
128     /* Table size, the sign of n flips the circle direction */
129
130     const int size = abs(n);
131
132     /* Determine the angle between samples */
133
134     const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
135
136     /* Allocate memory for n samples, plus duplicate of first entry at the end */
137
138     *sint = (double *) calloc(sizeof(double), size+1);
139     *cost = (double *) calloc(sizeof(double), size+1);
140
141     /* Bail out if memory allocation fails, fgError never returns */
142
143     if (!(*sint) || !(*cost))
144     {
145         free(*sint);
146         free(*cost);
147         fgError("Failed to allocate memory in fghCircleTable");
148     }
149
150     /* Compute cos and sin around the circle */
151
152     (*sint)[0] = 0.0;
153     (*cost)[0] = 1.0;
154
155     for (i=1; i<size; i++)
156     {
157         (*sint)[i] = sin(angle*i);
158         (*cost)[i] = cos(angle*i);
159     }
160
161     /* Last sample is duplicate of the first */
162
163     (*sint)[size] = (*sint)[0];
164     (*cost)[size] = (*cost)[0];
165 }
166
167 /*
168  * Draws a solid sphere
169  */
170 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
171 {
172     int i,j;
173
174     /* Adjust z and radius as stacks are drawn. */
175
176     double z0,z1;
177     double r0,r1;
178
179     /* Pre-computed circle */
180
181     double *sint1,*cost1;
182     double *sint2,*cost2;
183     fghCircleTable(&sint1,&cost1,-slices);
184     fghCircleTable(&sint2,&cost2,stacks*2);
185
186     /* The top stack is covered with a triangle fan */
187
188     z0 = 1.0;
189     z1 = cost2[(stacks>0)?1:0];
190     r0 = 0.0;
191     r1 = sint2[(stacks>0)?1:0];
192
193     glBegin(GL_TRIANGLE_FAN);
194
195         glNormal3d(0,0,1);
196         glVertex3d(0,0,radius);
197
198         for (j=slices; j>=0; j--)
199         {
200             glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
201             glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
202         }
203
204     glEnd();
205
206     /* Cover each stack with a quad strip, except the top and bottom stacks */
207
208     for( i=1; i<stacks-1; i++ )
209     {
210         z0 = z1; z1 = cost2[i+1];
211         r0 = r1; r1 = sint2[i+1];
212
213         glBegin(GL_QUAD_STRIP);
214
215             for(j=0; j<=slices; j++)
216             {
217                 glNormal3d(cost1[j]*r1,        sint1[j]*r1,        z1       );
218                 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
219                 glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
220                 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
221             }
222
223         glEnd();
224     }
225
226     /* The bottom stack is covered with a triangle fan */
227
228     z0 = z1;
229     r0 = r1;
230
231     glBegin(GL_TRIANGLE_FAN);
232
233         glNormal3d(0,0,-1);
234         glVertex3d(0,0,-radius);
235
236         for (j=0; j<=slices; j++)
237         {
238             glNormal3d(cost1[j]*r0,        sint1[j]*r0,        z0       );
239             glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
240         }
241
242     glEnd();
243
244     /* Release sin and cos tables */
245
246     free(sint1);
247     free(cost1);
248     free(sint2);
249     free(cost2);
250 }
251
252 /*
253  * Draws a wire sphere
254  */
255 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
256 {
257     int i,j;
258
259     /* Adjust z and radius as stacks and slices are drawn. */
260
261     double r;
262     double x,y,z;
263
264     /* Pre-computed circle */
265
266     double *sint1,*cost1;
267     double *sint2,*cost2;
268     fghCircleTable(&sint1,&cost1,-slices  );
269     fghCircleTable(&sint2,&cost2, stacks*2);
270
271     /* Draw a line loop for each stack */
272
273     for (i=1; i<stacks; i++)
274     {
275         z = cost2[i];
276         r = sint2[i];
277
278         glBegin(GL_LINE_LOOP);
279
280             for(j=0; j<=slices; j++)
281             {
282                 x = cost1[j];
283                 y = sint1[j];
284
285                 glNormal3d(x,y,z);
286                 glVertex3d(x*r*radius,y*r*radius,z*radius);
287             }
288
289         glEnd();
290     }
291
292     /* Draw a line loop for each slice */
293
294     for (i=0; i<slices; i++)
295     {
296         glBegin(GL_LINE_STRIP);
297
298             for(j=0; j<=stacks; j++)
299             {
300                 x = cost1[i]*sint2[j];
301                 y = sint1[i]*sint2[j];
302                 z = cost2[j];
303
304                 glNormal3d(x,y,z);
305                 glVertex3d(x*radius,y*radius,z*radius);
306             }
307
308         glEnd();
309     }
310
311     /* Release sin and cos tables */
312
313     free(sint1);
314     free(cost1);
315     free(sint2);
316     free(cost2);
317 }
318
319 /*
320  * Draws a solid cone
321  */
322 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
323 {
324     int i,j;
325
326     /* Step in z and radius as stacks are drawn. */
327
328     double z0,z1;
329     double r0,r1;
330
331     const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
332     const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
333
334     /* Scaling factors for vertex normals */
335
336     const double cosn = ( height / sqrt ( height * height + base * base ));
337     const double sinn = ( base   / sqrt ( height * height + base * base ));
338
339     /* Pre-computed circle */
340
341     double *sint,*cost;
342     fghCircleTable(&sint,&cost,-slices);
343
344     /* Cover the circular base with a triangle fan... */
345
346     z0 = 0.0;
347     z1 = zStep;
348
349     r0 = base;
350     r1 = r0 - rStep;
351
352     glBegin(GL_TRIANGLE_FAN);
353
354         glNormal3d(0.0,0.0,-1.0);
355         glVertex3d(0.0,0.0, z0 );
356
357         for (j=0; j<=slices; j++)
358             glVertex3d(cost[j]*r0, sint[j]*r0, z0);
359
360     glEnd();
361
362     /* Cover each stack with a quad strip, except the top stack */
363
364     for( i=0; i<stacks-1; i++ )
365     {
366         glBegin(GL_QUAD_STRIP);
367
368             for(j=0; j<=slices; j++)
369             {
370                 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
371                 glVertex3d(cost[j]*r0,   sint[j]*r0,   z0  );
372                 glVertex3d(cost[j]*r1,   sint[j]*r1,   z1  );
373             }
374
375             z0 = z1; z1 += zStep;
376             r0 = r1; r1 -= rStep;
377
378         glEnd();
379     }
380
381     /* The top stack is covered with individual triangles */
382
383     glBegin(GL_TRIANGLES);
384
385         glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
386
387         for (j=0; j<slices; j++)
388         {
389             glVertex3d(cost[j+0]*r0,   sint[j+0]*r0,   z0    );
390             glVertex3d(0,              0,              height);
391             glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn  );
392             glVertex3d(cost[j+1]*r0,   sint[j+1]*r0,   z0    );
393         }
394
395     glEnd();
396
397     /* Release sin and cos tables */
398
399     free(sint);
400     free(cost);
401 }
402
403 /*
404  * Draws a wire cone
405  */
406 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
407 {
408     int i,j;
409
410     /* Step in z and radius as stacks are drawn. */
411
412     double z = 0.0;
413     double r = base;
414
415     const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
416     const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
417
418     /* Scaling factors for vertex normals */
419
420     const double cosn = ( height / sqrt ( height * height + base * base ));
421     const double sinn = ( base   / sqrt ( height * height + base * base ));
422
423     /* Pre-computed circle */
424
425     double *sint,*cost;
426     fghCircleTable(&sint,&cost,-slices);
427
428     /* Draw the stacks... */
429
430     for (i=0; i<stacks; i++)
431     {
432         glBegin(GL_LINE_LOOP);
433
434             for( j=0; j<slices; j++ )
435             {
436                 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
437                 glVertex3d(cost[j]*r,    sint[j]*r,    z   );
438             }
439
440         glEnd();
441
442         z += zStep;
443         r -= rStep;
444     }
445
446     /* Draw the slices */
447
448     r = base;
449
450     glBegin(GL_LINES);
451
452         for (j=0; j<slices; j++)
453         {
454             glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn  );
455             glVertex3d(cost[j]*r,    sint[j]*r,    0.0   );
456             glVertex3d(0.0,          0.0,          height);
457         }
458
459     glEnd();
460
461     /* Release sin and cos tables */
462
463     free(sint);
464     free(cost);
465 }
466
467
468 /*
469  * Draws a solid cylinder
470  */
471 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
472 {
473     int i,j;
474
475     /* Step in z and radius as stacks are drawn. */
476
477     double z0,z1;
478     const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
479
480     /* Pre-computed circle */
481
482     double *sint,*cost;
483     fghCircleTable(&sint,&cost,-slices);
484
485     /* Cover the base and top */
486
487     glBegin(GL_TRIANGLE_FAN);
488         glNormal3d(0.0, 0.0, -1.0 );
489         glVertex3d(0.0, 0.0,  0.0 );
490         for (j=0; j<=slices; j++)
491           glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
492     glEnd();
493
494     glBegin(GL_TRIANGLE_FAN);
495         glNormal3d(0.0, 0.0, 1.0   );
496         glVertex3d(0.0, 0.0, height);
497         for (j=slices; j>=0; j--)
498           glVertex3d(cost[j]*radius, sint[j]*radius, height);
499     glEnd();
500
501     /* Do the stacks */
502
503     z0 = 0.0;
504     z1 = zStep;
505
506     for (i=1; i<=stacks; i++)
507     {
508         if (i==stacks)
509             z1 = height;
510
511         glBegin(GL_QUAD_STRIP);
512             for (j=0; j<=slices; j++ )
513             {
514                 glNormal3d(cost[j],        sint[j],        0.0 );
515                 glVertex3d(cost[j]*radius, sint[j]*radius, z0  );
516                 glVertex3d(cost[j]*radius, sint[j]*radius, z1  );
517             }
518         glEnd();
519
520         z0 = z1; z1 += zStep;
521     }
522
523     /* Release sin and cos tables */
524
525     free(sint);
526     free(cost);
527 }
528
529 /*
530  * Draws a wire cylinder
531  */
532 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
533 {
534     int i,j;
535
536     /* Step in z and radius as stacks are drawn. */
537
538           double z = 0.0;
539     const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
540
541     /* Pre-computed circle */
542
543     double *sint,*cost;
544     fghCircleTable(&sint,&cost,-slices);
545
546     /* Draw the stacks... */
547
548     for (i=0; i<=stacks; i++)
549     {
550         if (i==stacks)
551             z = height;
552
553         glBegin(GL_LINE_LOOP);
554
555             for( j=0; j<slices; j++ )
556             {
557                 glNormal3d(cost[j],        sint[j],        0.0);
558                 glVertex3d(cost[j]*radius, sint[j]*radius, z  );
559             }
560
561         glEnd();
562
563         z += zStep;
564     }
565
566     /* Draw the slices */
567
568     glBegin(GL_LINES);
569
570         for (j=0; j<slices; j++)
571         {
572             glNormal3d(cost[j],        sint[j],        0.0   );
573             glVertex3d(cost[j]*radius, sint[j]*radius, 0.0   );
574             glVertex3d(cost[j]*radius, sint[j]*radius, height);
575         }
576
577     glEnd();
578
579     /* Release sin and cos tables */
580
581     free(sint);
582     free(cost);
583 }
584
585 /*
586  * Draws a wire torus
587  */
588 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
589 {
590   double  iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
591   double *vertex, *normal;
592   int    i, j;
593   double spsi, cpsi, sphi, cphi ;
594   if ( nSides < 1 ) nSides = 1;
595   if ( nRings < 1 ) nRings = 1;
596
597   /* Allocate the vertices array */
598   vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
599   normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
600
601   glPushMatrix();
602
603   dpsi =  2.0 * M_PI / (double)nRings ;
604   dphi = -2.0 * M_PI / (double)nSides ;
605   psi  = 0.0;
606
607   for( j=0; j<nRings; j++ )
608   {
609     cpsi = cos ( psi ) ;
610     spsi = sin ( psi ) ;
611     phi = 0.0;
612
613     for( i=0; i<nSides; i++ )
614     {
615       int offset = 3 * ( j * nSides + i ) ;
616       cphi = cos ( phi ) ;
617       sphi = sin ( phi ) ;
618       *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
619       *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
620       *(vertex + offset + 2) =                    sphi * iradius  ;
621       *(normal + offset + 0) = cpsi * cphi ;
622       *(normal + offset + 1) = spsi * cphi ;
623       *(normal + offset + 2) =        sphi ;
624       phi += dphi;
625     }
626
627     psi += dpsi;
628   }
629
630   for( i=0; i<nSides; i++ )
631   {
632     glBegin( GL_LINE_LOOP );
633
634     for( j=0; j<nRings; j++ )
635     {
636       int offset = 3 * ( j * nSides + i ) ;
637       glNormal3dv( normal + offset );
638       glVertex3dv( vertex + offset );
639     }
640
641     glEnd();
642   }
643
644   for( j=0; j<nRings; j++ )
645   {
646     glBegin(GL_LINE_LOOP);
647
648     for( i=0; i<nSides; i++ )
649     {
650       int offset = 3 * ( j * nSides + i ) ;
651       glNormal3dv( normal + offset );
652       glVertex3dv( vertex + offset );
653     }
654
655     glEnd();
656   }
657
658   free ( vertex ) ;
659   free ( normal ) ;
660   glPopMatrix();
661 }
662
663 /*
664  * Draws a solid torus
665  */
666 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
667 {
668   double  iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
669   double *vertex, *normal;
670   int    i, j;
671   double spsi, cpsi, sphi, cphi ;
672   if ( nSides < 1 ) nSides = 1;
673   if ( nRings < 1 ) nRings = 1;
674
675   /* Increment the number of sides and rings to allow for one more point than surface */
676   nSides ++ ;
677   nRings ++ ;
678
679   /* Allocate the vertices array */
680   vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
681   normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
682
683   glPushMatrix();
684
685   dpsi =  2.0 * M_PI / (double)(nRings - 1) ;
686   dphi = -2.0 * M_PI / (double)(nSides - 1) ;
687   psi  = 0.0;
688
689   for( j=0; j<nRings; j++ )
690   {
691     cpsi = cos ( psi ) ;
692     spsi = sin ( psi ) ;
693     phi = 0.0;
694
695     for( i=0; i<nSides; i++ )
696     {
697       int offset = 3 * ( j * nSides + i ) ;
698       cphi = cos ( phi ) ;
699       sphi = sin ( phi ) ;
700       *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
701       *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
702       *(vertex + offset + 2) =                    sphi * iradius  ;
703       *(normal + offset + 0) = cpsi * cphi ;
704       *(normal + offset + 1) = spsi * cphi ;
705       *(normal + offset + 2) =        sphi ;
706       phi += dphi;
707     }
708
709     psi += dpsi;
710   }
711
712     glBegin( GL_QUADS );
713   for( i=0; i<nSides-1; i++ )
714   {
715     for( j=0; j<nRings-1; j++ )
716     {
717       int offset = 3 * ( j * nSides + i ) ;
718       glNormal3dv( normal + offset );
719       glVertex3dv( vertex + offset );
720       glNormal3dv( normal + offset + 3 );
721       glVertex3dv( vertex + offset + 3 );
722       glNormal3dv( normal + offset + 3 * nSides + 3 );
723       glVertex3dv( vertex + offset + 3 * nSides + 3 );
724       glNormal3dv( normal + offset + 3 * nSides );
725       glVertex3dv( vertex + offset + 3 * nSides );
726     }
727   }
728
729   glEnd();
730
731   free ( vertex ) ;
732   free ( normal ) ;
733   glPopMatrix();
734 }
735
736 /*
737  *
738  */
739 void FGAPIENTRY glutWireDodecahedron( void )
740 {
741   /* Magic Numbers:  It is possible to create a dodecahedron by attaching two pentagons to each face of
742    * of a cube.  The coordinates of the points are:
743    *   (+-x,0, z); (+-1, 1, 1); (0, z, x )
744    * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2  or
745    *       x = 0.61803398875 and z = 1.61803398875.
746    */
747   glBegin ( GL_LINE_LOOP ) ;
748   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 ) ;
749   glEnd () ;
750   glBegin ( GL_LINE_LOOP ) ;
751   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 ) ;
752   glEnd () ;
753   glBegin ( GL_LINE_LOOP ) ;
754   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 ) ;
755   glEnd () ;
756   glBegin ( GL_LINE_LOOP ) ;
757   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 ) ;
758   glEnd () ;
759
760   glBegin ( GL_LINE_LOOP ) ;
761   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 ) ;
762   glEnd () ;
763   glBegin ( GL_LINE_LOOP ) ;
764   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 ) ;
765   glEnd () ;
766   glBegin ( GL_LINE_LOOP ) ;
767   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 ) ;
768   glEnd () ;
769   glBegin ( GL_LINE_LOOP ) ;
770   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 ) ;
771   glEnd () ;
772
773   glBegin ( GL_LINE_LOOP ) ;
774   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 ) ;
775   glEnd () ;
776   glBegin ( GL_LINE_LOOP ) ;
777   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 ) ;
778   glEnd () ;
779   glBegin ( GL_LINE_LOOP ) ;
780   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 ) ;
781   glEnd () ;
782   glBegin ( GL_LINE_LOOP ) ;
783   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 ) ;
784   glEnd () ;
785 }
786
787 /*
788  *
789  */
790 void FGAPIENTRY glutSolidDodecahedron( void )
791 {
792   /* Magic Numbers:  It is possible to create a dodecahedron by attaching two pentagons to each face of
793    * of a cube.  The coordinates of the points are:
794    *   (+-x,0, z); (+-1, 1, 1); (0, z, x )
795    * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
796    *       x = 0.61803398875 and z = 1.61803398875.
797    */
798   glBegin ( GL_POLYGON ) ;
799   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 ) ;
800   glEnd () ;
801   glBegin ( GL_POLYGON ) ;
802   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 ) ;
803   glEnd () ;
804   glBegin ( GL_POLYGON ) ;
805   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 ) ;
806   glEnd () ;
807   glBegin ( GL_POLYGON ) ;
808   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 ) ;
809   glEnd () ;
810
811   glBegin ( GL_POLYGON ) ;
812   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 ) ;
813   glEnd () ;
814   glBegin ( GL_POLYGON ) ;
815   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 ) ;
816   glEnd () ;
817   glBegin ( GL_POLYGON ) ;
818   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 ) ;
819   glEnd () ;
820   glBegin ( GL_POLYGON ) ;
821   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 ) ;
822   glEnd () ;
823
824   glBegin ( GL_POLYGON ) ;
825   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 ) ;
826   glEnd () ;
827   glBegin ( GL_POLYGON ) ;
828   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 ) ;
829   glEnd () ;
830   glBegin ( GL_POLYGON ) ;
831   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 ) ;
832   glEnd () ;
833   glBegin ( GL_POLYGON ) ;
834   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 ) ;
835   glEnd () ;
836 }
837
838 /*
839  *
840  */
841 void FGAPIENTRY glutWireOctahedron( void )
842 {
843 #define RADIUS    1.0f
844   glBegin( GL_LINE_LOOP );
845     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 );
846     glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
847     glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
848     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 );
849     glNormal3d(-0.577350269189, 0.577350269189, 0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
850     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 );
851     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 );
852     glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
853   glEnd();
854 #undef RADIUS
855 }
856
857 /*
858  *
859  */
860 void FGAPIENTRY glutSolidOctahedron( void )
861 {
862 #define RADIUS    1.0f
863   glBegin( GL_TRIANGLES );
864     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 );
865     glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
866     glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
867     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 );
868     glNormal3d(-0.577350269189, 0.577350269189, 0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
869     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 );
870     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 );
871     glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
872   glEnd();
873 #undef RADIUS
874 }
875
876 /* Magic Numbers:  r0 = ( 1, 0, 0 )
877  *                 r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
878  *                 r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
879  *                 r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
880  * |r0| = |r1| = |r2| = |r3| = 1
881  * Distance between any two points is 2 sqrt(6) / 3
882  *
883  * Normals:  The unit normals are simply the negative of the coordinates of the point not on the surface.
884  */
885
886 #define NUM_TETR_FACES     4
887
888 static GLdouble tet_r[4][3] = { {             1.0,             0.0,             0.0 },
889                                 { -0.333333333333,  0.942809041582,             0.0 },
890                                 { -0.333333333333, -0.471404520791,  0.816496580928 },
891                                 { -0.333333333333, -0.471404520791, -0.816496580928 } } ;
892
893 static GLint tet_i[4][3] =  /* Vertex indices */
894 {
895   { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
896 } ;
897
898 /*
899  *
900  */
901 void FGAPIENTRY glutWireTetrahedron( void )
902 {
903   glBegin( GL_LINE_LOOP ) ;
904     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] ) ;
905     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] ) ;
906     glNormal3d ( -tet_r[2][0], -tet_r[2][1], -tet_r[2][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[3] ) ; glVertex3dv ( tet_r[1] ) ;
907     glNormal3d ( -tet_r[3][0], -tet_r[3][1], -tet_r[3][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[1] ) ; glVertex3dv ( tet_r[2] ) ;
908   glEnd() ;
909 }
910
911 /*
912  *
913  */
914 void FGAPIENTRY glutSolidTetrahedron( void )
915 {
916   glBegin( GL_TRIANGLES ) ;
917     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] ) ;
918     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] ) ;
919     glNormal3d ( -tet_r[2][0], -tet_r[2][1], -tet_r[2][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[3] ) ; glVertex3dv ( tet_r[1] ) ;
920     glNormal3d ( -tet_r[3][0], -tet_r[3][1], -tet_r[3][2] ) ; glVertex3dv ( tet_r[0] ) ; glVertex3dv ( tet_r[1] ) ; glVertex3dv ( tet_r[2] ) ;
921   glEnd() ;
922 }
923
924 /*
925  *
926  */
927 double icos_r[12][3] = { { 1.0, 0.0, 0.0 },
928   {  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 },
929   { -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 },
930   { -1.0, 0.0, 0.0 } } ;
931 int icos_v [20][3] = { { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 5 }, { 0, 5, 1 },
932                        { 1, 8, 2 }, { 2, 7, 3 }, { 3, 6, 4 }, { 4, 10, 5 }, { 5, 9, 1 },
933                        { 1, 9, 8 }, { 2, 8, 7 }, { 3, 7, 6 }, { 4, 6, 10 }, { 5, 10, 9 },
934                        { 11, 9, 10 }, { 11, 8, 9 }, { 11, 7, 8 }, { 11, 6, 7 }, { 11, 10, 6 } } ;
935
936 void FGAPIENTRY glutWireIcosahedron( void )
937 {
938   int i ;
939   for ( i = 0; i < 20; i++ )
940   {
941     double normal[3] ;
942     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] ) ;
943     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] ) ;
944     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] ) ;
945     glBegin ( GL_LINE_LOOP ) ;
946       glNormal3dv ( normal ) ;
947       glVertex3dv ( icos_r[icos_v[i][0]] ) ;
948       glVertex3dv ( icos_r[icos_v[i][1]] ) ;
949       glVertex3dv ( icos_r[icos_v[i][2]] ) ;
950     glEnd () ;
951   }
952 }
953
954 /*
955  *
956  */
957 void FGAPIENTRY glutSolidIcosahedron( void )
958 {
959   int i ;
960
961   glBegin ( GL_TRIANGLES ) ;
962   for ( i = 0; i < 20; i++ )
963   {
964     double normal[3] ;
965     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] ) ;
966     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] ) ;
967     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] ) ;
968       glNormal3dv ( normal ) ;
969       glVertex3dv ( icos_r[icos_v[i][0]] ) ;
970       glVertex3dv ( icos_r[icos_v[i][1]] ) ;
971       glVertex3dv ( icos_r[icos_v[i][2]] ) ;
972   }
973
974   glEnd () ;
975 }
976
977 /*
978  *
979  */
980 double rdod_r[14][3] = { { 0.0, 0.0, 1.0 },
981   {  0.707106781187,  0.000000000000,  0.5 }, {  0.000000000000,  0.707106781187,  0.5 }, { -0.707106781187,  0.000000000000,  0.5 }, {  0.000000000000, -0.707106781187,  0.5 },
982   {  0.707106781187,  0.707106781187,  0.0 }, { -0.707106781187,  0.707106781187,  0.0 }, { -0.707106781187, -0.707106781187,  0.0 }, {  0.707106781187, -0.707106781187,  0.0 },
983   {  0.707106781187,  0.000000000000, -0.5 }, {  0.000000000000,  0.707106781187, -0.5 }, { -0.707106781187,  0.000000000000, -0.5 }, {  0.000000000000, -0.707106781187, -0.5 },
984   {  0.0, 0.0, -1.0 } } ;
985 int rdod_v [12][4] = { { 0,  1,  5,  2 }, { 0,  2,  6,  3 }, { 0,  3,  7,  4 }, { 0,  4,  8, 1 },
986                        { 5, 10,  6,  2 }, { 6, 11,  7,  3 }, { 7, 12,  8,  4 }, { 8,  9,  5, 1 },
987                        { 5,  9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ;
988 double rdod_n[12][3] = {
989   {  0.353553390594,  0.353553390594,  0.5 }, { -0.353553390594,  0.353553390594,  0.5 }, { -0.353553390594, -0.353553390594,  0.5 }, {  0.353553390594, -0.353553390594,  0.5 },
990   {  0.000000000000,  1.000000000000,  0.0 }, { -1.000000000000,  0.000000000000,  0.0 }, {  0.000000000000, -1.000000000000,  0.0 }, {  1.000000000000,  0.000000000000,  0.0 },
991   {  0.353553390594,  0.353553390594, -0.5 }, { -0.353553390594,  0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, {  0.353553390594, -0.353553390594, -0.5 }
992   } ;
993
994 void FGAPIENTRY glutWireRhombicDodecahedron( void )
995 {
996   int i ;
997   for ( i = 0; i < 12; i++ )
998   {
999     glBegin ( GL_LINE_LOOP ) ;
1000       glNormal3dv ( rdod_n[i] ) ;
1001       glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1002       glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1003       glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1004       glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1005     glEnd () ;
1006   }
1007 }
1008
1009 /*
1010  *
1011  */
1012 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1013 {
1014   int i ;
1015
1016   glBegin ( GL_QUADS ) ;
1017   for ( i = 0; i < 12; i++ )
1018   {
1019       glNormal3dv ( rdod_n[i] ) ;
1020       glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1021       glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1022       glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1023       glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1024   }
1025
1026   glEnd () ;
1027 }
1028
1029 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1030 {
1031   int i, j ;
1032
1033   if ( num_levels == 0 )
1034   {
1035
1036     for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1037     {
1038       glBegin ( GL_LINE_LOOP ) ;
1039       glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1040       for ( j = 0; j < 3; j++ )
1041       {
1042         double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1043         double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1044         double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1045         glVertex3d ( x, y, z ) ;
1046       }
1047
1048       glEnd () ;
1049     }
1050   }
1051   else
1052   {
1053     GLdouble local_offset[3] ;  /* Use a local variable to avoid buildup of roundoff errors */
1054     num_levels -- ;
1055     scale /= 2.0 ;
1056     for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1057     {
1058       local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1059       local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1060       local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1061       glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1062     }
1063   }
1064 }
1065
1066 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1067 {
1068   int i, j ;
1069
1070   if ( num_levels == 0 )
1071   {
1072     glBegin ( GL_TRIANGLES ) ;
1073
1074     for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1075     {
1076       glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1077       for ( j = 0; j < 3; j++ )
1078       {
1079         double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1080         double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1081         double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1082         glVertex3d ( x, y, z ) ;
1083       }
1084     }
1085
1086     glEnd () ;
1087   }
1088   else
1089   {
1090     GLdouble local_offset[3] ;  /* Use a local variable to avoid buildup of roundoff errors */
1091     num_levels -- ;
1092     scale /= 2.0 ;
1093     for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1094     {
1095       local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1096       local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1097       local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1098       glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1099     }
1100   }
1101 }
1102
1103 /*** END OF FILE ***/