4 * Freeglut geometry rendering methods.
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
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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.
28 #include <GL/freeglut.h>
29 #include "fg_internal.h"
32 * TODO BEFORE THE STABLE RELEASE:
36 * Following functions have been contributed by Andreas Umbach.
38 * glutWireCube() -- looks OK
39 * glutSolidCube() -- OK
41 * Those functions have been implemented by John Fay.
43 * glutWireTorus() -- looks OK
44 * glutSolidTorus() -- looks OK
45 * glutWireDodecahedron() -- looks OK
46 * glutSolidDodecahedron() -- looks OK
47 * glutWireOctahedron() -- looks OK
48 * glutSolidOctahedron() -- looks OK
49 * glutWireTetrahedron() -- looks OK
50 * glutSolidTetrahedron() -- looks OK
51 * glutWireIcosahedron() -- looks OK
52 * glutSolidIcosahedron() -- looks OK
54 * The Following functions have been updated by Nigel Stewart, based
55 * on FreeGLUT 2.0.0 implementations:
57 * glutWireSphere() -- looks OK
58 * glutSolidSphere() -- looks OK
59 * glutWireCone() -- looks OK
60 * glutSolidCone() -- looks OK
65 * General function for drawing geometry. As for all geometry we have no
66 * redundancy (or hardly any in the case of cones and cylinders) in terms
67 * of the vertex/normal combinations, we just use glDrawArrays.
68 * useWireMode controls the drawing of solids (false) or wire frame
69 * versions (TRUE) of the geometry you pass
71 static void fghDrawGeometry(GLenum vertexMode, double* vertices, double* normals, GLsizei numVertices, GLboolean useWireMode)
75 glPushAttrib(GL_POLYGON_BIT);
76 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
79 glEnableClientState(GL_VERTEX_ARRAY);
80 glEnableClientState(GL_NORMAL_ARRAY);
82 glVertexPointer(3, GL_DOUBLE, 0, vertices);
83 glNormalPointer(GL_DOUBLE, 0, normals);
84 glDrawArrays(vertexMode,0,numVertices);
86 glDisableClientState(GL_VERTEX_ARRAY);
87 glDisableClientState(GL_NORMAL_ARRAY);
96 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
97 /* -- first the cachable ones -- */
99 /* Magic Numbers: r0 = ( 1, 0, 0 )
100 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
101 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
102 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
103 * |r0| = |r1| = |r2| = |r3| = 1
104 * Distance between any two points is 2 sqrt(6) / 3
106 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
109 /* -- TetraHedron -- */
110 #define TETR_NUM_FACES 4
111 #define TETR_NUM_VERT_PER_FACE 3
113 /* Vertex Coordinates */
114 static GLdouble tet_r[TETR_NUM_FACES][TETR_NUM_VERT_PER_FACE] =
117 { -0.333333333333, 0.942809041582, 0.0 },
118 { -0.333333333333, -0.471404520791, 0.816496580928 },
119 { -0.333333333333, -0.471404520791, -0.816496580928 }
123 static GLubyte tet_i[TETR_NUM_FACES][TETR_NUM_VERT_PER_FACE] =
125 { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
128 static GLubyte tet_n[TETR_NUM_FACES] =
133 /* Cache of input to glDrawArrays */
134 static GLboolean tetrCached = FALSE;
135 static double tetr_verts[TETR_NUM_FACES * TETR_NUM_VERT_PER_FACE * 3];
136 static double tetr_norms[TETR_NUM_FACES * TETR_NUM_VERT_PER_FACE * 3];
138 static void fghTetrahedronCache()
142 * Build array with vertices from vertex coordinates and vertex indices
143 * Do same for normals.
144 * Need to do this because of different normals at shared vertices
145 * (and because normals' coordinates need to be negated).
147 for (p=0; p<TETR_NUM_FACES; p++)
149 for (q=0; q<TETR_NUM_VERT_PER_FACE; q++)
151 int idx = p*TETR_NUM_VERT_PER_FACE*3+q*3;
152 tetr_verts[idx ] = tet_r[tet_i[p][q]][0];
153 tetr_verts[idx+1] = tet_r[tet_i[p][q]][1];
154 tetr_verts[idx+2] = tet_r[tet_i[p][q]][2];
156 tetr_norms[idx ] = -tet_r[tet_n[p]][0];
157 tetr_norms[idx+1] = -tet_r[tet_n[p]][1];
158 tetr_norms[idx+2] = -tet_r[tet_n[p]][2];
163 /* -- Now the various shapes involving circles -- */
165 * Compute lookup table of cos and sin values forming a cirle
168 * It is the responsibility of the caller to free these tables
169 * The size of the table is (n+1) to form a connected loop
170 * The last entry is exactly the same as the first
171 * The sign of n can be flipped to get the reverse loop
173 static void fghCircleTable(double **sint,double **cost,const int n)
177 /* Table size, the sign of n flips the circle direction */
179 const int size = abs(n);
181 /* Determine the angle between samples */
183 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
185 /* Allocate memory for n samples, plus duplicate of first entry at the end */
187 *sint = (double *) calloc(sizeof(double), size+1);
188 *cost = (double *) calloc(sizeof(double), size+1);
190 /* Bail out if memory allocation fails, fgError never returns */
192 if (!(*sint) || !(*cost))
196 fgError("Failed to allocate memory in fghCircleTable");
199 /* Compute cos and sin around the circle */
204 for (i=1; i<size; i++)
206 (*sint)[i] = sin(angle*i);
207 (*cost)[i] = cos(angle*i);
210 /* Last sample is duplicate of the first */
212 (*sint)[size] = (*sint)[0];
213 (*cost)[size] = (*cost)[0];
217 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
219 static void fghTetrahedron( GLboolean useWireMode )
222 fghTetrahedronCache();
224 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE,useWireMode);
228 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
231 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
233 void FGAPIENTRY glutWireCube( GLdouble dSize )
235 double size = dSize * 0.5;
237 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
239 # define V(a,b,c) glVertex3d( a size, b size, c size );
240 # define N(a,b,c) glNormal3d( a, b, c );
242 /* PWO: I dared to convert the code to use macros... */
243 glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
244 glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
245 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
246 glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
247 glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
248 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
255 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
257 void FGAPIENTRY glutSolidCube( GLdouble dSize )
259 double size = dSize * 0.5;
261 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
263 # define V(a,b,c) glVertex3d( a size, b size, c size );
264 # define N(a,b,c) glNormal3d( a, b, c );
266 /* PWO: Again, I dared to convert the code to use macros... */
268 N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+);
269 N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+);
270 N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+);
271 N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-);
272 N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+);
273 N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-);
282 * Draws a solid sphere
284 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
288 /* Adjust z and radius as stacks are drawn. */
293 /* Pre-computed circle */
295 double *sint1,*cost1;
296 double *sint2,*cost2;
298 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
300 fghCircleTable(&sint1,&cost1,-slices);
301 fghCircleTable(&sint2,&cost2,stacks*2);
303 /* The top stack is covered with a triangle fan */
306 z1 = cost2[(stacks>0)?1:0];
308 r1 = sint2[(stacks>0)?1:0];
310 glBegin(GL_TRIANGLE_FAN);
313 glVertex3d(0,0,radius);
315 for (j=slices; j>=0; j--)
317 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
318 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
323 /* Cover each stack with a quad strip, except the top and bottom stacks */
325 for( i=1; i<stacks-1; i++ )
327 z0 = z1; z1 = cost2[i+1];
328 r0 = r1; r1 = sint2[i+1];
330 glBegin(GL_QUAD_STRIP);
332 for(j=0; j<=slices; j++)
334 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
335 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
336 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
337 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
343 /* The bottom stack is covered with a triangle fan */
348 glBegin(GL_TRIANGLE_FAN);
351 glVertex3d(0,0,-radius);
353 for (j=0; j<=slices; j++)
355 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
356 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
361 /* Release sin and cos tables */
370 * Draws a wire sphere
372 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
376 /* Adjust z and radius as stacks and slices are drawn. */
381 /* Pre-computed circle */
383 double *sint1,*cost1;
384 double *sint2,*cost2;
386 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
388 fghCircleTable(&sint1,&cost1,-slices );
389 fghCircleTable(&sint2,&cost2, stacks*2);
391 /* Draw a line loop for each stack */
393 for (i=1; i<stacks; i++)
398 glBegin(GL_LINE_LOOP);
400 for(j=0; j<=slices; j++)
406 glVertex3d(x*r*radius,y*r*radius,z*radius);
412 /* Draw a line loop for each slice */
414 for (i=0; i<slices; i++)
416 glBegin(GL_LINE_STRIP);
418 for(j=0; j<=stacks; j++)
420 x = cost1[i]*sint2[j];
421 y = sint1[i]*sint2[j];
425 glVertex3d(x*radius,y*radius,z*radius);
431 /* Release sin and cos tables */
442 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
446 /* Step in z and radius as stacks are drawn. */
451 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
452 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
454 /* Scaling factors for vertex normals */
456 const double cosn = ( height / sqrt ( height * height + base * base ));
457 const double sinn = ( base / sqrt ( height * height + base * base ));
459 /* Pre-computed circle */
463 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
465 fghCircleTable(&sint,&cost,-slices);
467 /* Cover the circular base with a triangle fan... */
475 glBegin(GL_TRIANGLE_FAN);
477 glNormal3d(0.0,0.0,-1.0);
478 glVertex3d(0.0,0.0, z0 );
480 for (j=0; j<=slices; j++)
481 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
485 /* Cover each stack with a quad strip, except the top stack */
487 for( i=0; i<stacks-1; i++ )
489 glBegin(GL_QUAD_STRIP);
491 for(j=0; j<=slices; j++)
493 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
494 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
495 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
498 z0 = z1; z1 += zStep;
499 r0 = r1; r1 -= rStep;
504 /* The top stack is covered with individual triangles */
506 glBegin(GL_TRIANGLES);
508 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
510 for (j=0; j<slices; j++)
512 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
513 glVertex3d(0, 0, height);
514 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
515 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
520 /* Release sin and cos tables */
529 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
533 /* Step in z and radius as stacks are drawn. */
538 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
539 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
541 /* Scaling factors for vertex normals */
543 const double cosn = ( height / sqrt ( height * height + base * base ));
544 const double sinn = ( base / sqrt ( height * height + base * base ));
546 /* Pre-computed circle */
550 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
552 fghCircleTable(&sint,&cost,-slices);
554 /* Draw the stacks... */
556 for (i=0; i<stacks; i++)
558 glBegin(GL_LINE_LOOP);
560 for( j=0; j<slices; j++ )
562 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
563 glVertex3d(cost[j]*r, sint[j]*r, z );
572 /* Draw the slices */
578 for (j=0; j<slices; j++)
580 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
581 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
582 glVertex3d(0.0, 0.0, height);
587 /* Release sin and cos tables */
595 * Draws a solid cylinder
597 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
601 /* Step in z and radius as stacks are drawn. */
604 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
606 /* Pre-computed circle */
610 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
612 fghCircleTable(&sint,&cost,-slices);
614 /* Cover the base and top */
616 glBegin(GL_TRIANGLE_FAN);
617 glNormal3d(0.0, 0.0, -1.0 );
618 glVertex3d(0.0, 0.0, 0.0 );
619 for (j=0; j<=slices; j++)
620 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
623 glBegin(GL_TRIANGLE_FAN);
624 glNormal3d(0.0, 0.0, 1.0 );
625 glVertex3d(0.0, 0.0, height);
626 for (j=slices; j>=0; j--)
627 glVertex3d(cost[j]*radius, sint[j]*radius, height);
635 for (i=1; i<=stacks; i++)
640 glBegin(GL_QUAD_STRIP);
641 for (j=0; j<=slices; j++ )
643 glNormal3d(cost[j], sint[j], 0.0 );
644 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
645 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
649 z0 = z1; z1 += zStep;
652 /* Release sin and cos tables */
659 * Draws a wire cylinder
661 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
665 /* Step in z and radius as stacks are drawn. */
668 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
670 /* Pre-computed circle */
674 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
676 fghCircleTable(&sint,&cost,-slices);
678 /* Draw the stacks... */
680 for (i=0; i<=stacks; i++)
685 glBegin(GL_LINE_LOOP);
687 for( j=0; j<slices; j++ )
689 glNormal3d(cost[j], sint[j], 0.0);
690 glVertex3d(cost[j]*radius, sint[j]*radius, z );
698 /* Draw the slices */
702 for (j=0; j<slices; j++)
704 glNormal3d(cost[j], sint[j], 0.0 );
705 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
706 glVertex3d(cost[j]*radius, sint[j]*radius, height);
711 /* Release sin and cos tables */
720 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
722 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
723 double *vertex, *normal;
725 double spsi, cpsi, sphi, cphi ;
727 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
729 if ( nSides < 1 ) nSides = 1;
730 if ( nRings < 1 ) nRings = 1;
732 /* Allocate the vertices array */
733 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
734 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
738 dpsi = 2.0 * M_PI / (double)nRings ;
739 dphi = -2.0 * M_PI / (double)nSides ;
742 for( j=0; j<nRings; j++ )
748 for( i=0; i<nSides; i++ )
750 int offset = 3 * ( j * nSides + i ) ;
753 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
754 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
755 *(vertex + offset + 2) = sphi * iradius ;
756 *(normal + offset + 0) = cpsi * cphi ;
757 *(normal + offset + 1) = spsi * cphi ;
758 *(normal + offset + 2) = sphi ;
765 for( i=0; i<nSides; i++ )
767 glBegin( GL_LINE_LOOP );
769 for( j=0; j<nRings; j++ )
771 int offset = 3 * ( j * nSides + i ) ;
772 glNormal3dv( normal + offset );
773 glVertex3dv( vertex + offset );
779 for( j=0; j<nRings; j++ )
781 glBegin(GL_LINE_LOOP);
783 for( i=0; i<nSides; i++ )
785 int offset = 3 * ( j * nSides + i ) ;
786 glNormal3dv( normal + offset );
787 glVertex3dv( vertex + offset );
799 * Draws a solid torus
801 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
803 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
804 double *vertex, *normal;
806 double spsi, cpsi, sphi, cphi ;
808 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
810 if ( nSides < 1 ) nSides = 1;
811 if ( nRings < 1 ) nRings = 1;
813 /* Increment the number of sides and rings to allow for one more point than surface */
817 /* Allocate the vertices array */
818 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
819 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
823 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
824 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
827 for( j=0; j<nRings; j++ )
833 for( i=0; i<nSides; i++ )
835 int offset = 3 * ( j * nSides + i ) ;
838 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
839 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
840 *(vertex + offset + 2) = sphi * iradius ;
841 *(normal + offset + 0) = cpsi * cphi ;
842 *(normal + offset + 1) = spsi * cphi ;
843 *(normal + offset + 2) = sphi ;
851 for( i=0; i<nSides-1; i++ )
853 for( j=0; j<nRings-1; j++ )
855 int offset = 3 * ( j * nSides + i ) ;
856 glNormal3dv( normal + offset );
857 glVertex3dv( vertex + offset );
858 glNormal3dv( normal + offset + 3 );
859 glVertex3dv( vertex + offset + 3 );
860 glNormal3dv( normal + offset + 3 * nSides + 3 );
861 glVertex3dv( vertex + offset + 3 * nSides + 3 );
862 glNormal3dv( normal + offset + 3 * nSides );
863 glVertex3dv( vertex + offset + 3 * nSides );
877 void FGAPIENTRY glutWireDodecahedron( void )
879 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
881 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
882 * of a cube. The coordinates of the points are:
883 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
884 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
885 * x = 0.61803398875 and z = 1.61803398875.
887 glBegin ( GL_LINE_LOOP ) ;
888 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 ) ;
890 glBegin ( GL_LINE_LOOP ) ;
891 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 ) ;
893 glBegin ( GL_LINE_LOOP ) ;
894 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 ) ;
896 glBegin ( GL_LINE_LOOP ) ;
897 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 ) ;
900 glBegin ( GL_LINE_LOOP ) ;
901 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 ) ;
903 glBegin ( GL_LINE_LOOP ) ;
904 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 ) ;
906 glBegin ( GL_LINE_LOOP ) ;
907 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 ) ;
909 glBegin ( GL_LINE_LOOP ) ;
910 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 ) ;
913 glBegin ( GL_LINE_LOOP ) ;
914 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 ) ;
916 glBegin ( GL_LINE_LOOP ) ;
917 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 ) ;
919 glBegin ( GL_LINE_LOOP ) ;
920 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 ) ;
922 glBegin ( GL_LINE_LOOP ) ;
923 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 ) ;
930 void FGAPIENTRY glutSolidDodecahedron( void )
932 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
934 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
935 * of a cube. The coordinates of the points are:
936 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
937 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
938 * x = 0.61803398875 and z = 1.61803398875.
940 glBegin ( GL_POLYGON ) ;
941 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 ) ;
943 glBegin ( GL_POLYGON ) ;
944 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 ) ;
946 glBegin ( GL_POLYGON ) ;
947 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 ) ;
949 glBegin ( GL_POLYGON ) ;
950 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 ) ;
953 glBegin ( GL_POLYGON ) ;
954 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 ) ;
956 glBegin ( GL_POLYGON ) ;
957 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 ) ;
959 glBegin ( GL_POLYGON ) ;
960 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 ) ;
962 glBegin ( GL_POLYGON ) ;
963 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 ) ;
966 glBegin ( GL_POLYGON ) ;
967 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 ) ;
969 glBegin ( GL_POLYGON ) ;
970 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 ) ;
972 glBegin ( GL_POLYGON ) ;
973 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 ) ;
975 glBegin ( GL_POLYGON ) ;
976 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 ) ;
983 void FGAPIENTRY glutWireOctahedron( void )
985 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
988 glBegin( GL_LINE_LOOP );
989 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 );
990 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 );
991 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 );
992 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 );
993 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 );
994 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 );
995 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 );
996 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 );
1004 void FGAPIENTRY glutSolidOctahedron( void )
1006 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1009 glBegin( GL_TRIANGLES );
1010 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 );
1011 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 );
1012 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 );
1013 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 );
1014 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 );
1015 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 );
1016 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 );
1017 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 );
1025 static double icos_r[12][3] = {
1027 { 0.447213595500, 0.894427191000, 0.0 },
1028 { 0.447213595500, 0.276393202252, 0.850650808354 },
1029 { 0.447213595500, -0.723606797748, 0.525731112119 },
1030 { 0.447213595500, -0.723606797748, -0.525731112119 },
1031 { 0.447213595500, 0.276393202252, -0.850650808354 },
1032 { -0.447213595500, -0.894427191000, 0.0 },
1033 { -0.447213595500, -0.276393202252, 0.850650808354 },
1034 { -0.447213595500, 0.723606797748, 0.525731112119 },
1035 { -0.447213595500, 0.723606797748, -0.525731112119 },
1036 { -0.447213595500, -0.276393202252, -0.850650808354 },
1040 static int icos_v [20][3] = {
1063 void FGAPIENTRY glutWireIcosahedron( void )
1067 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1069 for ( i = 0; i < 20; i++ )
1072 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] ) ;
1073 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] ) ;
1074 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] ) ;
1075 glBegin ( GL_LINE_LOOP ) ;
1076 glNormal3dv ( normal ) ;
1077 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1078 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1079 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1087 void FGAPIENTRY glutSolidIcosahedron( void )
1091 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1093 glBegin ( GL_TRIANGLES ) ;
1094 for ( i = 0; i < 20; i++ )
1097 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] ) ;
1098 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] ) ;
1099 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] ) ;
1100 glNormal3dv ( normal ) ;
1101 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1102 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1103 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1112 static double rdod_r[14][3] = {
1114 { 0.707106781187, 0.000000000000, 0.5 },
1115 { 0.000000000000, 0.707106781187, 0.5 },
1116 { -0.707106781187, 0.000000000000, 0.5 },
1117 { 0.000000000000, -0.707106781187, 0.5 },
1118 { 0.707106781187, 0.707106781187, 0.0 },
1119 { -0.707106781187, 0.707106781187, 0.0 },
1120 { -0.707106781187, -0.707106781187, 0.0 },
1121 { 0.707106781187, -0.707106781187, 0.0 },
1122 { 0.707106781187, 0.000000000000, -0.5 },
1123 { 0.000000000000, 0.707106781187, -0.5 },
1124 { -0.707106781187, 0.000000000000, -0.5 },
1125 { 0.000000000000, -0.707106781187, -0.5 },
1129 static int rdod_v [12][4] = {
1144 static double rdod_n[12][3] = {
1145 { 0.353553390594, 0.353553390594, 0.5 },
1146 { -0.353553390594, 0.353553390594, 0.5 },
1147 { -0.353553390594, -0.353553390594, 0.5 },
1148 { 0.353553390594, -0.353553390594, 0.5 },
1149 { 0.000000000000, 1.000000000000, 0.0 },
1150 { -1.000000000000, 0.000000000000, 0.0 },
1151 { 0.000000000000, -1.000000000000, 0.0 },
1152 { 1.000000000000, 0.000000000000, 0.0 },
1153 { 0.353553390594, 0.353553390594, -0.5 },
1154 { -0.353553390594, 0.353553390594, -0.5 },
1155 { -0.353553390594, -0.353553390594, -0.5 },
1156 { 0.353553390594, -0.353553390594, -0.5 }
1159 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1163 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1165 for ( i = 0; i < 12; i++ )
1167 glBegin ( GL_LINE_LOOP ) ;
1168 glNormal3dv ( rdod_n[i] ) ;
1169 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1170 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1171 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1172 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1180 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1184 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1186 glBegin ( GL_QUADS ) ;
1187 for ( i = 0; i < 12; i++ )
1189 glNormal3dv ( rdod_n[i] ) ;
1190 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1191 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1192 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1193 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1199 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1203 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1205 if ( num_levels == 0 )
1208 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
1210 glBegin ( GL_LINE_LOOP ) ;
1211 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1212 for ( j = 0; j < 3; j++ )
1214 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1215 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1216 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1217 glVertex3d ( x, y, z ) ;
1223 else if ( num_levels > 0 )
1225 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1228 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
1230 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1231 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1232 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1233 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1238 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1242 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1244 if ( num_levels == 0 )
1246 glBegin ( GL_TRIANGLES ) ;
1248 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
1250 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1251 for ( j = 0; j < 3; j++ )
1253 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1254 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1255 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1256 glVertex3d ( x, y, z ) ;
1262 else if ( num_levels > 0 )
1264 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1267 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
1269 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1270 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1271 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1272 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1279 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1282 void FGAPIENTRY glutWireTetrahedron( void )
1284 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1286 fghTetrahedron( TRUE );
1288 void FGAPIENTRY glutSolidTetrahedron( void )
1290 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1292 fghTetrahedron( FALSE );
1296 /*** END OF FILE ***/