themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / freeglut_geometry.cxx
blobd11c9ef38f5dac9fef2561f38c719fa4bf85c98a
1 /*
2 * freeglut_geometry.c
4 * Freeglut geometry rendering methods.
6 * Copyright (c) 1999-2010 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 <FL/glut.H>
29 #include <FL/math.h>
30 #include <stdlib.h>
33 * TODO BEFORE THE STABLE RELEASE:
35 * Following functions have been contributed by Andreas Umbach.
37 * glutWireCube() -- looks OK
38 * glutSolidCube() -- OK
40 * Those functions have been implemented by John Fay.
42 * glutWireTorus() -- looks OK
43 * glutSolidTorus() -- looks OK
44 * glutWireDodecahedron() -- looks OK
45 * glutSolidDodecahedron() -- looks OK
46 * glutWireOctahedron() -- looks OK
47 * glutSolidOctahedron() -- looks OK
48 * glutWireTetrahedron() -- looks OK
49 * glutSolidTetrahedron() -- looks OK
50 * glutWireIcosahedron() -- looks OK
51 * glutSolidIcosahedron() -- looks OK
53 * The Following functions have been updated by Nigel Stewart, based
54 * on FreeGLUT 2.0.0 implementations:
56 * glutWireSphere() -- looks OK
57 * glutSolidSphere() -- looks OK
58 * glutWireCone() -- looks OK
59 * glutSolidCone() -- looks OK
63 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
66 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
68 void glutWireCube( GLdouble dSize )
70 double size = dSize * 0.5;
72 # define V(a,b,c) glVertex3d( a size, b size, c size );
73 # define N(a,b,c) glNormal3d( a, b, c );
75 /* PWO: I dared to convert the code to use macros... */
76 glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
77 glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
78 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
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();
83 # undef V
84 # undef N
88 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
90 void glutSolidCube( GLdouble dSize )
92 double size = dSize * 0.5;
94 # define V(a,b,c) glVertex3d( a size, b size, c size );
95 # define N(a,b,c) glNormal3d( a, b, c );
97 /* PWO: Again, I dared to convert the code to use macros... */
98 glBegin( GL_QUADS );
99 N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+);
100 N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+);
101 N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+);
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 glEnd();
107 # undef V
108 # undef N
112 * Compute lookup table of cos and sin values forming a cirle
114 * Notes:
115 * It is the responsibility of the caller to free these tables
116 * The size of the table is (n+1) to form a connected loop
117 * The last entry is exactly the same as the first
118 * The sign of n can be flipped to get the reverse loop
121 static void fghCircleTable(double **sint,double **cost,const int n)
123 int i;
125 /* Table size, the sign of n flips the circle direction */
127 const int size = abs(n);
129 /* Determine the angle between samples */
131 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
133 /* Allocate memory for n samples, plus duplicate of first entry at the end */
135 *sint = (double *) calloc(sizeof(double), size+1);
136 *cost = (double *) calloc(sizeof(double), size+1);
138 /* Bail out if memory allocation fails, fgError never returns */
140 if (!(*sint) || !(*cost))
142 if (*sint) free(*sint);
143 if (*cost) free(*cost);
144 return;
147 /* Compute cos and sin around the circle */
149 (*sint)[0] = 0.0;
150 (*cost)[0] = 1.0;
152 for (i=1; 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 glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
169 int i,j;
171 /* Adjust z and radius as stacks are drawn. */
173 double z0,z1;
174 double r0,r1;
176 /* Pre-computed circle */
178 double *sint1,*cost1;
179 double *sint2,*cost2;
181 fghCircleTable(&sint1,&cost1,-slices);
182 fghCircleTable(&sint2,&cost2,stacks*2);
184 /* The top stack is covered with a triangle fan */
186 z0 = 1.0;
187 z1 = cost2[(stacks>0)?1:0];
188 r0 = 0.0;
189 r1 = sint2[(stacks>0)?1:0];
191 glBegin(GL_TRIANGLE_FAN);
193 glNormal3d(0,0,1);
194 glVertex3d(0,0,radius);
196 for (j=slices; j>=0; j--)
198 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
199 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
202 glEnd();
204 /* Cover each stack with a quad strip, except the top and bottom stacks */
206 for( i=1; i<stacks-1; i++ )
208 z0 = z1; z1 = cost2[i+1];
209 r0 = r1; r1 = sint2[i+1];
211 glBegin(GL_QUAD_STRIP);
213 for(j=0; j<=slices; j++)
215 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
216 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
217 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
218 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
221 glEnd();
224 /* The bottom stack is covered with a triangle fan */
226 z0 = z1;
227 r0 = r1;
229 glBegin(GL_TRIANGLE_FAN);
231 glNormal3d(0,0,-1);
232 glVertex3d(0,0,-radius);
234 for (j=0; j<=slices; j++)
236 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
237 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
240 glEnd();
242 /* Release sin and cos tables */
244 free(sint1);
245 free(cost1);
246 free(sint2);
247 free(cost2);
251 * Draws a wire sphere
253 void glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
255 int i,j;
257 /* Adjust z and radius as stacks and slices are drawn. */
259 double r;
260 double x,y,z;
262 /* Pre-computed circle */
264 double *sint1,*cost1;
265 double *sint2,*cost2;
267 fghCircleTable(&sint1,&cost1,-slices );
268 fghCircleTable(&sint2,&cost2, stacks*2);
270 /* Draw a line loop for each stack */
272 for (i=1; i<stacks; i++)
274 z = cost2[i];
275 r = sint2[i];
277 glBegin(GL_LINE_LOOP);
279 for(j=0; j<=slices; j++)
281 x = cost1[j];
282 y = sint1[j];
284 glNormal3d(x,y,z);
285 glVertex3d(x*r*radius,y*r*radius,z*radius);
288 glEnd();
291 /* Draw a line loop for each slice */
293 for (i=0; i<slices; i++)
295 glBegin(GL_LINE_STRIP);
297 for(j=0; j<=stacks; j++)
299 x = cost1[i]*sint2[j];
300 y = sint1[i]*sint2[j];
301 z = cost2[j];
303 glNormal3d(x,y,z);
304 glVertex3d(x*radius,y*radius,z*radius);
307 glEnd();
310 /* Release sin and cos tables */
312 free(sint1);
313 free(cost1);
314 free(sint2);
315 free(cost2);
319 * Draws a solid cone
321 void glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
323 int i,j;
325 /* Step in z and radius as stacks are drawn. */
327 double z0,z1;
328 double r0,r1;
330 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
331 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
333 /* Scaling factors for vertex normals */
335 const double cosn = ( height / sqrt ( height * height + base * base ));
336 const double sinn = ( base / sqrt ( height * height + base * base ));
338 /* Pre-computed circle */
340 double *sint,*cost;
342 fghCircleTable(&sint,&cost,-slices);
344 /* Cover the circular base with a triangle fan... */
346 z0 = 0.0;
347 z1 = zStep;
349 r0 = base;
350 r1 = r0 - rStep;
352 glBegin(GL_TRIANGLE_FAN);
354 glNormal3d(0.0,0.0,-1.0);
355 glVertex3d(0.0,0.0, z0 );
357 for (j=0; j<=slices; j++)
358 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
360 glEnd();
362 /* Cover each stack with a quad strip, except the top stack */
364 for( i=0; i<stacks-1; i++ )
366 glBegin(GL_QUAD_STRIP);
368 for(j=0; j<=slices; j++)
370 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
371 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
372 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
375 z0 = z1; z1 += zStep;
376 r0 = r1; r1 -= rStep;
378 glEnd();
381 /* The top stack is covered with individual triangles */
383 glBegin(GL_TRIANGLES);
385 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
387 for (j=0; j<slices; j++)
389 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
390 glVertex3d(0, 0, height);
391 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
392 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
395 glEnd();
397 /* Release sin and cos tables */
399 free(sint);
400 free(cost);
404 * Draws a wire cone
406 void glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
408 int i,j;
410 /* Step in z and radius as stacks are drawn. */
412 double z = 0.0;
413 double r = base;
415 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
416 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
418 /* Scaling factors for vertex normals */
420 const double cosn = ( height / sqrt ( height * height + base * base ));
421 const double sinn = ( base / sqrt ( height * height + base * base ));
423 /* Pre-computed circle */
425 double *sint,*cost;
427 fghCircleTable(&sint,&cost,-slices);
429 /* Draw the stacks... */
431 for (i=0; i<stacks; i++)
433 glBegin(GL_LINE_LOOP);
435 for( j=0; j<slices; j++ )
437 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
438 glVertex3d(cost[j]*r, sint[j]*r, z );
441 glEnd();
443 z += zStep;
444 r -= rStep;
447 /* Draw the slices */
449 r = base;
451 glBegin(GL_LINES);
453 for (j=0; j<slices; j++)
455 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
456 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
457 glVertex3d(0.0, 0.0, height);
460 glEnd();
462 /* Release sin and cos tables */
464 free(sint);
465 free(cost);
470 * Draws a solid cylinder
472 void glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
474 int i,j;
476 /* Step in z and radius as stacks are drawn. */
478 double z0,z1;
479 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
481 /* Pre-computed circle */
483 double *sint,*cost;
485 fghCircleTable(&sint,&cost,-slices);
487 /* Cover the base and top */
489 glBegin(GL_TRIANGLE_FAN);
490 glNormal3d(0.0, 0.0, -1.0 );
491 glVertex3d(0.0, 0.0, 0.0 );
492 for (j=0; j<=slices; j++)
493 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
494 glEnd();
496 glBegin(GL_TRIANGLE_FAN);
497 glNormal3d(0.0, 0.0, 1.0 );
498 glVertex3d(0.0, 0.0, height);
499 for (j=slices; j>=0; j--)
500 glVertex3d(cost[j]*radius, sint[j]*radius, height);
501 glEnd();
503 /* Do the stacks */
505 z0 = 0.0;
506 z1 = zStep;
508 for (i=1; i<=stacks; i++)
510 if (i==stacks)
511 z1 = height;
513 glBegin(GL_QUAD_STRIP);
514 for (j=0; j<=slices; j++ )
516 glNormal3d(cost[j], sint[j], 0.0 );
517 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
518 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
520 glEnd();
522 z0 = z1; z1 += zStep;
525 /* Release sin and cos tables */
527 free(sint);
528 free(cost);
532 * Draws a wire cylinder
534 void glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
536 int i,j;
538 /* Step in z and radius as stacks are drawn. */
540 double z = 0.0;
541 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
543 /* Pre-computed circle */
545 double *sint,*cost;
547 fghCircleTable(&sint,&cost,-slices);
549 /* Draw the stacks... */
551 for (i=0; i<=stacks; i++)
553 if (i==stacks)
554 z = height;
556 glBegin(GL_LINE_LOOP);
558 for( j=0; j<slices; j++ )
560 glNormal3d(cost[j], sint[j], 0.0);
561 glVertex3d(cost[j]*radius, sint[j]*radius, z );
564 glEnd();
566 z += zStep;
569 /* Draw the slices */
571 glBegin(GL_LINES);
573 for (j=0; j<slices; j++)
575 glNormal3d(cost[j], sint[j], 0.0 );
576 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
577 glVertex3d(cost[j]*radius, sint[j]*radius, height);
580 glEnd();
582 /* Release sin and cos tables */
584 free(sint);
585 free(cost);
589 * Draws a wire torus
591 void glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
593 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
594 double *vertex, *normal;
595 int i, j;
596 double spsi, cpsi, sphi, cphi ;
598 if ( nSides < 1 ) nSides = 1;
599 if ( nRings < 1 ) nRings = 1;
601 /* Allocate the vertices array */
602 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
603 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
605 glPushMatrix();
607 dpsi = 2.0 * M_PI / (double)nRings ;
608 dphi = -2.0 * M_PI / (double)nSides ;
609 psi = 0.0;
611 for( j=0; j<nRings; j++ )
613 cpsi = cos ( psi ) ;
614 spsi = sin ( psi ) ;
615 phi = 0.0;
617 for( i=0; i<nSides; i++ )
619 int offset = 3 * ( j * nSides + i ) ;
620 cphi = cos ( phi ) ;
621 sphi = sin ( phi ) ;
622 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
623 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
624 *(vertex + offset + 2) = sphi * iradius ;
625 *(normal + offset + 0) = cpsi * cphi ;
626 *(normal + offset + 1) = spsi * cphi ;
627 *(normal + offset + 2) = sphi ;
628 phi += dphi;
631 psi += dpsi;
634 for( i=0; i<nSides; i++ )
636 glBegin( GL_LINE_LOOP );
638 for( j=0; j<nRings; j++ )
640 int offset = 3 * ( j * nSides + i ) ;
641 glNormal3dv( normal + offset );
642 glVertex3dv( vertex + offset );
645 glEnd();
648 for( j=0; j<nRings; j++ )
650 glBegin(GL_LINE_LOOP);
652 for( i=0; i<nSides; i++ )
654 int offset = 3 * ( j * nSides + i ) ;
655 glNormal3dv( normal + offset );
656 glVertex3dv( vertex + offset );
659 glEnd();
662 free ( vertex ) ;
663 free ( normal ) ;
664 glPopMatrix();
668 * Draws a solid torus
670 void glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
672 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
673 double *vertex, *normal;
674 int i, j;
675 double spsi, cpsi, sphi, cphi ;
677 if ( nSides < 1 ) nSides = 1;
678 if ( nRings < 1 ) nRings = 1;
680 /* Increment the number of sides and rings to allow for one more point than surface */
681 nSides ++ ;
682 nRings ++ ;
684 /* Allocate the vertices array */
685 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
686 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
688 glPushMatrix();
690 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
691 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
692 psi = 0.0;
694 for( j=0; j<nRings; j++ )
696 cpsi = cos ( psi ) ;
697 spsi = sin ( psi ) ;
698 phi = 0.0;
700 for( i=0; i<nSides; i++ )
702 int offset = 3 * ( j * nSides + i ) ;
703 cphi = cos ( phi ) ;
704 sphi = sin ( phi ) ;
705 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
706 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
707 *(vertex + offset + 2) = sphi * iradius ;
708 *(normal + offset + 0) = cpsi * cphi ;
709 *(normal + offset + 1) = spsi * cphi ;
710 *(normal + offset + 2) = sphi ;
711 phi += dphi;
714 psi += dpsi;
717 glBegin( GL_QUADS );
718 for( i=0; i<nSides-1; i++ )
720 for( j=0; j<nRings-1; j++ )
722 int offset = 3 * ( j * nSides + i ) ;
723 glNormal3dv( normal + offset );
724 glVertex3dv( vertex + offset );
725 glNormal3dv( normal + offset + 3 );
726 glVertex3dv( vertex + offset + 3 );
727 glNormal3dv( normal + offset + 3 * nSides + 3 );
728 glVertex3dv( vertex + offset + 3 * nSides + 3 );
729 glNormal3dv( normal + offset + 3 * nSides );
730 glVertex3dv( vertex + offset + 3 * nSides );
734 glEnd();
736 free ( vertex ) ;
737 free ( normal ) ;
738 glPopMatrix();
744 void glutWireDodecahedron( void )
746 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
747 * of a cube. The coordinates of the points are:
748 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
749 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
750 * x = 0.61803398875 and z = 1.61803398875.
752 glBegin ( GL_LINE_LOOP ) ;
753 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 ) ;
754 glEnd () ;
755 glBegin ( GL_LINE_LOOP ) ;
756 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 ) ;
757 glEnd () ;
758 glBegin ( GL_LINE_LOOP ) ;
759 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 ) ;
760 glEnd () ;
761 glBegin ( GL_LINE_LOOP ) ;
762 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 ) ;
763 glEnd () ;
765 glBegin ( GL_LINE_LOOP ) ;
766 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 ) ;
767 glEnd () ;
768 glBegin ( GL_LINE_LOOP ) ;
769 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 ) ;
770 glEnd () ;
771 glBegin ( GL_LINE_LOOP ) ;
772 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 ) ;
773 glEnd () ;
774 glBegin ( GL_LINE_LOOP ) ;
775 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 ) ;
776 glEnd () ;
778 glBegin ( GL_LINE_LOOP ) ;
779 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 ) ;
780 glEnd () ;
781 glBegin ( GL_LINE_LOOP ) ;
782 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 glEnd () ;
784 glBegin ( GL_LINE_LOOP ) ;
785 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 ) ;
786 glEnd () ;
787 glBegin ( GL_LINE_LOOP ) ;
788 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 ) ;
789 glEnd () ;
795 void glutSolidDodecahedron( void )
797 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
798 * of a cube. The coordinates of the points are:
799 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
800 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
801 * x = 0.61803398875 and z = 1.61803398875.
803 glBegin ( GL_POLYGON ) ;
804 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 ) ;
805 glEnd () ;
806 glBegin ( GL_POLYGON ) ;
807 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 ) ;
808 glEnd () ;
809 glBegin ( GL_POLYGON ) ;
810 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 ) ;
811 glEnd () ;
812 glBegin ( GL_POLYGON ) ;
813 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 ) ;
814 glEnd () ;
816 glBegin ( GL_POLYGON ) ;
817 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 ) ;
818 glEnd () ;
819 glBegin ( GL_POLYGON ) ;
820 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 ) ;
821 glEnd () ;
822 glBegin ( GL_POLYGON ) ;
823 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 ) ;
824 glEnd () ;
825 glBegin ( GL_POLYGON ) ;
826 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 ) ;
827 glEnd () ;
829 glBegin ( GL_POLYGON ) ;
830 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 ) ;
831 glEnd () ;
832 glBegin ( GL_POLYGON ) ;
833 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 glEnd () ;
835 glBegin ( GL_POLYGON ) ;
836 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 ) ;
837 glEnd () ;
838 glBegin ( GL_POLYGON ) ;
839 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 ) ;
840 glEnd () ;
846 void glutWireOctahedron( void )
848 #define RADIUS 1.0f
849 glBegin( GL_LINE_LOOP );
850 glNormal3d( 0.577350269189, 0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, RADIUS, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS );
851 glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
852 glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
853 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 );
854 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 );
855 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 );
856 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 );
857 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 );
858 glEnd();
859 #undef RADIUS
865 void glutSolidOctahedron( void )
867 #define RADIUS 1.0f
868 glBegin( GL_TRIANGLES );
869 glNormal3d( 0.577350269189, 0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, RADIUS, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS );
870 glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
871 glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
872 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 );
873 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 );
874 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 );
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 glEnd();
878 #undef RADIUS
881 /* Magic Numbers: r0 = ( 1, 0, 0 )
882 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
883 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
884 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
885 * |r0| = |r1| = |r2| = |r3| = 1
886 * Distance between any two points is 2 sqrt(6) / 3
888 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
891 #define NUM_TETR_FACES 4
893 static GLdouble tet_r[4][3] = { { 1.0, 0.0, 0.0 },
894 { -0.333333333333, 0.942809041582, 0.0 },
895 { -0.333333333333, -0.471404520791, 0.816496580928 },
896 { -0.333333333333, -0.471404520791, -0.816496580928 } } ;
898 static GLint tet_i[4][3] = /* Vertex indices */
900 { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
906 void glutWireTetrahedron( void )
908 glBegin( GL_LINE_LOOP ) ;
909 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] ) ;
910 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] ) ;
911 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] ) ;
912 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] ) ;
913 glEnd() ;
919 void glutSolidTetrahedron( void )
921 glBegin( GL_TRIANGLES ) ;
922 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] ) ;
923 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] ) ;
924 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] ) ;
925 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] ) ;
926 glEnd() ;
932 double icos_r[12][3] = { { 1.0, 0.0, 0.0 },
933 { 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 },
934 { -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 },
935 { -1.0, 0.0, 0.0 } } ;
936 int icos_v [20][3] = { { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 5 }, { 0, 5, 1 },
937 { 1, 8, 2 }, { 2, 7, 3 }, { 3, 6, 4 }, { 4, 10, 5 }, { 5, 9, 1 },
938 { 1, 9, 8 }, { 2, 8, 7 }, { 3, 7, 6 }, { 4, 6, 10 }, { 5, 10, 9 },
939 { 11, 9, 10 }, { 11, 8, 9 }, { 11, 7, 8 }, { 11, 6, 7 }, { 11, 10, 6 } } ;
941 void glutWireIcosahedron( void )
943 int i ;
945 for ( i = 0; i < 20; i++ )
947 double normal[3] ;
948 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] ) ;
949 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] ) ;
950 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] ) ;
951 glBegin ( GL_LINE_LOOP ) ;
952 glNormal3dv ( normal ) ;
953 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
954 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
955 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
956 glEnd () ;
963 void glutSolidIcosahedron( void )
965 int i ;
967 glBegin ( GL_TRIANGLES ) ;
968 for ( i = 0; i < 20; i++ )
970 double normal[3] ;
971 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] ) ;
972 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] ) ;
973 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] ) ;
974 glNormal3dv ( normal ) ;
975 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
976 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
977 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
980 glEnd () ;
986 double rdod_r[14][3] = { { 0.0, 0.0, 1.0 },
987 { 0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, 0.707106781187, 0.5 }, { -0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, -0.707106781187, 0.5 },
988 { 0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, -0.707106781187, 0.0 }, { 0.707106781187, -0.707106781187, 0.0 },
989 { 0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, 0.707106781187, -0.5 }, { -0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, -0.707106781187, -0.5 },
990 { 0.0, 0.0, -1.0 } } ;
991 int rdod_v [12][4] = { { 0, 1, 5, 2 }, { 0, 2, 6, 3 }, { 0, 3, 7, 4 }, { 0, 4, 8, 1 },
992 { 5, 10, 6, 2 }, { 6, 11, 7, 3 }, { 7, 12, 8, 4 }, { 8, 9, 5, 1 },
993 { 5, 9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ;
994 double rdod_n[12][3] = {
995 { 0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, -0.353553390594, 0.5 }, { 0.353553390594, -0.353553390594, 0.5 },
996 { 0.000000000000, 1.000000000000, 0.0 }, { -1.000000000000, 0.000000000000, 0.0 }, { 0.000000000000, -1.000000000000, 0.0 }, { 1.000000000000, 0.000000000000, 0.0 },
997 { 0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, { 0.353553390594, -0.353553390594, -0.5 }
1000 void glutWireRhombicDodecahedron( void )
1002 int i ;
1004 for ( i = 0; i < 12; i++ )
1006 glBegin ( GL_LINE_LOOP ) ;
1007 glNormal3dv ( rdod_n[i] ) ;
1008 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1009 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1010 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1011 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1012 glEnd () ;
1019 void glutSolidRhombicDodecahedron( void )
1021 int i ;
1023 glBegin ( GL_QUADS ) ;
1024 for ( i = 0; i < 12; i++ )
1026 glNormal3dv ( rdod_n[i] ) ;
1027 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1028 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1029 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1030 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1033 glEnd () ;
1036 void glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1038 int i, j ;
1040 if ( num_levels == 0 )
1043 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1045 glBegin ( GL_LINE_LOOP ) ;
1046 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1047 for ( j = 0; j < 3; j++ )
1049 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1050 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1051 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1052 glVertex3d ( x, y, z ) ;
1055 glEnd () ;
1058 else
1060 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1061 num_levels -- ;
1062 scale /= 2.0 ;
1063 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1065 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1066 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1067 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1068 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1073 void glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1075 int i, j ;
1077 if ( num_levels == 0 )
1079 glBegin ( GL_TRIANGLES ) ;
1081 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1083 glNormal3d ( -tet_r[i][0], -tet_r[i][1], -tet_r[i][2] ) ;
1084 for ( j = 0; j < 3; j++ )
1086 double x = offset[0] + scale * tet_r[tet_i[i][j]][0] ;
1087 double y = offset[1] + scale * tet_r[tet_i[i][j]][1] ;
1088 double z = offset[2] + scale * tet_r[tet_i[i][j]][2] ;
1089 glVertex3d ( x, y, z ) ;
1093 glEnd () ;
1095 else
1097 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1098 num_levels -- ;
1099 scale /= 2.0 ;
1100 for ( i = 0 ; i < NUM_TETR_FACES ; i++ )
1102 local_offset[0] = offset[0] + scale * tet_r[i][0] ;
1103 local_offset[1] = offset[1] + scale * tet_r[i][1] ;
1104 local_offset[2] = offset[2] + scale * tet_r[i][2] ;
1105 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1110 /*** END OF FILE ***/