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 * TODO BEFORE THE STABLE RELEASE:
34 * Following functions have been contributed by Andreas Umbach.
36 * glutWireCube() -- looks OK
37 * glutSolidCube() -- OK
39 * Those functions have been implemented by John Fay.
41 * glutWireTorus() -- looks OK
42 * glutSolidTorus() -- looks OK
43 * glutWireDodecahedron() -- looks OK
44 * glutSolidDodecahedron() -- looks OK
45 * glutWireOctahedron() -- looks OK
46 * glutSolidOctahedron() -- looks OK
47 * glutWireTetrahedron() -- looks OK
48 * glutSolidTetrahedron() -- looks OK
49 * glutWireIcosahedron() -- looks OK
50 * glutSolidIcosahedron() -- looks OK
52 * The Following functions have been updated by Nigel Stewart, based
53 * on FreeGLUT 2.0.0 implementations:
55 * glutWireSphere() -- looks OK
56 * glutSolidSphere() -- looks OK
57 * glutWireCone() -- looks OK
58 * glutSolidCone() -- looks OK
62 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
65 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
67 void GLUTAPIENTRY
glutWireCube( GLdouble dSize
)
69 double size
= dSize
* 0.5;
71 # define V(a,b,c) glVertex3d( a size, b size, c size );
72 # define N(a,b,c) glNormal3d( a, b, c );
75 * PWO: I dared to convert the code to use macros...
77 glBegin( GL_LINE_LOOP
); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
78 glBegin( GL_LINE_LOOP
); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
79 glBegin( GL_LINE_LOOP
); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
80 glBegin( GL_LINE_LOOP
); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
81 glBegin( GL_LINE_LOOP
); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
82 glBegin( GL_LINE_LOOP
); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
89 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
91 void GLUTAPIENTRY
glutSolidCube( GLdouble dSize
)
93 double size
= dSize
* 0.5;
95 # define V(a,b,c) glVertex3d( a size, b size, c size );
96 # define N(a,b,c) glNormal3d( a, b, c );
99 * 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 _glut_fatal("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 GLUTAPIENTRY
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 solid sphere
252 void GLUTAPIENTRY
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 GLUTAPIENTRY
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 GLUTAPIENTRY
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 GLUTAPIENTRY
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 GLUTAPIENTRY
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 GLUTAPIENTRY
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
;
593 * Allocate the vertices array
595 vertex
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
596 normal
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
600 dpsi
= 2.0 * M_PI
/ (double)nRings
;
601 dphi
= -2.0 * M_PI
/ (double)nSides
;
604 for( j
=0; j
<nRings
; j
++ )
610 for( i
=0; i
<nSides
; i
++ )
612 int offset
= 3 * ( j
* nSides
+ i
) ;
615 *(vertex
+ offset
+ 0) = cpsi
* ( oradius
+ cphi
* iradius
) ;
616 *(vertex
+ offset
+ 1) = spsi
* ( oradius
+ cphi
* iradius
) ;
617 *(vertex
+ offset
+ 2) = sphi
* iradius
;
618 *(normal
+ offset
+ 0) = cpsi
* cphi
;
619 *(normal
+ offset
+ 1) = spsi
* cphi
;
620 *(normal
+ offset
+ 2) = sphi
;
627 for( i
=0; i
<nSides
; i
++ )
629 glBegin( GL_LINE_LOOP
);
631 for( j
=0; j
<nRings
; j
++ )
633 int offset
= 3 * ( j
* nSides
+ i
) ;
634 glNormal3dv( normal
+ offset
);
635 glVertex3dv( vertex
+ offset
);
641 for( j
=0; j
<nRings
; j
++ )
643 glBegin(GL_LINE_LOOP
);
645 for( i
=0; i
<nSides
; i
++ )
647 int offset
= 3 * ( j
* nSides
+ i
) ;
648 glNormal3dv( normal
+ offset
);
649 glVertex3dv( vertex
+ offset
);
663 void GLUTAPIENTRY
glutSolidTorus( GLdouble dInnerRadius
, GLdouble dOuterRadius
, GLint nSides
, GLint nRings
)
665 double iradius
= dInnerRadius
, oradius
= dOuterRadius
, phi
, psi
, dpsi
, dphi
;
666 double *vertex
, *normal
;
668 double spsi
, cpsi
, sphi
, cphi
;
671 * Increment the number of sides and rings to allow for one more point than surface
677 * Allocate the vertices array
679 vertex
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
680 normal
= (double *)calloc( sizeof(double), 3 * nSides
* nRings
);
684 dpsi
= 2.0 * M_PI
/ (double)(nRings
- 1) ;
685 dphi
= -2.0 * M_PI
/ (double)(nSides
- 1) ;
688 for( j
=0; j
<nRings
; j
++ )
694 for( i
=0; i
<nSides
; i
++ )
696 int offset
= 3 * ( j
* nSides
+ i
) ;
699 *(vertex
+ offset
+ 0) = cpsi
* ( oradius
+ cphi
* iradius
) ;
700 *(vertex
+ offset
+ 1) = spsi
* ( oradius
+ cphi
* iradius
) ;
701 *(vertex
+ offset
+ 2) = sphi
* iradius
;
702 *(normal
+ offset
+ 0) = cpsi
* cphi
;
703 *(normal
+ offset
+ 1) = spsi
* cphi
;
704 *(normal
+ offset
+ 2) = sphi
;
712 for( i
=0; i
<nSides
-1; i
++ )
714 for( j
=0; j
<nRings
-1; j
++ )
716 int offset
= 3 * ( j
* nSides
+ i
) ;
717 glNormal3dv( normal
+ offset
);
718 glVertex3dv( vertex
+ offset
);
719 glNormal3dv( normal
+ offset
+ 3 );
720 glVertex3dv( vertex
+ offset
+ 3 );
721 glNormal3dv( normal
+ offset
+ 3 * nSides
+ 3 );
722 glVertex3dv( vertex
+ offset
+ 3 * nSides
+ 3 );
723 glNormal3dv( normal
+ offset
+ 3 * nSides
);
724 glVertex3dv( vertex
+ offset
+ 3 * nSides
);
738 void GLUTAPIENTRY
glutWireDodecahedron( void )
740 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
741 * of a cube. The coordinates of the points are:
742 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
743 * where x = 0.61803398875 and z = 1.61803398875.
745 glBegin ( GL_LINE_LOOP
) ;
746 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 ) ;
748 glBegin ( GL_LINE_LOOP
) ;
749 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 ) ;
751 glBegin ( GL_LINE_LOOP
) ;
752 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 glBegin ( GL_LINE_LOOP
) ;
755 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.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 ) ;
761 glBegin ( GL_LINE_LOOP
) ;
762 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 ) ;
764 glBegin ( GL_LINE_LOOP
) ;
765 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 glBegin ( GL_LINE_LOOP
) ;
768 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.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 ) ;
774 glBegin ( GL_LINE_LOOP
) ;
775 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 ) ;
777 glBegin ( GL_LINE_LOOP
) ;
778 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 glBegin ( GL_LINE_LOOP
) ;
781 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 ) ;
788 void GLUTAPIENTRY
glutSolidDodecahedron( void )
790 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
791 * of a cube. The coordinates of the points are:
792 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
793 * where x = 0.61803398875 and z = 1.61803398875.
795 glBegin ( GL_POLYGON
) ;
796 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 ) ;
798 glBegin ( GL_POLYGON
) ;
799 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 ) ;
801 glBegin ( GL_POLYGON
) ;
802 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.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 glBegin ( GL_POLYGON
) ;
809 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 ) ;
811 glBegin ( GL_POLYGON
) ;
812 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 ) ;
814 glBegin ( GL_POLYGON
) ;
815 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.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 glBegin ( GL_POLYGON
) ;
822 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 ) ;
824 glBegin ( GL_POLYGON
) ;
825 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 ) ;
827 glBegin ( GL_POLYGON
) ;
828 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 ) ;
830 glBegin ( GL_POLYGON
) ;
831 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 void GLUTAPIENTRY
glutWireOctahedron( void )
841 glBegin( GL_LINE_LOOP
);
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
);
846 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
);
847 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
);
848 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
);
849 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 void GLUTAPIENTRY
glutSolidOctahedron( void )
860 glBegin( GL_TRIANGLES
);
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
);
865 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
);
866 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
);
867 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
);
868 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 void GLUTAPIENTRY
glutWireTetrahedron( void )
878 /* Magic Numbers: r0 = ( 1, 0, 0 )
879 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
880 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
881 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
882 * |r0| = |r1| = |r2| = |r3| = 1
883 * Distance between any two points is 2 sqrt(6) / 3
885 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
888 double r0
[3] = { 1.0, 0.0, 0.0 } ;
889 double r1
[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
890 double r2
[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
891 double r3
[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
893 glBegin( GL_LINE_LOOP
) ;
894 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1
) ; glVertex3dv ( r3
) ; glVertex3dv ( r2
) ;
895 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r2
) ; glVertex3dv ( r3
) ;
896 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r3
) ; glVertex3dv ( r1
) ;
897 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r1
) ; glVertex3dv ( r2
) ;
904 void GLUTAPIENTRY
glutSolidTetrahedron( void )
906 /* Magic Numbers: r0 = ( 1, 0, 0 )
907 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
908 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
909 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
910 * |r0| = |r1| = |r2| = |r3| = 1
911 * Distance between any two points is 2 sqrt(6) / 3
913 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
916 double r0
[3] = { 1.0, 0.0, 0.0 } ;
917 double r1
[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
918 double r2
[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
919 double r3
[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
921 glBegin( GL_TRIANGLES
) ;
922 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1
) ; glVertex3dv ( r3
) ; glVertex3dv ( r2
) ;
923 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r2
) ; glVertex3dv ( r3
) ;
924 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r3
) ; glVertex3dv ( r1
) ;
925 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0
) ; glVertex3dv ( r1
) ; glVertex3dv ( r2
) ;
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 GLUTAPIENTRY
glutWireIcosahedron( void )
944 for ( i
= 0; i
< 20; i
++ )
947 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] ) ;
948 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] ) ;
949 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] ) ;
950 glBegin ( GL_LINE_LOOP
) ;
951 glNormal3dv ( normal
) ;
952 glVertex3dv ( icos_r
[icos_v
[i
][0]] ) ;
953 glVertex3dv ( icos_r
[icos_v
[i
][1]] ) ;
954 glVertex3dv ( icos_r
[icos_v
[i
][2]] ) ;
962 void GLUTAPIENTRY
glutSolidIcosahedron( void )
966 glBegin ( GL_TRIANGLES
) ;
967 for ( i
= 0; i
< 20; i
++ )
970 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] ) ;
971 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] ) ;
972 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] ) ;
973 glNormal3dv ( normal
) ;
974 glVertex3dv ( icos_r
[icos_v
[i
][0]] ) ;
975 glVertex3dv ( icos_r
[icos_v
[i
][1]] ) ;
976 glVertex3dv ( icos_r
[icos_v
[i
][2]] ) ;
985 double rdod_r
[14][3] = { { 0.0, 0.0, 1.0 },
986 { 0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, 0.707106781187, 0.5 }, { -0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, -0.707106781187, 0.5 },
987 { 0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, -0.707106781187, 0.0 }, { 0.707106781187, -0.707106781187, 0.0 },
988 { 0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, 0.707106781187, -0.5 }, { -0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, -0.707106781187, -0.5 },
989 { 0.0, 0.0, -1.0 } } ;
990 int rdod_v
[12][4] = { { 0, 1, 5, 2 }, { 0, 2, 6, 3 }, { 0, 3, 7, 4 }, { 0, 4, 8, 1 },
991 { 5, 10, 6, 2 }, { 6, 11, 7, 3 }, { 7, 12, 8, 4 }, { 8, 9, 5, 1 },
992 { 5, 9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ;
993 double rdod_n
[12][3] = {
994 { 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 { 0.000000000000, 1.000000000000, 0.0 }, { -1.000000000000, 0.000000000000, 0.0 }, { 0.000000000000, -1.000000000000, 0.0 }, { 1.000000000000, 0.000000000000, 0.0 },
996 { 0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, { 0.353553390594, -0.353553390594, -0.5 }
999 void GLUTAPIENTRY
glutWireRhombicDodecahedron( void )
1002 for ( i
= 0; i
< 12; i
++ )
1004 glBegin ( GL_LINE_LOOP
) ;
1005 glNormal3dv ( rdod_n
[i
] ) ;
1006 glVertex3dv ( rdod_r
[rdod_v
[i
][0]] ) ;
1007 glVertex3dv ( rdod_r
[rdod_v
[i
][1]] ) ;
1008 glVertex3dv ( rdod_r
[rdod_v
[i
][2]] ) ;
1009 glVertex3dv ( rdod_r
[rdod_v
[i
][3]] ) ;
1017 void GLUTAPIENTRY
glutSolidRhombicDodecahedron( void )
1021 glBegin ( GL_QUADS
) ;
1022 for ( i
= 0; i
< 12; i
++ )
1024 glNormal3dv ( rdod_n
[i
] ) ;
1025 glVertex3dv ( rdod_r
[rdod_v
[i
][0]] ) ;
1026 glVertex3dv ( rdod_r
[rdod_v
[i
][1]] ) ;
1027 glVertex3dv ( rdod_r
[rdod_v
[i
][2]] ) ;
1028 glVertex3dv ( rdod_r
[rdod_v
[i
][3]] ) ;
1036 static GLdouble tetrahedron_v
[4][3] = /* Vertices */
1038 { -0.5, -0.288675134595, -0.144337567297 },
1039 { 0.5, -0.288675134595, -0.144337567297 },
1040 { 0.0, 0.577350269189, -0.144337567297 },
1041 { 0.0, 0.0, 0.672159013631 }
1044 static GLint tetrahedron_i
[4][3] = /* Vertex indices */
1046 { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 1, 3, 2 }
1049 static GLdouble tetrahedron_n
[4][3] = /* Normals */
1052 { -0.816496580928, 0.471404520791, 0.333333333333 },
1053 { 0.0, -0.942809041582, 0.333333333333 },
1054 { 0.816496580928, 0.471404520791, 0.333333333333 }
1057 void GLUTAPIENTRY
glutWireSierpinskiSponge ( int num_levels
, GLdouble offset
[3], GLdouble scale
)
1061 if ( num_levels
== 0 )
1064 for ( i
= 0 ; i
< NUM_FACES
; i
++ )
1066 glBegin ( GL_LINE_LOOP
) ;
1067 glNormal3dv ( tetrahedron_n
[i
] ) ;
1068 for ( j
= 0; j
< 3; j
++ )
1070 double x
= offset
[0] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][0] ;
1071 double y
= offset
[1] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][1] ;
1072 double z
= offset
[2] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][2] ;
1073 glVertex3d ( x
, y
, z
) ;
1081 GLdouble local_offset
[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1084 local_offset
[0] = offset
[0] + scale
* tetrahedron_v
[0][0] ;
1085 local_offset
[1] = offset
[1] + scale
* tetrahedron_v
[0][1] ;
1086 local_offset
[2] = offset
[2] + scale
* tetrahedron_v
[0][2] ;
1087 glutWireSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1088 local_offset
[0] += scale
;
1089 glutWireSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1090 local_offset
[0] -= 0.5 * scale
;
1091 local_offset
[1] += 0.866025403784 * scale
;
1092 glutWireSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1093 local_offset
[1] -= 0.577350269189 * scale
;
1094 local_offset
[2] += 0.816496580928 * scale
;
1095 glutWireSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1099 void GLUTAPIENTRY
glutSolidSierpinskiSponge ( int num_levels
, GLdouble offset
[3], GLdouble scale
)
1103 if ( num_levels
== 0 )
1105 glBegin ( GL_TRIANGLES
) ;
1107 for ( i
= 0 ; i
< NUM_FACES
; i
++ )
1109 glNormal3dv ( tetrahedron_n
[i
] ) ;
1110 for ( j
= 0; j
< 3; j
++ )
1112 double x
= offset
[0] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][0] ;
1113 double y
= offset
[1] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][1] ;
1114 double z
= offset
[2] + scale
* tetrahedron_v
[tetrahedron_i
[i
][j
]][2] ;
1115 glVertex3d ( x
, y
, z
) ;
1123 GLdouble local_offset
[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1126 local_offset
[0] = offset
[0] + scale
* tetrahedron_v
[0][0] ;
1127 local_offset
[1] = offset
[1] + scale
* tetrahedron_v
[0][1] ;
1128 local_offset
[2] = offset
[2] + scale
* tetrahedron_v
[0][2] ;
1129 glutSolidSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1130 local_offset
[0] += scale
;
1131 glutSolidSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1132 local_offset
[0] -= 0.5 * scale
;
1133 local_offset
[1] += 0.866025403784 * scale
;
1134 glutSolidSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1135 local_offset
[1] -= 0.577350269189 * scale
;
1136 local_offset
[2] += 0.816496580928 * scale
;
1137 glutSolidSierpinskiSponge ( num_levels
, local_offset
, scale
) ;
1143 /*** END OF FILE ***/