4 * Freeglut geometry rendering methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "../include/GL/freeglut.h"
33 #include "freeglut_internal.h"
36 * TODO BEFORE THE STABLE RELEASE:
38 * Following functions have been contributed by Andreas Umbach.
40 * glutWireCube() -- looks OK
41 * glutSolidCube() -- OK
42 * glutWireSphere() -- OK
43 * glutSolidSphere() -- OK
45 * Following functions have been implemented by Pawel and modified by John Fay:
47 * glutWireCone() -- looks OK
48 * glutSolidCone() -- looks OK
50 * Those functions have been implemented by John Fay.
52 * glutWireTorus() -- looks OK
53 * glutSolidTorus() -- looks OK
54 * glutWireDodecahedron() -- looks OK
55 * glutSolidDodecahedron() -- looks OK
56 * glutWireOctahedron() -- looks OK
57 * glutSolidOctahedron() -- looks OK
58 * glutWireTetrahedron() -- looks OK
59 * glutSolidTetrahedron() -- looks OK
60 * glutWireIcosahedron() -- looks OK
61 * glutSolidIcosahedron() -- looks OK
65 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
68 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
70 void FGAPIENTRY glutWireCube( GLdouble dSize )
72 double size = dSize * 0.5;
74 # define V(a,b,c) glVertex3d( a size, b size, c size );
75 # define N(a,b,c) glNormal3d( a, b, c );
78 * PWO: I dared to convert the code to use macros...
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 glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
84 glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
85 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
92 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
94 void FGAPIENTRY glutSolidCube( GLdouble dSize )
96 double size = dSize * 0.5;
98 # define V(a,b,c) glVertex3d( a size, b size, c size );
99 # define N(a,b,c) glNormal3d( a, b, c );
102 * PWO: Again, I dared to convert the code to use macros...
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 N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-);
109 N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+);
110 N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-);
118 * Draws a wire sphere. Code contributed by Andreas Umbach <marvin@dataway.ch>
120 void FGAPIENTRY glutWireSphere( GLdouble dRadius, GLint slices, GLint stacks )
122 double radius = dRadius, phi, psi, dpsi, dphi;
125 double cphi, sphi, cpsi, spsi ;
128 * Allocate the vertices array
130 vertex = (double *)calloc( sizeof(double), 3 * slices * (stacks - 1) );
133 glScaled( radius, radius, radius );
135 dpsi = M_PI / (stacks + 1);
136 dphi = 2 * M_PI / slices;
139 for( j=0; j<stacks-1; j++ )
145 for( i=0; i<slices; i++ )
147 int offset = 3 * ( j * slices + i ) ;
150 *(vertex + offset + 0) = sphi * spsi ;
151 *(vertex + offset + 1) = cphi * spsi ;
152 *(vertex + offset + 2) = cpsi ;
159 for( i=0; i<slices; i++ )
161 glBegin( GL_LINE_STRIP );
162 glNormal3d( 0, 0, 1 );
163 glVertex3d( 0, 0, 1 );
165 for( j=0; j<stacks - 1; j++ )
167 int offset = 3 * ( j * slices + i ) ;
168 glNormal3dv( vertex + offset );
169 glVertex3dv( vertex + offset );
172 glNormal3d(0, 0, -1);
173 glVertex3d(0, 0, -1);
177 for( j=0; j<stacks-1; j++ )
179 glBegin(GL_LINE_LOOP);
181 for( i=0; i<slices; i++ )
183 int offset = 3 * ( j * slices + i ) ;
184 glNormal3dv( vertex + offset );
185 glVertex3dv( vertex + offset );
196 * Draws a solid sphere. Code contributed by Andreas Umbach <marvin@dataway.ch>
198 void FGAPIENTRY glutSolidSphere( GLdouble dRadius, GLint slices, GLint stacks )
200 double radius = dRadius, phi, psi, dpsi, dphi;
201 double *next, *tmp, *row;
203 double cphi, sphi, cpsi, spsi ;
206 /* glScalef( radius, radius, radius ); */
208 row = (double *)calloc( sizeof(double), slices * 3 );
209 next = (double *)calloc( sizeof(double), slices * 3 );
211 dpsi = M_PI / (stacks + 1);
212 dphi = 2 * M_PI / slices;
216 /* init first line + do polar cap */
217 glBegin( GL_TRIANGLE_FAN );
218 glNormal3d( 0.0, 0.0, 1.0 );
219 glVertex3d( 0.0, 0.0, radius );
221 for( i=0; i<slices; i++ )
223 row[ i * 3 + 0 ] = sin( phi ) * sin( psi );
224 row[ i * 3 + 1 ] = cos( phi ) * sin( psi );
225 row[ i * 3 + 2 ] = cos( psi );
227 glNormal3dv( row + 3 * i );
229 radius * *(row + 3 * i + 0),
230 radius * *(row + 3 * i + 1),
231 radius * *(row + 3 * i + 2)
238 glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
241 for( j=0; j<stacks-1; j++ )
249 glBegin( GL_QUAD_STRIP );
251 /* glBegin(GL_LINE_LOOP); */
252 for( i=0; i<slices; i++ )
256 next[ i * 3 + 0 ] = sphi * spsi ;
257 next[ i * 3 + 1 ] = cphi * spsi ;
258 next[ i * 3 + 2 ] = cpsi ;
260 glNormal3dv( row + i * 3 );
262 radius * *(row + 3 * i + 0),
263 radius * *(row + 3 * i + 1),
264 radius * *(row + 3 * i + 2)
267 glNormal3dv( next + i * 3 );
269 radius * *(next + 3 * i + 0),
270 radius * *(next + 3 * i + 1),
271 radius * *(next + 3 * i + 2)
278 glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
280 glVertex3d( radius * *(next + 0), radius * *(next + 1), radius * *(next + 2) );
289 glBegin( GL_TRIANGLE_FAN );
290 glNormal3d( 0.0, 0.0, -1.0 );
291 glVertex3d( 0.0, 0.0, -radius );
293 glVertex3d( radius * *(row + 0), radius * *(row + 1), radius * *(row + 2) );
295 for( i=slices-1; i>=0; i-- )
297 glNormal3dv(row + 3 * i);
299 radius * *(row + 3 * i + 0),
300 radius * *(row + 3 * i + 1),
301 radius * *(row + 3 * i + 2)
315 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
317 double alt = height / (double) (stacks + 1);
318 double angle = M_PI / (double) slices * 2.0;
319 double slope = ( height / base );
320 double sBase = base ;
321 double sinNormal = ( base / sqrt ( height * height + base * base )) ;
322 double cosNormal = ( height / sqrt ( height * height + base * base )) ;
324 double *vertices = NULL;
328 * We need 'slices' points on a circle
330 vertices = (double *)calloc( sizeof(double), 2 * (slices + 1) );
332 for( j=0; j<slices+1; j++ )
334 vertices[ j*2 + 0 ] = cos( angle * j );
335 vertices[ j*2 + 1 ] = sin( angle * j );
339 * First the cone's bottom...
341 for( j=0; j<slices; j++ )
343 glBegin( GL_LINE_LOOP );
344 glNormal3d( 0.0, 0.0, -1.0 );
345 glVertex3d( vertices[ (j+0)*2+0 ] * sBase, vertices[ (j+0)*2+1 ] * sBase, 0 );
346 glVertex3d( vertices[ (j+1)*2+0 ] * sBase, vertices[ (j+1)*2+1 ] * sBase, 0 );
347 glVertex3d( 0.0, 0.0, 0.0 );
352 * Then all the stacks between the bottom and the top
354 for( i=0; i<stacks; i++ )
356 double alt_a = i * alt, alt_b = (i + 1) * alt;
357 double scl_a = (height - alt_a) / slope;
358 double scl_b = (height - alt_b) / slope;
360 for( j=0; j<slices; j++ )
362 glBegin( GL_LINE_LOOP );
363 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
364 glVertex3d( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
365 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
366 glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
367 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
368 glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
371 glBegin( GL_LINE_LOOP );
372 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
373 glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
374 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
375 glVertex3d( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
376 glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
382 * Finally have the top part drawn...
384 for( j=0; j<slices; j++ )
386 double scl = alt / slope;
388 glBegin( GL_LINE_LOOP );
389 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
390 glVertex3d( vertices[ (j+0)*2+0 ] * scl, vertices[ (j+0)*2+1 ] * scl, height - alt );
391 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
392 glVertex3d( vertices[ (j+1)*2+0 ] * scl, vertices[ (j+1)*2+1 ] * scl, height - alt );
393 glVertex3d( 0, 0, height );
401 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
403 double alt = height / (double) (stacks + 1);
404 double angle = M_PI / (double) slices * 2.0f;
405 double slope = ( height / base );
406 double sBase = base ;
407 double sinNormal = ( base / sqrt ( height * height + base * base )) ;
408 double cosNormal = ( height / sqrt ( height * height + base * base )) ;
410 double *vertices = NULL;
414 * We need 'slices' points on a circle
416 vertices = (double *)calloc( sizeof(double), 2 * (slices + 1) );
418 for( j=0; j<slices+1; j++ )
420 vertices[ j*2 + 0 ] = cos( angle * j );
421 vertices[ j*2 + 1 ] = sin( angle * j );
425 * First the cone's bottom...
427 for( j=0; j<slices; j++ )
429 glBegin( GL_TRIANGLES );
430 glNormal3d( 0.0, 0.0, -1.0 );
431 glVertex3d( vertices[ (j+0)*2+0 ] * sBase, vertices[ (j+0)*2+1 ] * sBase, 0 );
432 glVertex3d( vertices[ (j+1)*2+0 ] * sBase, vertices[ (j+1)*2+1 ] * sBase, 0 );
433 glVertex3d( 0.0, 0.0, 0.0 );
438 * Then all the stacks between the bottom and the top
440 for( i=0; i<stacks; i++ )
442 double alt_a = i * alt, alt_b = (i + 1) * alt;
443 double scl_a = (height - alt_a) / slope;
444 double scl_b = (height - alt_b) / slope;
446 for( j=0; j<slices; j++ )
448 glBegin( GL_TRIANGLES );
449 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
450 glVertex3d( vertices[(j+0)*2+0] * scl_a, vertices[(j+0)*2+1] * scl_a, alt_a );
451 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
452 glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
453 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
454 glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
457 glBegin( GL_TRIANGLES );
458 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
459 glVertex3d( vertices[(j+0)*2+0] * scl_b, vertices[(j+0)*2+1] * scl_b, alt_b );
460 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
461 glVertex3d( vertices[(j+1)*2+0] * scl_b, vertices[(j+1)*2+1] * scl_b, alt_b );
462 glVertex3d( vertices[(j+1)*2+0] * scl_a, vertices[(j+1)*2+1] * scl_a, alt_a );
468 * Finally have the top part drawn...
470 for( j=0; j<slices; j++ )
472 double scl = alt / slope;
474 glBegin( GL_TRIANGLES );
475 glNormal3d( sinNormal * vertices[(j+0)*2+0], sinNormal * vertices[(j+0)*2+1], cosNormal ) ;
476 glVertex3d( vertices[ (j+0)*2+0 ] * scl, vertices[ (j+0)*2+1 ] * scl, height - alt );
477 glNormal3d( sinNormal * vertices[(j+1)*2+0], sinNormal * vertices[(j+1)*2+1], cosNormal ) ;
478 glVertex3d( vertices[ (j+1)*2+0 ] * scl, vertices[ (j+1)*2+1 ] * scl, height - alt );
479 glVertex3d( 0, 0, height );
487 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
489 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
490 double *vertex, *normal;
492 double spsi, cpsi, sphi, cphi ;
495 * Allocate the vertices array
497 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
498 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
502 dpsi = 2.0 * M_PI / (double)nRings ;
503 dphi = 2.0 * M_PI / (double)nSides ;
506 for( j=0; j<nRings; j++ )
512 for( i=0; i<nSides; i++ )
514 int offset = 3 * ( j * nSides + i ) ;
517 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
518 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
519 *(vertex + offset + 2) = sphi * iradius ;
520 *(normal + offset + 0) = cpsi * cphi ;
521 *(normal + offset + 1) = spsi * cphi ;
522 *(normal + offset + 2) = sphi ;
529 for( i=0; i<nSides; i++ )
531 glBegin( GL_LINE_LOOP );
533 for( j=0; j<nRings; j++ )
535 int offset = 3 * ( j * nSides + i ) ;
536 glNormal3dv( normal + offset );
537 glVertex3dv( vertex + offset );
543 for( j=0; j<nRings; j++ )
545 glBegin(GL_LINE_LOOP);
547 for( i=0; i<nSides; i++ )
549 int offset = 3 * ( j * nSides + i ) ;
550 glNormal3dv( normal + offset );
551 glVertex3dv( vertex + offset );
565 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
567 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
568 double *vertex, *normal;
570 double spsi, cpsi, sphi, cphi ;
573 * Increment the number of sides and rings to allow for one more point than surface
579 * Allocate the vertices array
581 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
582 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
586 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
587 dphi = 2.0 * M_PI / (double)(nSides - 1) ;
590 for( j=0; j<nRings; j++ )
596 for( i=0; i<nSides; i++ )
598 int offset = 3 * ( j * nSides + i ) ;
601 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
602 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
603 *(vertex + offset + 2) = sphi * iradius ;
604 *(normal + offset + 0) = cpsi * cphi ;
605 *(normal + offset + 1) = spsi * cphi ;
606 *(normal + offset + 2) = sphi ;
614 for( i=0; i<nSides-1; i++ )
616 for( j=0; j<nRings-1; j++ )
618 int offset = 3 * ( j * nSides + i ) ;
619 glNormal3dv( normal + offset );
620 glVertex3dv( vertex + offset );
621 glNormal3dv( normal + offset + 3 );
622 glVertex3dv( vertex + offset + 3 );
623 glNormal3dv( normal + offset + 3 * nSides + 3 );
624 glVertex3dv( vertex + offset + 3 * nSides + 3 );
625 glNormal3dv( normal + offset + 3 * nSides );
626 glVertex3dv( vertex + offset + 3 * nSides );
640 void FGAPIENTRY glutWireDodecahedron( void )
642 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
643 * of a cube. The coordinates of the points are:
644 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
645 * where x = 0.61803398875 and z = 1.61803398875.
647 glBegin ( GL_LINE_LOOP ) ;
648 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 ) ;
650 glBegin ( GL_LINE_LOOP ) ;
651 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 ) ;
653 glBegin ( GL_LINE_LOOP ) ;
654 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 ) ;
656 glBegin ( GL_LINE_LOOP ) ;
657 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 ) ;
660 glBegin ( GL_LINE_LOOP ) ;
661 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 ) ;
663 glBegin ( GL_LINE_LOOP ) ;
664 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 ) ;
666 glBegin ( GL_LINE_LOOP ) ;
667 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 ) ;
669 glBegin ( GL_LINE_LOOP ) ;
670 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 ) ;
673 glBegin ( GL_LINE_LOOP ) ;
674 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 ) ;
676 glBegin ( GL_LINE_LOOP ) ;
677 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 ) ;
679 glBegin ( GL_LINE_LOOP ) ;
680 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 ) ;
682 glBegin ( GL_LINE_LOOP ) ;
683 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 ) ;
690 void FGAPIENTRY glutSolidDodecahedron( void )
692 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
693 * of a cube. The coordinates of the points are:
694 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
695 * where x = 0.61803398875 and z = 1.61803398875.
697 glBegin ( GL_POLYGON ) ;
698 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 ) ;
700 glBegin ( GL_POLYGON ) ;
701 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 ) ;
703 glBegin ( GL_POLYGON ) ;
704 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 ) ;
706 glBegin ( GL_POLYGON ) ;
707 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 ) ;
710 glBegin ( GL_POLYGON ) ;
711 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 ) ;
713 glBegin ( GL_POLYGON ) ;
714 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 ) ;
716 glBegin ( GL_POLYGON ) ;
717 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 ) ;
719 glBegin ( GL_POLYGON ) ;
720 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 ) ;
723 glBegin ( GL_POLYGON ) ;
724 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 ) ;
726 glBegin ( GL_POLYGON ) ;
727 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 ) ;
729 glBegin ( GL_POLYGON ) ;
730 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 ) ;
732 glBegin ( GL_POLYGON ) ;
733 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 ) ;
740 void FGAPIENTRY glutWireOctahedron( void )
743 glBegin( GL_LINE_LOOP );
744 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 );
745 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 );
746 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 );
747 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 );
748 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 );
749 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 );
750 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 );
751 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 );
759 void FGAPIENTRY glutSolidOctahedron( void )
762 glBegin( GL_TRIANGLES );
763 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 );
764 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 );
765 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 );
766 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 );
767 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 );
768 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 );
769 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 );
770 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 );
778 void FGAPIENTRY glutWireTetrahedron( void )
780 /* Magic Numbers: r0 = ( 1, 0, 0 )
781 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
782 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
783 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
784 * |r0| = |r1| = |r2| = |r3| = 1
785 * Distance between any two points is 2 sqrt(6) / 3
787 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
790 double r0[3] = { 1.0, 0.0, 0.0 } ;
791 double r1[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
792 double r2[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
793 double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
795 glBegin( GL_LINE_LOOP ) ;
796 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
797 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
798 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
799 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
806 void FGAPIENTRY glutSolidTetrahedron( void )
808 /* Magic Numbers: r0 = ( 1, 0, 0 )
809 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
810 * r2 = ( -1/3, -sqrt(2) / 3, sqrt(6) / 3 )
811 * r3 = ( -1/3, -sqrt(2) / 3, -sqrt(6) / 3 )
812 * |r0| = |r1| = |r2| = |r3| = 1
813 * Distance between any two points is 2 sqrt(6) / 3
815 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
818 double r0[3] = { 1.0, 0.0, 0.0 } ;
819 double r1[3] = { -0.333333333333, 0.942809041582, 0.0 } ;
820 double r2[3] = { -0.333333333333, -0.471404520791, 0.816496580928 } ;
821 double r3[3] = { -0.333333333333, -0.471404520791, -0.816496580928 } ;
823 glBegin( GL_TRIANGLES ) ;
824 glNormal3d ( -1.0, 0.0, 0.0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r2 ) ;
825 glNormal3d ( 0.333333333333, -0.942809041582, 0.0 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r2 ) ; glVertex3dv ( r3 ) ;
826 glNormal3d ( 0.333333333333, 0.471404520791, -0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r3 ) ; glVertex3dv ( r1 ) ;
827 glNormal3d ( 0.333333333333, 0.471404520791, 0.816496580928 ) ; glVertex3dv ( r0 ) ; glVertex3dv ( r1 ) ; glVertex3dv ( r2 ) ;
834 double icos_r[12][3] = { { 1.0, 0.0, 0.0 },
835 { 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 },
836 { -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 },
837 { -1.0, 0.0, 0.0 } } ;
838 int icos_v [20][3] = { { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 4 }, { 0, 4, 5 }, { 0, 5, 1 },
839 { 1, 8, 2 }, { 2, 7, 3 }, { 3, 6, 4 }, { 4, 10, 5 }, { 5, 9, 1 },
840 { 1, 9, 8 }, { 2, 8, 7 }, { 3, 7, 6 }, { 4, 6, 10 }, { 5, 10, 9 },
841 { 11, 9, 10 }, { 11, 8, 9 }, { 11, 7, 8 }, { 11, 6, 7 }, { 11, 10, 6 } } ;
843 void FGAPIENTRY glutWireIcosahedron( void )
846 for ( i = 0; i < 20; i++ )
849 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] ) ;
850 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] ) ;
851 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] ) ;
852 glBegin ( GL_LINE_LOOP ) ;
853 glNormal3dv ( normal ) ;
854 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
855 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
856 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
864 void FGAPIENTRY glutSolidIcosahedron( void )
868 glBegin ( GL_TRIANGLES ) ;
869 for ( i = 0; i < 20; i++ )
872 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] ) ;
873 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] ) ;
874 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] ) ;
875 glNormal3dv ( normal ) ;
876 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
877 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
878 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
887 double rdod_r[14][3] = { { 0.0, 0.0, 1.0 },
888 { 0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, 0.707106781187, 0.5 }, { -0.707106781187, 0.000000000000, 0.5 }, { 0.000000000000, -0.707106781187, 0.5 },
889 { 0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, 0.707106781187, 0.0 }, { -0.707106781187, -0.707106781187, 0.0 }, { 0.707106781187, -0.707106781187, 0.0 },
890 { 0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, 0.707106781187, -0.5 }, { -0.707106781187, 0.000000000000, -0.5 }, { 0.000000000000, -0.707106781187, -0.5 },
891 { 0.0, 0.0, -1.0 } } ;
892 int rdod_v [12][4] = { { 0, 1, 5, 2 }, { 0, 2, 6, 3 }, { 0, 3, 7, 4 }, { 0, 4, 8, 1 },
893 { 5, 10, 6, 2 }, { 6, 11, 7, 3 }, { 7, 12, 8, 4 }, { 8, 9, 5, 1 },
894 { 5, 9, 13, 10 }, { 6, 10, 13, 11 }, { 7, 11, 13, 12 }, { 8, 12, 13, 9 } } ;
895 double rdod_n[12][3] = {
896 { 0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, 0.353553390594, 0.5 }, { -0.353553390594, -0.353553390594, 0.5 }, { 0.353553390594, -0.353553390594, 0.5 },
897 { 0.000000000000, 1.000000000000, 0.0 }, { -1.000000000000, 0.000000000000, 0.0 }, { 0.000000000000, -1.000000000000, 0.0 }, { 1.000000000000, 0.000000000000, 0.0 },
898 { 0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, 0.353553390594, -0.5 }, { -0.353553390594, -0.353553390594, -0.5 }, { 0.353553390594, -0.353553390594, -0.5 }
901 void FGAPIENTRY glutWireRhombicDodecahedron( void )
904 for ( i = 0; i < 12; i++ )
906 glBegin ( GL_LINE_LOOP ) ;
907 glNormal3dv ( rdod_n[i] ) ;
908 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
909 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
910 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
911 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
919 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
923 glBegin ( GL_QUADS ) ;
924 for ( i = 0; i < 12; i++ )
926 glNormal3dv ( rdod_n[i] ) ;
927 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
928 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
929 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
930 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
938 static GLdouble tetrahedron_v[4][3] = /* Vertices */
940 { -0.5, -0.288675134595, -0.144337567297 },
941 { 0.5, -0.288675134595, -0.144337567297 },
942 { 0.0, 0.577350269189, -0.144337567297 },
943 { 0.0, 0.0, 0.672159013631 }
946 static GLint tetrahedron_i[4][3] = /* Vertex indices */
948 { 0, 1, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 1, 3, 2 }
951 static GLdouble tetrahedron_n[4][3] = /* Normals */
954 { -0.816496580928, 0.471404520791, 0.333333333333 },
955 { 0.0, -0.942809041582, 0.333333333333 },
956 { 0.816496580928, 0.471404520791, 0.333333333333 }
959 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
963 if ( num_levels == 0 )
966 for ( i = 0 ; i < NUM_FACES ; i++ )
968 glBegin ( GL_LINE_LOOP ) ;
969 glNormal3dv ( tetrahedron_n[i] ) ;
970 for ( j = 0; j < 3; j++ )
972 double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
973 double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
974 double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
975 glVertex3d ( x, y, z ) ;
983 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
986 local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
987 local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
988 local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
989 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
990 local_offset[0] += scale ;
991 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
992 local_offset[0] -= 0.5 * scale ;
993 local_offset[1] += 0.866025403784 * scale ;
994 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
995 local_offset[1] -= 0.577350269189 * scale ;
996 local_offset[2] += 0.816496580928 * scale ;
997 glutWireSierpinskiSponge ( num_levels, local_offset, scale ) ;
1001 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1005 if ( num_levels == 0 )
1007 glBegin ( GL_TRIANGLES ) ;
1009 for ( i = 0 ; i < NUM_FACES ; i++ )
1011 glNormal3dv ( tetrahedron_n[i] ) ;
1012 for ( j = 0; j < 3; j++ )
1014 double x = offset[0] + scale * tetrahedron_v[tetrahedron_i[i][j]][0] ;
1015 double y = offset[1] + scale * tetrahedron_v[tetrahedron_i[i][j]][1] ;
1016 double z = offset[2] + scale * tetrahedron_v[tetrahedron_i[i][j]][2] ;
1017 glVertex3d ( x, y, z ) ;
1025 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
1028 local_offset[0] = offset[0] + scale * tetrahedron_v[0][0] ;
1029 local_offset[1] = offset[1] + scale * tetrahedron_v[0][1] ;
1030 local_offset[2] = offset[2] + scale * tetrahedron_v[0][2] ;
1031 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1032 local_offset[0] += scale ;
1033 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1034 local_offset[0] -= 0.5 * scale ;
1035 local_offset[1] += 0.866025403784 * scale ;
1036 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1037 local_offset[1] -= 0.577350269189 * scale ;
1038 local_offset[2] += 0.816496580928 * scale ;
1039 glutSolidSierpinskiSponge ( num_levels, local_offset, scale ) ;
1045 /*** END OF FILE ***/