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.
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();
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... */
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(+,-,-);
112 * Compute lookup table of cos and sin values forming a cirle
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
)
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
);
147 /* Compute cos and sin around the circle */
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
)
171 /* Adjust z and radius as stacks are drawn. */
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 */
187 z1
= cost2
[(stacks
>0)?1:0];
189 r1
= sint2
[(stacks
>0)?1:0];
191 glBegin(GL_TRIANGLE_FAN
);
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
);
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
);
224 /* The bottom stack is covered with a triangle fan */
229 glBegin(GL_TRIANGLE_FAN
);
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
);
242 /* Release sin and cos tables */
251 * Draws a wire sphere
253 void glutWireSphere(GLdouble radius
, GLint slices
, GLint stacks
)
257 /* Adjust z and radius as stacks and slices are drawn. */
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
++)
277 glBegin(GL_LINE_LOOP
);
279 for(j
=0; j
<=slices
; j
++)
285 glVertex3d(x
*r
*radius
,y
*r
*radius
,z
*radius
);
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
];
304 glVertex3d(x
*radius
,y
*radius
,z
*radius
);
310 /* Release sin and cos tables */
321 void glutSolidCone( GLdouble base
, GLdouble height
, GLint slices
, GLint stacks
)
325 /* Step in z and radius as stacks are drawn. */
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 */
342 fghCircleTable(&sint
,&cost
,-slices
);
344 /* Cover the circular base with a triangle fan... */
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
);
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
;
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
);
397 /* Release sin and cos tables */
406 void glutWireCone( GLdouble base
, GLdouble height
, GLint slices
, GLint stacks
)
410 /* Step in z and radius as stacks are drawn. */
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 */
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
);
447 /* Draw the slices */
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
);
462 /* Release sin and cos tables */
470 * Draws a solid cylinder
472 void glutSolidCylinder(GLdouble radius
, GLdouble height
, GLint slices
, GLint stacks
)
476 /* Step in z and radius as stacks are drawn. */
479 const double zStep
= height
/ ( ( stacks
> 0 ) ? stacks
: 1 );
481 /* Pre-computed circle */
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);
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
);
508 for (i
=1; i
<=stacks
; i
++)
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
);
522 z0
= z1
; z1
+= zStep
;
525 /* Release sin and cos tables */
532 * Draws a wire cylinder
534 void glutWireCylinder(GLdouble radius
, GLdouble height
, GLint slices
, GLint stacks
)
538 /* Step in z and radius as stacks are drawn. */
541 const double zStep
= height
/ ( ( stacks
> 0 ) ? stacks
: 1 );
543 /* Pre-computed circle */
547 fghCircleTable(&sint
,&cost
,-slices
);
549 /* Draw the stacks... */
551 for (i
=0; i
<=stacks
; i
++)
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
);
569 /* Draw the slices */
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
);
582 /* Release sin and cos tables */
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
;
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
);
607 dpsi
= 2.0 * M_PI
/ (double)nRings
;
608 dphi
= -2.0 * M_PI
/ (double)nSides
;
611 for( j
=0; j
<nRings
; j
++ )
617 for( i
=0; i
<nSides
; i
++ )
619 int offset
= 3 * ( j
* nSides
+ i
) ;
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
;
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
);
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
);
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
;
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 */
684 /* Allocate the vertices array */
685 vertex
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
686 normal
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
690 dpsi
= 2.0 * M_PI
/ (double)(nRings
- 1) ;
691 dphi
= -2.0 * M_PI
/ (double)(nSides
- 1) ;
694 for( j
=0; j
<nRings
; j
++ )
700 for( i
=0; i
<nSides
; i
++ )
702 int offset
= 3 * ( j
* nSides
+ i
) ;
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
;
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
);
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
846 void glutWireOctahedron( void )
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 );
865 void glutSolidOctahedron( void )
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 );
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] ) ;
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] ) ;
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 )
945 for ( i
= 0; i
< 20; i
++ )
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]] ) ;
963 void glutSolidIcosahedron( void )
967 glBegin ( GL_TRIANGLES
) ;
968 for ( i
= 0; i
< 20; i
++ )
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]] ) ;
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 )
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]] ) ;
1019 void glutSolidRhombicDodecahedron( void )
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]] ) ;
1036 void glutWireSierpinskiSponge ( int num_levels
, GLdouble offset
[3], GLdouble scale
)
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
) ;
1060 GLdouble local_offset
[3] ; /* Use a local variable to avoid buildup of roundoff errors */
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
)
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
) ;
1097 GLdouble local_offset
[3] ; /* Use a local variable to avoid buildup of roundoff errors */
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 ***/