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