cell: checkpoint: more work in emit_function_call()
[mesa.git] / src / glut / dos / shapes.c
1 /*
2 * freeglut_geometry.c
3 *
4 * Freeglut geometry rendering methods.
5 *
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
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
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.
26 */
27
28 #include <math.h>
29 #include "internal.h"
30
31 /*
32 * TODO BEFORE THE STABLE RELEASE:
33 *
34 * Following functions have been contributed by Andreas Umbach.
35 *
36 * glutWireCube() -- looks OK
37 * glutSolidCube() -- OK
38 *
39 * Those functions have been implemented by John Fay.
40 *
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
51 *
52 * The Following functions have been updated by Nigel Stewart, based
53 * on FreeGLUT 2.0.0 implementations:
54 *
55 * glutWireSphere() -- looks OK
56 * glutSolidSphere() -- looks OK
57 * glutWireCone() -- looks OK
58 * glutSolidCone() -- looks OK
59 */
60
61
62 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
63
64 /*
65 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
66 */
67 void GLUTAPIENTRY glutWireCube( GLdouble dSize )
68 {
69 double size = dSize * 0.5;
70
71 # define V(a,b,c) glVertex3d( a size, b size, c size );
72 # define N(a,b,c) glNormal3d( a, b, c );
73
74 /*
75 * PWO: I dared to convert the code to use macros...
76 */
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();
83
84 # undef V
85 # undef N
86 }
87
88 /*
89 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
90 */
91 void GLUTAPIENTRY glutSolidCube( GLdouble dSize )
92 {
93 double size = dSize * 0.5;
94
95 # define V(a,b,c) glVertex3d( a size, b size, c size );
96 # define N(a,b,c) glNormal3d( a, b, c );
97
98 /*
99 * PWO: Again, I dared to convert the code to use macros...
100 */
101 glBegin( GL_QUADS );
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(+,-,-);
108 glEnd();
109
110 # undef V
111 # undef N
112 }
113
114 /*
115 * Compute lookup table of cos and sin values forming a cirle
116 *
117 * Notes:
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
122 */
123
124 static void circleTable(double **sint,double **cost,const int n)
125 {
126 int i;
127
128 /* Table size, the sign of n flips the circle direction */
129
130 const int size = abs(n);
131
132 /* Determine the angle between samples */
133
134 const double angle = 2*M_PI/(double)n;
135
136 /* Allocate memory for n samples, plus duplicate of first entry at the end */
137
138 *sint = (double *) calloc(sizeof(double), size+1);
139 *cost = (double *) calloc(sizeof(double), size+1);
140
141 /* Bail out if memory allocation fails, fgError never returns */
142
143 if (!(*sint) || !(*cost))
144 {
145 free(*sint);
146 free(*cost);
147 _glut_fatal("Failed to allocate memory in circleTable");
148 }
149
150 /* Compute cos and sin around the circle */
151
152 for (i=0; i<size; i++)
153 {
154 (*sint)[i] = sin(angle*i);
155 (*cost)[i] = cos(angle*i);
156 }
157
158 /* Last sample is duplicate of the first */
159
160 (*sint)[size] = (*sint)[0];
161 (*cost)[size] = (*cost)[0];
162 }
163
164 /*
165 * Draws a solid sphere
166 */
167 void GLUTAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
168 {
169 int i,j;
170
171 /* Adjust z and radius as stacks are drawn. */
172
173 double z0,z1;
174 double r0,r1;
175
176 /* Pre-computed circle */
177
178 double *sint1,*cost1;
179 double *sint2,*cost2;
180 circleTable(&sint1,&cost1,-slices);
181 circleTable(&sint2,&cost2,stacks*2);
182
183 /* The top stack is covered with a triangle fan */
184
185 z0 = 1.0;
186 z1 = cost2[1];
187 r0 = 0.0;
188 r1 = sint2[1];
189
190 glBegin(GL_TRIANGLE_FAN);
191
192 glNormal3d(0,0,1);
193 glVertex3d(0,0,radius);
194
195 for (j=slices; j>=0; j--)
196 {
197 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
198 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
199 }
200
201 glEnd();
202
203 /* Cover each stack with a quad strip, except the top and bottom stacks */
204
205 for( i=1; i<stacks-1; i++ )
206 {
207 z0 = z1; z1 = cost2[i+1];
208 r0 = r1; r1 = sint2[i+1];
209
210 glBegin(GL_QUAD_STRIP);
211
212 for(j=0; j<=slices; j++)
213 {
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);
218 }
219
220 glEnd();
221 }
222
223 /* The bottom stack is covered with a triangle fan */
224
225 z0 = z1;
226 r0 = r1;
227
228 glBegin(GL_TRIANGLE_FAN);
229
230 glNormal3d(0,0,-1);
231 glVertex3d(0,0,-radius);
232
233 for (j=0; j<=slices; j++)
234 {
235 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
236 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
237 }
238
239 glEnd();
240
241 /* Release sin and cos tables */
242
243 free(sint1);
244 free(cost1);
245 free(sint2);
246 free(cost2);
247 }
248
249 /*
250 * Draws a solid sphere
251 */
252 void GLUTAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
253 {
254 int i,j;
255
256 /* Adjust z and radius as stacks and slices are drawn. */
257
258 double r;
259 double x,y,z;
260
261 /* Pre-computed circle */
262
263 double *sint1,*cost1;
264 double *sint2,*cost2;
265 circleTable(&sint1,&cost1,-slices );
266 circleTable(&sint2,&cost2, stacks*2);
267
268 /* Draw a line loop for each stack */
269
270 for (i=1; i<stacks; i++)
271 {
272 z = cost2[i];
273 r = sint2[i];
274
275 glBegin(GL_LINE_LOOP);
276
277 for(j=0; j<=slices; j++)
278 {
279 x = cost1[j];
280 y = sint1[j];
281
282 glNormal3d(x,y,z);
283 glVertex3d(x*r*radius,y*r*radius,z*radius);
284 }
285
286 glEnd();
287 }
288
289 /* Draw a line loop for each slice */
290
291 for (i=0; i<slices; i++)
292 {
293 glBegin(GL_LINE_STRIP);
294
295 for(j=0; j<=stacks; j++)
296 {
297 x = cost1[i]*sint2[j];
298 y = sint1[i]*sint2[j];
299 z = cost2[j];
300
301 glNormal3d(x,y,z);
302 glVertex3d(x*radius,y*radius,z*radius);
303 }
304
305 glEnd();
306 }
307
308 /* Release sin and cos tables */
309
310 free(sint1);
311 free(cost1);
312 free(sint2);
313 free(cost2);
314 }
315
316 /*
317 * Draws a solid cone
318 */
319 void GLUTAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
320 {
321 int i,j;
322
323 /* Step in z and radius as stacks are drawn. */
324
325 double z0,z1;
326 double r0,r1;
327
328 const double zStep = height/stacks;
329 const double rStep = base/stacks;
330
331 /* Scaling factors for vertex normals */
332
333 const double cosn = ( height / sqrt ( height * height + base * base ));
334 const double sinn = ( base / sqrt ( height * height + base * base ));
335
336 /* Pre-computed circle */
337
338 double *sint,*cost;
339 circleTable(&sint,&cost,-slices);
340
341 /* Cover the circular base with a triangle fan... */
342
343 z0 = 0.0;
344 z1 = zStep;
345
346 r0 = base;
347 r1 = r0 - rStep;
348
349 glBegin(GL_TRIANGLE_FAN);
350
351 glNormal3d(0.0,0.0,-1.0);
352 glVertex3d(0.0,0.0, z0 );
353
354 for (j=0; j<=slices; j++)
355 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
356
357 glEnd();
358
359 /* Cover each stack with a quad strip, except the top stack */
360
361 for( i=0; i<stacks-1; i++ )
362 {
363 glBegin(GL_QUAD_STRIP);
364
365 for(j=0; j<=slices; j++)
366 {
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 );
370 }
371
372 z0 = z1; z1 += zStep;
373 r0 = r1; r1 -= rStep;
374
375 glEnd();
376 }
377
378 /* The top stack is covered with individual triangles */
379
380 glBegin(GL_TRIANGLES);
381
382 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
383
384 for (j=0; j<slices; j++)
385 {
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 );
390 }
391
392 glEnd();
393
394 /* Release sin and cos tables */
395
396 free(sint);
397 free(cost);
398 }
399
400 /*
401 * Draws a wire cone
402 */
403 void GLUTAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
404 {
405 int i,j;
406
407 /* Step in z and radius as stacks are drawn. */
408
409 double z = 0.0;
410 double r = base;
411
412 const double zStep = height/stacks;
413 const double rStep = base/stacks;
414
415 /* Scaling factors for vertex normals */
416
417 const double cosn = ( height / sqrt ( height * height + base * base ));
418 const double sinn = ( base / sqrt ( height * height + base * base ));
419
420 /* Pre-computed circle */
421
422 double *sint,*cost;
423 circleTable(&sint,&cost,-slices);
424
425 /* Draw the stacks... */
426
427 for (i=0; i<stacks; i++)
428 {
429 glBegin(GL_LINE_LOOP);
430
431 for( j=0; j<slices; j++ )
432 {
433 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
434 glVertex3d(cost[j]*r, sint[j]*r, z );
435 }
436
437 glEnd();
438
439 z += zStep;
440 r -= rStep;
441 }
442
443 /* Draw the slices */
444
445 r = base;
446
447 glBegin(GL_LINES);
448
449 for (j=0; j<slices; j++)
450 {
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);
454 }
455
456 glEnd();
457
458 /* Release sin and cos tables */
459
460 free(sint);
461 free(cost);
462 }
463
464
465 /*
466 * Draws a solid cylinder
467 */
468 void GLUTAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
469 {
470 int i,j;
471
472 /* Step in z and radius as stacks are drawn. */
473
474 double z0,z1;
475 const double zStep = height/stacks;
476
477 /* Pre-computed circle */
478
479 double *sint,*cost;
480 circleTable(&sint,&cost,-slices);
481
482 /* Cover the base and top */
483
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);
489 glEnd();
490
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);
496 glEnd();
497
498 /* Do the stacks */
499
500 z0 = 0.0;
501 z1 = zStep;
502
503 for (i=1; i<=stacks; i++)
504 {
505 if (i==stacks)
506 z1 = height;
507
508 glBegin(GL_QUAD_STRIP);
509 for (j=0; j<=slices; j++ )
510 {
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 );
514 }
515 glEnd();
516
517 z0 = z1; z1 += zStep;
518 }
519
520 /* Release sin and cos tables */
521
522 free(sint);
523 free(cost);
524 }
525
526 /*
527 * Draws a wire cylinder
528 */
529 void GLUTAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
530 {
531 int i,j;
532
533 /* Step in z and radius as stacks are drawn. */
534
535 double z = 0.0;
536 const double zStep = height/stacks;
537
538 /* Pre-computed circle */
539
540 double *sint,*cost;
541 circleTable(&sint,&cost,-slices);
542
543 /* Draw the stacks... */
544
545 for (i=0; i<=stacks; i++)
546 {
547 if (i==stacks)
548 z = height;
549
550 glBegin(GL_LINE_LOOP);
551
552 for( j=0; j<slices; j++ )
553 {
554 glNormal3d(cost[j], sint[j], 0.0);
555 glVertex3d(cost[j]*radius, sint[j]*radius, z );
556 }
557
558 glEnd();
559
560 z += zStep;
561 }
562
563 /* Draw the slices */
564
565 glBegin(GL_LINES);
566
567 for (j=0; j<slices; j++)
568 {
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);
572 }
573
574 glEnd();
575
576 /* Release sin and cos tables */
577
578 free(sint);
579 free(cost);
580 }
581
582 /*
583 *
584 */
585 void GLUTAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
586 {
587 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
588 double *vertex, *normal;
589 int i, j;
590 double spsi, cpsi, sphi, cphi ;
591
592 /*
593 * Allocate the vertices array
594 */
595 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
596 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
597
598 glPushMatrix();
599
600 dpsi = 2.0 * M_PI / (double)nRings ;
601 dphi = -2.0 * M_PI / (double)nSides ;
602 psi = 0.0;
603
604 for( j=0; j<nRings; j++ )
605 {
606 cpsi = cos ( psi ) ;
607 spsi = sin ( psi ) ;
608 phi = 0.0;
609
610 for( i=0; i<nSides; i++ )
611 {
612 int offset = 3 * ( j * nSides + i ) ;
613 cphi = cos ( phi ) ;
614 sphi = sin ( phi ) ;
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 ;
621 phi += dphi;
622 }
623
624 psi += dpsi;
625 }
626
627 for( i=0; i<nSides; i++ )
628 {
629 glBegin( GL_LINE_LOOP );
630
631 for( j=0; j<nRings; j++ )
632 {
633 int offset = 3 * ( j * nSides + i ) ;
634 glNormal3dv( normal + offset );
635 glVertex3dv( vertex + offset );
636 }
637
638 glEnd();
639 }
640
641 for( j=0; j<nRings; j++ )
642 {
643 glBegin(GL_LINE_LOOP);
644
645 for( i=0; i<nSides; i++ )
646 {
647 int offset = 3 * ( j * nSides + i ) ;
648 glNormal3dv( normal + offset );
649 glVertex3dv( vertex + offset );
650 }
651
652 glEnd();
653 }
654
655 free ( vertex ) ;
656 free ( normal ) ;
657 glPopMatrix();
658 }
659
660 /*
661 *
662 */
663 void GLUTAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
664 {
665 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
666 double *vertex, *normal;
667 int i, j;
668 double spsi, cpsi, sphi, cphi ;
669
670 /*
671 * Increment the number of sides and rings to allow for one more point than surface
672 */
673 nSides ++ ;
674 nRings ++ ;
675
676 /*
677 * Allocate the vertices array
678 */
679 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
680 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
681
682 glPushMatrix();
683
684 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
685 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
686 psi = 0.0;
687
688 for( j=0; j<nRings; j++ )
689 {
690 cpsi = cos ( psi ) ;
691 spsi = sin ( psi ) ;
692 phi = 0.0;
693
694 for( i=0; i<nSides; i++ )
695 {
696 int offset = 3 * ( j * nSides + i ) ;
697 cphi = cos ( phi ) ;
698 sphi = sin ( phi ) ;
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 ;
705 phi += dphi;
706 }
707
708 psi += dpsi;
709 }
710
711 glBegin( GL_QUADS );
712 for( i=0; i<nSides-1; i++ )
713 {
714 for( j=0; j<nRings-1; j++ )
715 {
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 );
725 }
726 }
727
728 glEnd();
729
730 free ( vertex ) ;
731 free ( normal ) ;
732 glPopMatrix();
733 }
734
735 /*
736 *
737 */
738 void GLUTAPIENTRY glutWireDodecahedron( void )
739 {
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.
744 */
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 ) ;
747 glEnd () ;
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 ) ;
750 glEnd () ;
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 ) ;
753 glEnd () ;
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 ) ;
756 glEnd () ;
757
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 ) ;
760 glEnd () ;
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 ) ;
763 glEnd () ;
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 ) ;
766 glEnd () ;
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 ) ;
769 glEnd () ;
770
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 ) ;
773 glEnd () ;
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 ) ;
776 glEnd () ;
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 ) ;
779 glEnd () ;
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 ) ;
782 glEnd () ;
783 }
784
785 /*
786 *
787 */
788 void GLUTAPIENTRY glutSolidDodecahedron( void )
789 {
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.
794 */
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 ) ;
797 glEnd () ;
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 ) ;
800 glEnd () ;
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 ) ;
803 glEnd () ;
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 ) ;
806 glEnd () ;
807
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 ) ;
810 glEnd () ;
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 ) ;
813 glEnd () ;
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 ) ;
816 glEnd () ;
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 ) ;
819 glEnd () ;
820
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 ) ;
823 glEnd () ;
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 ) ;
826 glEnd () ;
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 ) ;
829 glEnd () ;
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 ) ;
832 glEnd () ;
833 }
834
835 /*
836 *
837 */
838 void GLUTAPIENTRY glutWireOctahedron( void )
839 {
840 #define RADIUS 1.0f
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 );
850 glEnd();
851 #undef RADIUS
852 }
853
854 /*
855 *
856 */
857 void GLUTAPIENTRY glutSolidOctahedron( void )
858 {
859 #define RADIUS 1.0f
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 );
869 glEnd();
870 #undef RADIUS
871 }
872
873 /*
874 *
875 */
876 void GLUTAPIENTRY glutWireTetrahedron( void )
877 {
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
884 *
885 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
886 */
887
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 } ;
892
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 ) ;
898 glEnd() ;
899 }
900
901 /*
902 *
903 */
904 void GLUTAPIENTRY glutSolidTetrahedron( void )
905 {
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
912 *
913 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
914 */
915
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 } ;
920
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 ) ;
926 glEnd() ;
927 }
928
929 /*
930 *
931 */
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 } } ;
940
941 void GLUTAPIENTRY glutWireIcosahedron( void )
942 {
943 int i ;
944 for ( i = 0; i < 20; i++ )
945 {
946 double normal[3] ;
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]] ) ;
955 glEnd () ;
956 }
957 }
958
959 /*
960 *
961 */
962 void GLUTAPIENTRY glutSolidIcosahedron( void )
963 {
964 int i ;
965
966 glBegin ( GL_TRIANGLES ) ;
967 for ( i = 0; i < 20; i++ )
968 {
969 double normal[3] ;
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]] ) ;
977 }
978
979 glEnd () ;
980 }
981
982 /*
983 *
984 */
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 }
997 } ;
998
999 void GLUTAPIENTRY glutWireRhombicDodecahedron( void )
1000 {
1001 int i ;
1002 for ( i = 0; i < 12; i++ )
1003 {
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]] ) ;
1010 glEnd () ;
1011 }
1012 }
1013
1014 /*
1015 *
1016 */
1017 void GLUTAPIENTRY glutSolidRhombicDodecahedron( void )
1018 {
1019 int i ;
1020
1021 glBegin ( GL_QUADS ) ;
1022 for ( i = 0; i < 12; i++ )
1023 {
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]] ) ;
1029 }
1030
1031 glEnd () ;
1032 }
1033
1034 #define NUM_FACES 4
1035
1036 static GLdouble tetrahedron_v[4][3] = /* Vertices */
1037 {
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 }
1042 } ;
1043
1044 static GLint tetrahedron_i[4][3] = /* Vertex indices */
1045 {
1046 { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 1, 3, 2 }
1047 } ;
1048
1049 static GLdouble tetrahedron_n[4][3] = /* Normals */
1050 {
1051 { 0.0, 0.0, -1.0 },
1052 { -0.816496580928, 0.471404520791, 0.333333333333 },
1053 { 0.0, -0.942809041582, 0.333333333333 },
1054 { 0.816496580928, 0.471404520791, 0.333333333333 }
1055 } ;
1056
1057 void GLUTAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1058 {
1059 int i, j ;
1060
1061 if ( num_levels == 0 )
1062 {
1063
1064 for ( i = 0 ; i < NUM_FACES ; i++ )
1065 {
1066 glBegin ( GL_LINE_LOOP ) ;
1067 glNormal3dv ( tetrahedron_n[i] ) ;
1068 for ( j = 0; j < 3; j++ )
1069 {
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 ) ;
1074 }
1075
1076 glEnd () ;
1077 }
1078 }
1079 else
1080 {
1081 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1082 num_levels -- ;
1083 scale /= 2.0 ;
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 ) ;
1096 }
1097 }
1098
1099 void GLUTAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1100 {
1101 int i, j ;
1102
1103 if ( num_levels == 0 )
1104 {
1105 glBegin ( GL_TRIANGLES ) ;
1106
1107 for ( i = 0 ; i < NUM_FACES ; i++ )
1108 {
1109 glNormal3dv ( tetrahedron_n[i] ) ;
1110 for ( j = 0; j < 3; j++ )
1111 {
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 ) ;
1116 }
1117 }
1118
1119 glEnd () ;
1120 }
1121 else
1122 {
1123 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1124 num_levels -- ;
1125 scale /= 2.0 ;
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 ) ;
1138 }
1139 }
1140
1141 #undef NUM_FACES
1142
1143 /*** END OF FILE ***/