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 "freeglut_internal.h"
32 * TODO BEFORE THE STABLE RELEASE:
34 * Following functions have been contributed by Andreas Umbach.
36 * glutWireCube() -- looks OK
37 * glutSolidCube() -- OK
39 * Those functions have been implemented by John Fay.
41 * glutWireTorus() -- looks OK
42 * glutSolidTorus() -- looks OK
43 * glutWireDodecahedron() -- looks OK
44 * glutSolidDodecahedron() -- looks OK
45 * glutWireOctahedron() -- looks OK
46 * glutSolidOctahedron() -- looks OK
47 * glutWireTetrahedron() -- looks OK
48 * glutSolidTetrahedron() -- looks OK
49 * glutWireIcosahedron() -- looks OK
50 * glutSolidIcosahedron() -- looks OK
52 * The Following functions have been updated by Nigel Stewart, based
53 * on FreeGLUT 2.0.0 implementations:
55 * glutWireSphere() -- looks OK
56 * glutSolidSphere() -- looks OK
57 * glutWireCone() -- looks OK
58 * glutSolidCone() -- looks OK
62 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
65 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
67 void FGAPIENTRY glutWireCube( GLdouble dSize )
69 double size = dSize * 0.5;
71 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
73 # define V(a,b,c) glVertex3d( a size, b size, c size );
74 # define N(a,b,c) glNormal3d( a, b, c );
76 /* PWO: I dared to convert the code to use macros... */
77 glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
78 glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
79 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
80 glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
81 glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
82 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
89 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
91 void FGAPIENTRY glutSolidCube( GLdouble dSize )
93 double size = dSize * 0.5;
95 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
97 # define V(a,b,c) glVertex3d( a size, b size, c size );
98 # define N(a,b,c) glNormal3d( a, b, c );
100 /* PWO: Again, I dared to convert the code to use macros... */
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(+,-,-);
115 * Compute lookup table of cos and sin values forming a cirle
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
124 static void fghCircleTable(double **sint,double **cost,const int n)
128 /* Table size, the sign of n flips the circle direction */
130 const int size = abs(n);
132 /* Determine the angle between samples */
134 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
136 /* Allocate memory for n samples, plus duplicate of first entry at the end */
138 *sint = (double *) calloc(sizeof(double), size+1);
139 *cost = (double *) calloc(sizeof(double), size+1);
141 /* Bail out if memory allocation fails, fgError never returns */
143 if (!(*sint) || !(*cost))
147 fgError("Failed to allocate memory in fghCircleTable");
150 /* Compute cos and sin around the circle */
155 for (i=1; i<size; i++)
157 (*sint)[i] = sin(angle*i);
158 (*cost)[i] = cos(angle*i);
161 /* Last sample is duplicate of the first */
163 (*sint)[size] = (*sint)[0];
164 (*cost)[size] = (*cost)[0];
168 * Draws a solid sphere
170 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
174 /* Adjust z and radius as stacks are drawn. */
179 /* Pre-computed circle */
181 double *sint1,*cost1;
182 double *sint2,*cost2;
184 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
186 fghCircleTable(&sint1,&cost1,-slices);
187 fghCircleTable(&sint2,&cost2,stacks*2);
189 /* The top stack is covered with a triangle fan */
192 z1 = cost2[(stacks>0)?1:0];
194 r1 = sint2[(stacks>0)?1:0];
196 glBegin(GL_TRIANGLE_FAN);
199 glVertex3d(0,0,radius);
201 for (j=slices; j>=0; j--)
203 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
204 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
209 /* Cover each stack with a quad strip, except the top and bottom stacks */
211 for( i=1; i<stacks-1; i++ )
213 z0 = z1; z1 = cost2[i+1];
214 r0 = r1; r1 = sint2[i+1];
216 glBegin(GL_QUAD_STRIP);
218 for(j=0; j<=slices; j++)
220 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
221 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
222 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
223 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
229 /* The bottom stack is covered with a triangle fan */
234 glBegin(GL_TRIANGLE_FAN);
237 glVertex3d(0,0,-radius);
239 for (j=0; j<=slices; j++)
241 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
242 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
247 /* Release sin and cos tables */
256 * Draws a wire sphere
258 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
262 /* Adjust z and radius as stacks and slices are drawn. */
267 /* Pre-computed circle */
269 double *sint1,*cost1;
270 double *sint2,*cost2;
272 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
274 fghCircleTable(&sint1,&cost1,-slices );
275 fghCircleTable(&sint2,&cost2, stacks*2);
277 /* Draw a line loop for each stack */
279 for (i=1; i<stacks; i++)
284 glBegin(GL_LINE_LOOP);
286 for(j=0; j<=slices; j++)
292 glVertex3d(x*r*radius,y*r*radius,z*radius);
298 /* Draw a line loop for each slice */
300 for (i=0; i<slices; i++)
302 glBegin(GL_LINE_STRIP);
304 for(j=0; j<=stacks; j++)
306 x = cost1[i]*sint2[j];
307 y = sint1[i]*sint2[j];
311 glVertex3d(x*radius,y*radius,z*radius);
317 /* Release sin and cos tables */
328 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
332 /* Step in z and radius as stacks are drawn. */
337 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
338 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
340 /* Scaling factors for vertex normals */
342 const double cosn = ( height / sqrt ( height * height + base * base ));
343 const double sinn = ( base / sqrt ( height * height + base * base ));
345 /* Pre-computed circle */
349 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
351 fghCircleTable(&sint,&cost,-slices);
353 /* Cover the circular base with a triangle fan... */
361 glBegin(GL_TRIANGLE_FAN);
363 glNormal3d(0.0,0.0,-1.0);
364 glVertex3d(0.0,0.0, z0 );
366 for (j=0; j<=slices; j++)
367 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
371 /* Cover each stack with a quad strip, except the top stack */
373 for( i=0; i<stacks-1; i++ )
375 glBegin(GL_QUAD_STRIP);
377 for(j=0; j<=slices; j++)
379 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
380 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
381 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
384 z0 = z1; z1 += zStep;
385 r0 = r1; r1 -= rStep;
390 /* The top stack is covered with individual triangles */
392 glBegin(GL_TRIANGLES);
394 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
396 for (j=0; j<slices; j++)
398 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
399 glVertex3d(0, 0, height);
400 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
401 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
406 /* Release sin and cos tables */
415 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
419 /* Step in z and radius as stacks are drawn. */
424 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
425 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
427 /* Scaling factors for vertex normals */
429 const double cosn = ( height / sqrt ( height * height + base * base ));
430 const double sinn = ( base / sqrt ( height * height + base * base ));
432 /* Pre-computed circle */
436 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
438 fghCircleTable(&sint,&cost,-slices);
440 /* Draw the stacks... */
442 for (i=0; i<stacks; i++)
444 glBegin(GL_LINE_LOOP);
446 for( j=0; j<slices; j++ )
448 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
449 glVertex3d(cost[j]*r, sint[j]*r, z );
458 /* Draw the slices */
464 for (j=0; j<slices; j++)
466 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
467 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
468 glVertex3d(0.0, 0.0, height);
473 /* Release sin and cos tables */
481 * Draws a solid cylinder
483 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
487 /* Step in z and radius as stacks are drawn. */
490 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
492 /* Pre-computed circle */
496 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
498 fghCircleTable(&sint,&cost,-slices);
500 /* Cover the base and top */
502 glBegin(GL_TRIANGLE_FAN);
503 glNormal3d(0.0, 0.0, -1.0 );
504 glVertex3d(0.0, 0.0, 0.0 );
505 for (j=0; j<=slices; j++)
506 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
509 glBegin(GL_TRIANGLE_FAN);
510 glNormal3d(0.0, 0.0, 1.0 );
511 glVertex3d(0.0, 0.0, height);
512 for (j=slices; j>=0; j--)
513 glVertex3d(cost[j]*radius, sint[j]*radius, height);
521 for (i=1; i<=stacks; i++)
526 glBegin(GL_QUAD_STRIP);
527 for (j=0; j<=slices; j++ )
529 glNormal3d(cost[j], sint[j], 0.0 );
530 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
531 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
535 z0 = z1; z1 += zStep;
538 /* Release sin and cos tables */
545 * Draws a wire cylinder
547 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
551 /* Step in z and radius as stacks are drawn. */
554 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
556 /* Pre-computed circle */
560 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
562 fghCircleTable(&sint,&cost,-slices);
564 /* Draw the stacks... */
566 for (i=0; i<=stacks; i++)
571 glBegin(GL_LINE_LOOP);
573 for( j=0; j<slices; j++ )
575 glNormal3d(cost[j], sint[j], 0.0);
576 glVertex3d(cost[j]*radius, sint[j]*radius, z );
584 /* Draw the slices */
588 for (j=0; j<slices; j++)
590 glNormal3d(cost[j], sint[j], 0.0 );
591 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
592 glVertex3d(cost[j]*radius, sint[j]*radius, height);
597 /* Release sin and cos tables */
606 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
608 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
609 double *vertex, *normal;
611 double spsi, cpsi, sphi, cphi ;
613 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
615 if ( nSides < 1 ) nSides = 1;
616 if ( nRings < 1 ) nRings = 1;
618 /* Allocate the vertices array */
619 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
620 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
624 dpsi = 2.0 * M_PI / (double)nRings ;
625 dphi = -2.0 * M_PI / (double)nSides ;
628 for( j=0; j<nRings; j++ )
634 for( i=0; i<nSides; i++ )
636 int offset = 3 * ( j * nSides + i ) ;
639 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
640 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
641 *(vertex + offset + 2) = sphi * iradius ;
642 *(normal + offset + 0) = cpsi * cphi ;
643 *(normal + offset + 1) = spsi * cphi ;
644 *(normal + offset + 2) = sphi ;
651 for( i=0; i<nSides; i++ )
653 glBegin( GL_LINE_LOOP );
655 for( j=0; j<nRings; j++ )
657 int offset = 3 * ( j * nSides + i ) ;
658 glNormal3dv( normal + offset );
659 glVertex3dv( vertex + offset );
665 for( j=0; j<nRings; j++ )
667 glBegin(GL_LINE_LOOP);
669 for( i=0; i<nSides; i++ )
671 int offset = 3 * ( j * nSides + i ) ;
672 glNormal3dv( normal + offset );
673 glVertex3dv( vertex + offset );
685 * Draws a solid torus
687 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
689 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
690 double *vertex, *normal;
692 double spsi, cpsi, sphi, cphi ;
694 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
696 if ( nSides < 1 ) nSides = 1;
697 if ( nRings < 1 ) nRings = 1;
699 /* Increment the number of sides and rings to allow for one more point than surface */
703 /* Allocate the vertices array */
704 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
705 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
709 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
710 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
713 for( j=0; j<nRings; j++ )
719 for( i=0; i<nSides; i++ )
721 int offset = 3 * ( j * nSides + i ) ;
724 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
725 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
726 *(vertex + offset + 2) = sphi * iradius ;
727 *(normal + offset + 0) = cpsi * cphi ;
728 *(normal + offset + 1) = spsi * cphi ;
729 *(normal + offset + 2) = sphi ;
737 for( i=0; i<nSides-1; i++ )
739 for( j=0; j<nRings-1; j++ )
741 int offset = 3 * ( j * nSides + i ) ;
742 glNormal3dv( normal + offset );
743 glVertex3dv( vertex + offset );
744 glNormal3dv( normal + offset + 3 );
745 glVertex3dv( vertex + offset + 3 );
746 glNormal3dv( normal + offset + 3 * nSides + 3 );
747 glVertex3dv( vertex + offset + 3 * nSides + 3 );
748 glNormal3dv( normal + offset + 3 * nSides );
749 glVertex3dv( vertex + offset + 3 * nSides );
763 void FGAPIENTRY glutWireDodecahedron( void )
765 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
767 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
768 * of a cube. The coordinates of the points are:
769 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
770 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
771 * x = 0.61803398875 and z = 1.61803398875.
773 glBegin ( GL_LINE_LOOP ) ;
774 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 ) ;
776 glBegin ( GL_LINE_LOOP ) ;
777 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 glBegin ( GL_LINE_LOOP ) ;
780 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 glBegin ( GL_LINE_LOOP ) ;
783 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 ) ;
786 glBegin ( GL_LINE_LOOP ) ;
787 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 ) ;
789 glBegin ( GL_LINE_LOOP ) ;
790 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 glBegin ( GL_LINE_LOOP ) ;
793 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 glBegin ( GL_LINE_LOOP ) ;
796 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 ) ;
799 glBegin ( GL_LINE_LOOP ) ;
800 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 ) ;
802 glBegin ( GL_LINE_LOOP ) ;
803 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 glBegin ( GL_LINE_LOOP ) ;
806 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 glBegin ( GL_LINE_LOOP ) ;
809 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 ) ;
816 void FGAPIENTRY glutSolidDodecahedron( void )
818 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
820 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
821 * of a cube. The coordinates of the points are:
822 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
823 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
824 * x = 0.61803398875 and z = 1.61803398875.
826 glBegin ( GL_POLYGON ) ;
827 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 ) ;
829 glBegin ( GL_POLYGON ) ;
830 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 glBegin ( GL_POLYGON ) ;
833 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 glBegin ( GL_POLYGON ) ;
836 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 ) ;
839 glBegin ( GL_POLYGON ) ;
840 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 ) ;
842 glBegin ( GL_POLYGON ) ;
843 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 glBegin ( GL_POLYGON ) ;
846 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 glBegin ( GL_POLYGON ) ;
849 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 ) ;
852 glBegin ( GL_POLYGON ) ;
853 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 ) ;
855 glBegin ( GL_POLYGON ) ;
856 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 glBegin ( GL_POLYGON ) ;
859 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 glBegin ( GL_POLYGON ) ;
862 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 ) ;
869 void FGAPIENTRY glutWireOctahedron( void )
871 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
874 glBegin( GL_LINE_LOOP );
875 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 );
876 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 );
877 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 );
878 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 );
879 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 );
880 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 );
881 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 );
882 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 );
890 void FGAPIENTRY glutSolidOctahedron( void )
892 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
895 glBegin( GL_TRIANGLES );
896 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 );
897 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 );
898 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 );
899 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 );
900 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 );
901 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 );
902 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 );
903 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 /* Magic Numbers: r0 = ( 1, 0, 0 )
909 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
910 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
911 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
912 * |r0| = |r1| = |r2| = |r3| = 1
913 * Distance between any two points is 2 sqrt(6) / 3
915 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
918 #define NUM_TETR_FACES 4
920 static GLdouble tet_r[4][3] = { { 1.0, 0.0, 0.0 },
921 { -0.333333333333, 0.942809041582, 0.0 },
922 { -0.333333333333, -0.471404520791, 0.816496580928 },
923 { -0.333333333333, -0.471404520791, -0.816496580928 } } ;
925 static GLint tet_i[4][3] = /* Vertex indices */
927 { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
933 void FGAPIENTRY glutWireTetrahedron( void )
935 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
937 glBegin( GL_LINE_LOOP ) ;
938 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] ) ;
939 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] ) ;
940 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] ) ;
941 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] ) ;
948 void FGAPIENTRY glutSolidTetrahedron( void )
950 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
952 glBegin( GL_TRIANGLES ) ;
953 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] ) ;
954 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] ) ;
955 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] ) ;
956 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] ) ;
963 static double icos_r[12][3] = {
965 { 0.447213595500, 0.894427191000, 0.0 },
966 { 0.447213595500, 0.276393202252, 0.850650808354 },
967 { 0.447213595500, -0.723606797748, 0.525731112119 },
968 { 0.447213595500, -0.723606797748, -0.525731112119 },
969 { 0.447213595500, 0.276393202252, -0.850650808354 },
970 { -0.447213595500, -0.894427191000, 0.0 },
971 { -0.447213595500, -0.276393202252, 0.850650808354 },
972 { -0.447213595500, 0.723606797748, 0.525731112119 },
973 { -0.447213595500, 0.723606797748, -0.525731112119 },
974 { -0.447213595500, -0.276393202252, -0.850650808354 },
978 static int icos_v [20][3] = {
1001 void FGAPIENTRY glutWireIcosahedron( void )
1005 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1007 for ( i = 0; i < 20; i++ )
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 glBegin ( GL_LINE_LOOP ) ;
1014 glNormal3dv ( normal ) ;
1015 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1016 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1017 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1025 void FGAPIENTRY glutSolidIcosahedron( void )
1029 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1031 glBegin ( GL_TRIANGLES ) ;
1032 for ( i = 0; i < 20; i++ )
1035 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] ) ;
1036 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] ) ;
1037 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] ) ;
1038 glNormal3dv ( normal ) ;
1039 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1040 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1041 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1050 static double rdod_r[14][3] = {
1052 { 0.707106781187, 0.000000000000, 0.5 },
1053 { 0.000000000000, 0.707106781187, 0.5 },
1054 { -0.707106781187, 0.000000000000, 0.5 },
1055 { 0.000000000000, -0.707106781187, 0.5 },
1056 { 0.707106781187, 0.707106781187, 0.0 },
1057 { -0.707106781187, 0.707106781187, 0.0 },
1058 { -0.707106781187, -0.707106781187, 0.0 },
1059 { 0.707106781187, -0.707106781187, 0.0 },
1060 { 0.707106781187, 0.000000000000, -0.5 },
1061 { 0.000000000000, 0.707106781187, -0.5 },
1062 { -0.707106781187, 0.000000000000, -0.5 },
1063 { 0.000000000000, -0.707106781187, -0.5 },
1067 static int rdod_v [12][4] = {
1082 static double rdod_n[12][3] = {
1083 { 0.353553390594, 0.353553390594, 0.5 },
1084 { -0.353553390594, 0.353553390594, 0.5 },
1085 { -0.353553390594, -0.353553390594, 0.5 },
1086 { 0.353553390594, -0.353553390594, 0.5 },
1087 { 0.000000000000, 1.000000000000, 0.0 },
1088 { -1.000000000000, 0.000000000000, 0.0 },
1089 { 0.000000000000, -1.000000000000, 0.0 },
1090 { 1.000000000000, 0.000000000000, 0.0 },
1091 { 0.353553390594, 0.353553390594, -0.5 },
1092 { -0.353553390594, 0.353553390594, -0.5 },
1093 { -0.353553390594, -0.353553390594, -0.5 },
1094 { 0.353553390594, -0.353553390594, -0.5 }
1097 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1101 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1103 for ( i = 0; i < 12; i++ )
1105 glBegin ( GL_LINE_LOOP ) ;
1106 glNormal3dv ( rdod_n[i] ) ;
1107 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1108 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1109 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1110 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1118 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1122 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1124 glBegin ( GL_QUADS ) ;
1125 for ( i = 0; i < 12; i++ )
1127 glNormal3dv ( rdod_n[i] ) ;
1128 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1129 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1130 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1131 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1137 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1141 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1143 if ( num_levels == 0 )
1146 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1148 glBegin ( GL_LINE_LOOP ) ;
1149 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1150 for ( j = 0; j < 3; j++ )
1152 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1153 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1154 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1155 glVertex3d ( x, y, z ) ;
1161 else if ( num_levels > 0 )
1163 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1166 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1168 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1169 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1170 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1171 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1176 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1180 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1182 if ( num_levels == 0 )
1184 glBegin ( GL_TRIANGLES ) ;
1186 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1188 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1189 for ( j = 0; j < 3; j++ )
1191 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1192 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1193 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1194 glVertex3d ( x, y, z ) ;
1200 else if ( num_levels > 0 )
1202 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1205 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1207 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1208 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1209 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1210 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1215 /*** END OF FILE ***/