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.
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
36 * TODO BEFORE THE STABLE RELEASE:
38 * Following functions have been contributed by Andreas Umbach.
40 * glutWireCube() -- looks OK
41 * glutSolidCube() -- OK
43 * Those functions have been implemented by John Fay.
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
56 * The Following functions have been updated by Nigel Stewart, based
57 * on FreeGLUT 2.0.0 implementations:
59 * glutWireSphere() -- looks OK
60 * glutSolidSphere() -- looks OK
61 * glutWireCone() -- looks OK
62 * glutSolidCone() -- looks OK
66 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
69 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
71 void FGAPIENTRY glutWireCube( GLdouble dSize )
73 double size = dSize * 0.5;
75 # define V(a,b,c) glVertex3d( a size, b size, c size );
76 # define N(a,b,c) glNormal3d( a, b, c );
78 /* PWO: I dared to convert the code to use macros... */
79 glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
80 glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
81 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
82 glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
83 glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
84 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
91 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
93 void FGAPIENTRY glutSolidCube( GLdouble dSize )
95 double size = dSize * 0.5;
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 circleTable(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;
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 circleTable");
150 /* Compute cos and sin around the circle */
152 for (i=0; i<size; i++)
154 (*sint)[i] = sin(angle*i);
155 (*cost)[i] = cos(angle*i);
158 /* Last sample is duplicate of the first */
160 (*sint)[size] = (*sint)[0];
161 (*cost)[size] = (*cost)[0];
165 * Draws a solid sphere
167 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
171 /* Adjust z and radius as stacks are drawn. */
176 /* Pre-computed circle */
178 double *sint1,*cost1;
179 double *sint2,*cost2;
180 circleTable(&sint1,&cost1,-slices);
181 circleTable(&sint2,&cost2,stacks*2);
183 /* The top stack is covered with a triangle fan */
190 glBegin(GL_TRIANGLE_FAN);
193 glVertex3d(0,0,radius);
195 for (j=slices; j>=0; j--)
197 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
198 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
203 /* Cover each stack with a quad strip, except the top and bottom stacks */
205 for( i=1; i<stacks-1; i++ )
207 z0 = z1; z1 = cost2[i+1];
208 r0 = r1; r1 = sint2[i+1];
210 glBegin(GL_QUAD_STRIP);
212 for(j=0; j<=slices; j++)
214 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
215 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
216 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
217 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
223 /* The bottom stack is covered with a triangle fan */
228 glBegin(GL_TRIANGLE_FAN);
231 glVertex3d(0,0,-radius);
233 for (j=0; j<=slices; j++)
235 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
236 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
241 /* Release sin and cos tables */
250 * Draws a wire sphere
252 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
256 /* Adjust z and radius as stacks and slices are drawn. */
261 /* Pre-computed circle */
263 double *sint1,*cost1;
264 double *sint2,*cost2;
265 circleTable(&sint1,&cost1,-slices );
266 circleTable(&sint2,&cost2, stacks*2);
268 /* Draw a line loop for each stack */
270 for (i=1; i<stacks; i++)
275 glBegin(GL_LINE_LOOP);
277 for(j=0; j<=slices; j++)
283 glVertex3d(x*r*radius,y*r*radius,z*radius);
289 /* Draw a line loop for each slice */
291 for (i=0; i<slices; i++)
293 glBegin(GL_LINE_STRIP);
295 for(j=0; j<=stacks; j++)
297 x = cost1[i]*sint2[j];
298 y = sint1[i]*sint2[j];
302 glVertex3d(x*radius,y*radius,z*radius);
308 /* Release sin and cos tables */
319 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
323 /* Step in z and radius as stacks are drawn. */
328 const double zStep = height/stacks;
329 const double rStep = base/stacks;
331 /* Scaling factors for vertex normals */
333 const double cosn = ( height / sqrt ( height * height + base * base ));
334 const double sinn = ( base / sqrt ( height * height + base * base ));
336 /* Pre-computed circle */
339 circleTable(&sint,&cost,-slices);
341 /* Cover the circular base with a triangle fan... */
349 glBegin(GL_TRIANGLE_FAN);
351 glNormal3d(0.0,0.0,-1.0);
352 glVertex3d(0.0,0.0, z0 );
354 for (j=0; j<=slices; j++)
355 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
359 /* Cover each stack with a quad strip, except the top stack */
361 for( i=0; i<stacks-1; i++ )
363 glBegin(GL_QUAD_STRIP);
365 for(j=0; j<=slices; j++)
367 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
368 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
369 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
372 z0 = z1; z1 += zStep;
373 r0 = r1; r1 -= rStep;
378 /* The top stack is covered with individual triangles */
380 glBegin(GL_TRIANGLES);
382 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
384 for (j=0; j<slices; j++)
386 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
387 glVertex3d(0, 0, height);
388 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
389 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
394 /* Release sin and cos tables */
403 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
407 /* Step in z and radius as stacks are drawn. */
412 const double zStep = height/stacks;
413 const double rStep = base/stacks;
415 /* Scaling factors for vertex normals */
417 const double cosn = ( height / sqrt ( height * height + base * base ));
418 const double sinn = ( base / sqrt ( height * height + base * base ));
420 /* Pre-computed circle */
423 circleTable(&sint,&cost,-slices);
425 /* Draw the stacks... */
427 for (i=0; i<stacks; i++)
429 glBegin(GL_LINE_LOOP);
431 for( j=0; j<slices; j++ )
433 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
434 glVertex3d(cost[j]*r, sint[j]*r, z );
443 /* Draw the slices */
449 for (j=0; j<slices; j++)
451 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
452 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
453 glVertex3d(0.0, 0.0, height);
458 /* Release sin and cos tables */
466 * Draws a solid cylinder
468 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
472 /* Step in z and radius as stacks are drawn. */
475 const double zStep = height/stacks;
477 /* Pre-computed circle */
480 circleTable(&sint,&cost,-slices);
482 /* Cover the base and top */
484 glBegin(GL_TRIANGLE_FAN);
485 glNormal3d(0.0, 0.0, -1.0 );
486 glVertex3d(0.0, 0.0, 0.0 );
487 for (j=0; j<=slices; j++)
488 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
491 glBegin(GL_TRIANGLE_FAN);
492 glNormal3d(0.0, 0.0, 1.0 );
493 glVertex3d(0.0, 0.0, height);
494 for (j=slices; j>=0; j--)
495 glVertex3d(cost[j]*radius, sint[j]*radius, height);
503 for (i=1; i<=stacks; i++)
508 glBegin(GL_QUAD_STRIP);
509 for (j=0; j<=slices; j++ )
511 glNormal3d(cost[j], sint[j], 0.0 );
512 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
513 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
517 z0 = z1; z1 += zStep;
520 /* Release sin and cos tables */
527 * Draws a wire cylinder
529 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
533 /* Step in z and radius as stacks are drawn. */
536 const double zStep = height/stacks;
538 /* Pre-computed circle */
541 circleTable(&sint,&cost,-slices);
543 /* Draw the stacks... */
545 for (i=0; i<=stacks; i++)
550 glBegin(GL_LINE_LOOP);
552 for( j=0; j<slices; j++ )
554 glNormal3d(cost[j], sint[j], 0.0);
555 glVertex3d(cost[j]*radius, sint[j]*radius, z );
563 /* Draw the slices */
567 for (j=0; j<slices; j++)
569 glNormal3d(cost[j], sint[j], 0.0 );
570 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
571 glVertex3d(cost[j]*radius, sint[j]*radius, height);
576 /* Release sin and cos tables */
585 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
587 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
588 double *vertex, *normal;
590 double spsi, cpsi, sphi, cphi ;
592 /* Allocate the vertices array */
593 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
594 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
598 dpsi = 2.0 * M_PI / (double)nRings ;
599 dphi = -2.0 * M_PI / (double)nSides ;
602 for( j=0; j<nRings; j++ )
608 for( i=0; i<nSides; i++ )
610 int offset = 3 * ( j * nSides + i ) ;
613 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
614 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
615 *(vertex + offset + 2) = sphi * iradius ;
616 *(normal + offset + 0) = cpsi * cphi ;
617 *(normal + offset + 1) = spsi * cphi ;
618 *(normal + offset + 2) = sphi ;
625 for( i=0; i<nSides; i++ )
627 glBegin( GL_LINE_LOOP );
629 for( j=0; j<nRings; j++ )
631 int offset = 3 * ( j * nSides + i ) ;
632 glNormal3dv( normal + offset );
633 glVertex3dv( vertex + offset );
639 for( j=0; j<nRings; j++ )
641 glBegin(GL_LINE_LOOP);
643 for( i=0; i<nSides; i++ )
645 int offset = 3 * ( j * nSides + i ) ;
646 glNormal3dv( normal + offset );
647 glVertex3dv( vertex + offset );
659 * Draws a solid torus
661 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
663 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
664 double *vertex, *normal;
666 double spsi, cpsi, sphi, cphi ;
668 /* Increment the number of sides and rings to allow for one more point than surface */
672 /* Allocate the vertices array */
673 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
674 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
678 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
679 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
682 for( j=0; j<nRings; j++ )
688 for( i=0; i<nSides; i++ )
690 int offset = 3 * ( j * nSides + i ) ;
693 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
694 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
695 *(vertex + offset + 2) = sphi * iradius ;
696 *(normal + offset + 0) = cpsi * cphi ;
697 *(normal + offset + 1) = spsi * cphi ;
698 *(normal + offset + 2) = sphi ;
706 for( i=0; i<nSides-1; i++ )
708 for( j=0; j<nRings-1; j++ )
710 int offset = 3 * ( j * nSides + i ) ;
711 glNormal3dv( normal + offset );
712 glVertex3dv( vertex + offset );
713 glNormal3dv( normal + offset + 3 );
714 glVertex3dv( vertex + offset + 3 );
715 glNormal3dv( normal + offset + 3 * nSides + 3 );
716 glVertex3dv( vertex + offset + 3 * nSides + 3 );
717 glNormal3dv( normal + offset + 3 * nSides );
718 glVertex3dv( vertex + offset + 3 * nSides );
732 void FGAPIENTRY glutWireDodecahedron( void )
734 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
735 * of a cube. The coordinates of the points are:
736 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
737 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
738 * x = 0.61803398875 and z = 1.61803398875.
740 glBegin ( GL_LINE_LOOP ) ;
741 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 ) ;
743 glBegin ( GL_LINE_LOOP ) ;
744 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 ) ;
746 glBegin ( GL_LINE_LOOP ) ;
747 glNormal3d ( 0.0, -0.525731112119, 0.850650808354 ) ; glVertex3d ( 0.0, -1.61803398875, 0.61803398875 ) ; glVertex3d ( 1.0, -1.0, 1.0 ) ; glVertex3d ( 0.61803398875, 0.0, 1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0, 1.61803398875 ) ; glVertex3d ( -1.0, -1.0, 1.0 ) ;
749 glBegin ( GL_LINE_LOOP ) ;
750 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 ) ;
753 glBegin ( GL_LINE_LOOP ) ;
754 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 ) ;
756 glBegin ( GL_LINE_LOOP ) ;
757 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 ) ;
759 glBegin ( GL_LINE_LOOP ) ;
760 glNormal3d ( 0.850650808354, 0.0, -0.525731112119 ) ; glVertex3d ( 0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( 1.0, 1.0, -1.0 ) ; glVertex3d ( 1.61803398875, 0.61803398875, 0.0 ) ; glVertex3d ( 1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( 1.0, -1.0, -1.0 ) ;
762 glBegin ( GL_LINE_LOOP ) ;
763 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 ) ;
766 glBegin ( GL_LINE_LOOP ) ;
767 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 ) ;
769 glBegin ( GL_LINE_LOOP ) ;
770 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 ) ;
772 glBegin ( GL_LINE_LOOP ) ;
773 glNormal3d ( -0.525731112119, 0.850650808354, 0.0 ) ; glVertex3d ( -1.61803398875, 0.61803398875, 0.0 ) ; glVertex3d ( -1.0, 1.0, 1.0 ) ; glVertex3d ( 0.0, 1.61803398875, 0.61803398875 ) ; glVertex3d ( 0.0, 1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0, 1.0, -1.0 ) ;
775 glBegin ( GL_LINE_LOOP ) ;
776 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 ) ;
783 void FGAPIENTRY glutSolidDodecahedron( void )
785 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
786 * of a cube. The coordinates of the points are:
787 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
788 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
789 * x = 0.61803398875 and z = 1.61803398875.
791 glBegin ( GL_POLYGON ) ;
792 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 ) ;
794 glBegin ( GL_POLYGON ) ;
795 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 ) ;
797 glBegin ( GL_POLYGON ) ;
798 glNormal3d ( 0.0, -0.525731112119, 0.850650808354 ) ; glVertex3d ( 0.0, -1.61803398875, 0.61803398875 ) ; glVertex3d ( 1.0, -1.0, 1.0 ) ; glVertex3d ( 0.61803398875, 0.0, 1.61803398875 ) ; glVertex3d ( -0.61803398875, 0.0, 1.61803398875 ) ; glVertex3d ( -1.0, -1.0, 1.0 ) ;
800 glBegin ( GL_POLYGON ) ;
801 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 ) ;
804 glBegin ( GL_POLYGON ) ;
805 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 ) ;
807 glBegin ( GL_POLYGON ) ;
808 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 ) ;
810 glBegin ( GL_POLYGON ) ;
811 glNormal3d ( 0.850650808354, 0.0, -0.525731112119 ) ; glVertex3d ( 0.61803398875, 0.0, -1.61803398875 ) ; glVertex3d ( 1.0, 1.0, -1.0 ) ; glVertex3d ( 1.61803398875, 0.61803398875, 0.0 ) ; glVertex3d ( 1.61803398875, -0.61803398875, 0.0 ) ; glVertex3d ( 1.0, -1.0, -1.0 ) ;
813 glBegin ( GL_POLYGON ) ;
814 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 ) ;
817 glBegin ( GL_POLYGON ) ;
818 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 ) ;
820 glBegin ( GL_POLYGON ) ;
821 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 ) ;
823 glBegin ( GL_POLYGON ) ;
824 glNormal3d ( -0.525731112119, 0.850650808354, 0.0 ) ; glVertex3d ( -1.61803398875, 0.61803398875, 0.0 ) ; glVertex3d ( -1.0, 1.0, 1.0 ) ; glVertex3d ( 0.0, 1.61803398875, 0.61803398875 ) ; glVertex3d ( 0.0, 1.61803398875, -0.61803398875 ) ; glVertex3d ( -1.0, 1.0, -1.0 ) ;
826 glBegin ( GL_POLYGON ) ;
827 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 ) ;
834 void FGAPIENTRY glutWireOctahedron( void )
837 glBegin( GL_LINE_LOOP );
838 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 );
839 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 );
840 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 );
841 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 );
842 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 );
843 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 );
844 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 );
845 glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0,-RADIUS, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS );
853 void FGAPIENTRY glutSolidOctahedron( void )
856 glBegin( GL_TRIANGLES );
857 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 );
858 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 );
859 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 );
860 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 );
861 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 );
862 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 );
863 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 );
864 glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0,-RADIUS, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS );
872 void FGAPIENTRY glutWireTetrahedron( void )
874 /* Magic Numbers: r0 = ( 1, 0, 0 )
875 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
876 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
877 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
878 * |r0| = |r1| = |r2| = |r3| = 1
879 * Distance between any two points is 2 sqrt(6) / 3
881 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
884 double r0[3] = { 1.0, 0.0, 0.0 } ;
885 double r1[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
886 double r2[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
887 double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
889 glBegin( GL_LINE_LOOP ) ;
890 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
891 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
892 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
893 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
900 void FGAPIENTRY glutSolidTetrahedron( void )
902 /* Magic Numbers: r0 = ( 1, 0, 0 )
903 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
904 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
905 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
906 * |r0| = |r1| = |r2| = |r3| = 1
907 * Distance between any two points is 2 sqrt(6) / 3
909 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
912 double r0[3] = { 1.0, 0.0, 0.0 } ;
913 double r1[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
914 double r2[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
915 double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
917 glBegin( GL_TRIANGLES ) ;
918 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
919 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
920 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
921 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
928 double icos_r[12][3] = { { 1.0, 0.0, 0.0 },
929 { 0.447213595500, 0.894427191000, 0.0 }, { 0.447213595500, 0.276393202252, 0.850650808354 }, { 0.447213595500, -0.723606797748, 0.525731112119 }, { 0.447213595500, -0.723606797748, -0.525731112119 }, { 0.447213595500, 0.276393202252, -0.850650808354 },
930 { -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 },
931 { -1.0, 0.0, 0.0 } } ;
932 int icos_v [20][3] = { { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 5 }, { 0, 5, 1 },
933 { 1, 8, 2 }, { 2, 7, 3 }, { 3, 6, 4 }, { 4, 10, 5 }, { 5, 9, 1 },
934 { 1, 9, 8 }, { 2, 8, 7 }, { 3, 7, 6 }, { 4, 6, 10 }, { 5, 10, 9 },
935 { 11, 9, 10 }, { 11, 8, 9 }, { 11, 7, 8 }, { 11, 6, 7 }, { 11, 10, 6 } } ;
937 void FGAPIENTRY glutWireIcosahedron( void )
940 for ( i = 0; i < 20; i++ )
943 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] ) ;
944 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] ) ;
945 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] ) ;
946 glBegin ( GL_LINE_LOOP ) ;
947 glNormal3dv ( normal ) ;
948 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
949 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
950 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
958 void FGAPIENTRY glutSolidIcosahedron( void )
962 glBegin ( GL_TRIANGLES ) ;
963 for ( i = 0; i < 20; i++ )
966 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] ) ;
967 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] ) ;
968 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] ) ;
969 glNormal3dv ( normal ) ;
970 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
971 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
972 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
981 double rdod_r[14][3] = { { 0.0, 0.0, 1.0 },
982 { 0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, 0.707106781187, 0.5 }, { -0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, -0.707106781187, 0.5 },
983 { 0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, -0.707106781187, 0.0 }, { 0.707106781187, -0.707106781187, 0.0 },
984 { 0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, 0.707106781187, -0.5 }, { -0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, -0.707106781187, -0.5 },
985 { 0.0, 0.0, -1.0 } } ;
986 int rdod_v [12][4] = { { 0, 1, 5, 2 }, { 0, 2, 6, 3 }, { 0, 3, 7, 4 }, { 0, 4, 8, 1 },
987 { 5, 10, 6, 2 }, { 6, 11, 7, 3 }, { 7, 12, 8, 4 }, { 8, 9, 5, 1 },
988 { 5, 9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ;
989 double rdod_n[12][3] = {
990 { 0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, -0.353553390594, 0.5 }, { 0.353553390594, -0.353553390594, 0.5 },
991 { 0.000000000000, 1.000000000000, 0.0 }, { -1.000000000000, 0.000000000000, 0.0 }, { 0.000000000000, -1.000000000000, 0.0 }, { 1.000000000000, 0.000000000000, 0.0 },
992 { 0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, { 0.353553390594, -0.353553390594, -0.5 }
995 void FGAPIENTRY glutWireRhombicDodecahedron( void )
998 for ( i = 0; i < 12; i++ )
1000 glBegin ( GL_LINE_LOOP ) ;
1001 glNormal3dv ( rdod_n[i] ) ;
1002 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1003 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1004 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1005 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1013 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1017 glBegin ( GL_QUADS ) ;
1018 for ( i = 0; i < 12; i++ )
1020 glNormal3dv ( rdod_n[i] ) ;
1021 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1022 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1023 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1024 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1032 static GLdouble tetrahedron_v[4][3] = /* Vertices */
1034 { -0.5, -0.288675134595, -0.144337567297 },
1035 { 0.5, -0.288675134595, -0.144337567297 },
1036 { 0.0, 0.577350269189, -0.144337567297 },
1037 { 0.0, 0.0, 0.672159013631 }
1040 static GLint tetrahedron_i[4][3] = /* Vertex indices */
1042 { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 1, 3, 2 }
1045 static GLdouble tetrahedron_n[4][3] = /* Normals */
1048 { -0.816496580928, 0.471404520791, 0.333333333333 },
1049 { 0.0, -0.942809041582, 0.333333333333 },
1050 { 0.816496580928, 0.471404520791, 0.333333333333 }
1053 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1057 if ( num_levels == 0 )
1060 for ( i = 0 ; i < NUM_FACES ; i++ )
1062 glBegin ( GL_LINE_LOOP ) ;
1063 glNormal3dv ( tetrahedron_n[i] ) ;
1064 for ( j = 0; j < 3; j++ )
1066 double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
1067 double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
1068 double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
1069 glVertex3d ( x, y, z ) ;
1077 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1080 local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
1081 local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
1082 local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
1083 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1084 local_offset[0] += scale ;
1085 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1086 local_offset[0] -= 0.5 * scale ;
1087 local_offset[1] += 0.866025403784 * scale ;
1088 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1089 local_offset[1] -= 0.577350269189 * scale ;
1090 local_offset[2] += 0.816496580928 * scale ;
1091 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1095 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1099 if ( num_levels == 0 )
1101 glBegin ( GL_TRIANGLES ) ;
1103 for ( i = 0 ; i < NUM_FACES ; i++ )
1105 glNormal3dv ( tetrahedron_n[i] ) ;
1106 for ( j = 0; j < 3; j++ )
1108 double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
1109 double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
1110 double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
1111 glVertex3d ( x, y, z ) ;
1119 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1122 local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
1123 local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
1124 local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
1125 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1126 local_offset[0] += scale ;
1127 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1128 local_offset[0] -= 0.5 * scale ;
1129 local_offset[1] += 0.866025403784 * scale ;
1130 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1131 local_offset[1] -= 0.577350269189 * scale ;
1132 local_offset[2] += 0.816496580928 * scale ;
1133 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1139 /*** END OF FILE ***/