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.
28 #include <GL/freeglut.h>
29 #include "fg_internal.h"
32 * TODO BEFORE THE STABLE RELEASE:
36 * Following functions have been contributed by Andreas Umbach.
38 * glutWireCube() -- looks OK
39 * glutSolidCube() -- OK
41 * Those functions have been implemented by John Fay.
43 * glutWireTorus() -- looks OK
44 * glutSolidTorus() -- looks OK
45 * glutWireDodecahedron() -- looks OK
46 * glutSolidDodecahedron() -- looks OK
47 * glutWireOctahedron() -- looks OK
48 * glutSolidOctahedron() -- looks OK
49 * glutWireTetrahedron() -- looks OK
50 * glutSolidTetrahedron() -- looks OK
51 * glutWireIcosahedron() -- looks OK
52 * glutSolidIcosahedron() -- looks OK
54 * The Following functions have been updated by Nigel Stewart, based
55 * on FreeGLUT 2.0.0 implementations:
57 * glutWireSphere() -- looks OK
58 * glutSolidSphere() -- looks OK
59 * glutWireCone() -- looks OK
60 * glutSolidCone() -- looks OK
65 * General function for drawing geometry. As for all geometry we have no
66 * redundancy (or hardly any in the case of cones and cylinders) in terms
67 * of the vertex/normal combinations, we just use glDrawArrays.
68 * useWireMode controls the drawing of solids (false) or wire frame
69 * versions (TRUE) of the geometry you pass
71 static void fghDrawGeometry(GLenum vertexMode, double* vertices, double* normals, GLsizei numVertices, GLboolean useWireMode)
75 glPushAttrib(GL_POLYGON_BIT);
76 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
79 glEnableClientState(GL_VERTEX_ARRAY);
80 glEnableClientState(GL_NORMAL_ARRAY);
82 glVertexPointer(3, GL_DOUBLE, 0, vertices);
83 glNormalPointer(GL_DOUBLE, 0, normals);
84 glDrawArrays(vertexMode,0,numVertices);
86 glDisableClientState(GL_VERTEX_ARRAY);
87 glDisableClientState(GL_NORMAL_ARRAY);
96 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
97 static unsigned int ipow (int x, unsigned int y)
99 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
102 /* Magic Numbers: r0 = ( 1, 0, 0 )
103 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
104 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
105 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
106 * |r0| = |r1| = |r2| = |r3| = 1
107 * Distance between any two points is 2 sqrt(6) / 3
109 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
112 /* -- Tetrahedron -- */
113 #define TETR_NUM_FACES 4
114 #define TETR_NUM_VERT_PER_FACE 3
115 #define TETR_VERT_PER_TETR TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE
116 #define TETR_VERT_ELEM_PER_TETR TETR_VERT_PER_TETR*3
118 /* Vertex Coordinates */
119 static GLdouble tet_r[TETR_NUM_FACES][TETR_NUM_VERT_PER_FACE] =
122 { -0.333333333333, 0.942809041582, 0.0 },
123 { -0.333333333333, -0.471404520791, 0.816496580928 },
124 { -0.333333333333, -0.471404520791, -0.816496580928 }
128 static GLubyte tet_i[TETR_NUM_FACES][TETR_NUM_VERT_PER_FACE] =
130 { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
133 static GLubyte tet_n[TETR_NUM_FACES] =
138 /* Cache of input to glDrawArrays */
139 static GLboolean tetrCached = FALSE;
140 static double tetr_verts[TETR_VERT_ELEM_PER_TETR];
141 static double tetr_norms[TETR_VERT_ELEM_PER_TETR];
143 static void fghTetrahedronGenerate()
147 * Build array with vertices from vertex coordinates and vertex indices
148 * Do same for normals.
149 * Need to do this because of different normals at shared vertices
150 * (and because normals' coordinates need to be negated).
152 for (i=0; i<TETR_NUM_FACES; i++)
154 for (j=0; j<TETR_NUM_VERT_PER_FACE; j++)
156 int idx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
157 tetr_verts[idx ] = tet_r[tet_i[i][j]][0];
158 tetr_verts[idx+1] = tet_r[tet_i[i][j]][1];
159 tetr_verts[idx+2] = tet_r[tet_i[i][j]][2];
161 tetr_norms[idx ] = -tet_r[tet_n[i]][0];
162 tetr_norms[idx+1] = -tet_r[tet_n[i]][1];
163 tetr_norms[idx+2] = -tet_r[tet_n[i]][2];
168 /* -- Sierpinski Sponge -- */
169 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, double* vertices, double* normals )
172 if ( numLevels == 0 )
174 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
176 for ( j = 0; j < TETR_NUM_VERT_PER_FACE; j++ )
178 int idx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
179 vertices[idx ] = offset[0] + scale * tet_r[tet_i[i][j]][0];
180 vertices[idx+1] = offset[1] + scale * tet_r[tet_i[i][j]][1];
181 vertices[idx+2] = offset[2] + scale * tet_r[tet_i[i][j]][2];
183 normals[idx ] = -tet_r[tet_n[i]][0];
184 normals[idx+1] = -tet_r[tet_n[i]][1];
185 normals[idx+2] = -tet_r[tet_n[i]][2];
189 else if ( numLevels > 0 )
191 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
192 unsigned int stride = ipow(4,--numLevels)*TETR_VERT_ELEM_PER_TETR;
194 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
196 local_offset[0] = offset[0] + scale * tet_r[i][0];
197 local_offset[1] = offset[1] + scale * tet_r[i][1];
198 local_offset[2] = offset[2] + scale * tet_r[i][2];
199 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
204 /* -- Now the various shapes involving circles -- */
206 * Compute lookup table of cos and sin values forming a cirle
209 * It is the responsibility of the caller to free these tables
210 * The size of the table is (n+1) to form a connected loop
211 * The last entry is exactly the same as the first
212 * The sign of n can be flipped to get the reverse loop
214 static void fghCircleTable(double **sint,double **cost,const int n)
218 /* Table size, the sign of n flips the circle direction */
220 const int size = abs(n);
222 /* Determine the angle between samples */
224 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
226 /* Allocate memory for n samples, plus duplicate of first entry at the end */
228 *sint = (double *) calloc(sizeof(double), size+1);
229 *cost = (double *) calloc(sizeof(double), size+1);
231 /* Bail out if memory allocation fails, fgError never returns */
233 if (!(*sint) || !(*cost))
237 fgError("Failed to allocate memory in fghCircleTable");
240 /* Compute cos and sin around the circle */
245 for (i=1; i<size; i++)
247 (*sint)[i] = sin(angle*i);
248 (*cost)[i] = cos(angle*i);
251 /* Last sample is duplicate of the first */
253 (*sint)[size] = (*sint)[0];
254 (*cost)[size] = (*cost)[0];
258 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
260 static void fghTetrahedron( GLboolean useWireMode )
263 fghTetrahedronGenerate();
265 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
268 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
272 unsigned int numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
273 unsigned int numVert = numTetr*TETR_VERT_PER_TETR;
277 /* Allocate memory */
278 vertices = malloc(numVert*3 * sizeof(double));
279 normals = malloc(numVert*3 * sizeof(double));
281 /* Generate elements */
282 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
284 /* Draw and cleanup */
285 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
292 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
295 * Draws a wireframed cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
297 void FGAPIENTRY glutWireCube( GLdouble dSize )
299 double size = dSize * 0.5;
301 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
303 # define V(a,b,c) glVertex3d( a size, b size, c size );
304 # define N(a,b,c) glNormal3d( a, b, c );
306 /* PWO: I dared to convert the code to use macros... */
307 glBegin( GL_LINE_LOOP ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); glEnd();
308 glBegin( GL_LINE_LOOP ); N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+); glEnd();
309 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+); glEnd();
310 glBegin( GL_LINE_LOOP ); N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-); glEnd();
311 glBegin( GL_LINE_LOOP ); N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+); glEnd();
312 glBegin( GL_LINE_LOOP ); N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-); glEnd();
319 * Draws a solid cube. Code contributed by Andreas Umbach <marvin@dataway.ch>
321 void FGAPIENTRY glutSolidCube( GLdouble dSize )
323 double size = dSize * 0.5;
325 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
327 # define V(a,b,c) glVertex3d( a size, b size, c size );
328 # define N(a,b,c) glNormal3d( a, b, c );
330 /* PWO: Again, I dared to convert the code to use macros... */
332 N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+);
333 N( 0.0, 1.0, 0.0); V(+,+,+); V(+,+,-); V(-,+,-); V(-,+,+);
334 N( 0.0, 0.0, 1.0); V(+,+,+); V(-,+,+); V(-,-,+); V(+,-,+);
335 N(-1.0, 0.0, 0.0); V(-,-,+); V(-,+,+); V(-,+,-); V(-,-,-);
336 N( 0.0,-1.0, 0.0); V(-,-,+); V(-,-,-); V(+,-,-); V(+,-,+);
337 N( 0.0, 0.0,-1.0); V(-,-,-); V(-,+,-); V(+,+,-); V(+,-,-);
346 * Draws a solid sphere
348 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
352 /* Adjust z and radius as stacks are drawn. */
357 /* Pre-computed circle */
359 double *sint1,*cost1;
360 double *sint2,*cost2;
362 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
364 fghCircleTable(&sint1,&cost1,-slices);
365 fghCircleTable(&sint2,&cost2,stacks*2);
367 /* The top stack is covered with a triangle fan */
370 z1 = cost2[(stacks>0)?1:0];
372 r1 = sint2[(stacks>0)?1:0];
374 glBegin(GL_TRIANGLE_FAN);
377 glVertex3d(0,0,radius);
379 for (j=slices; j>=0; j--)
381 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
382 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
387 /* Cover each stack with a quad strip, except the top and bottom stacks */
389 for( i=1; i<stacks-1; i++ )
391 z0 = z1; z1 = cost2[i+1];
392 r0 = r1; r1 = sint2[i+1];
394 glBegin(GL_QUAD_STRIP);
396 for(j=0; j<=slices; j++)
398 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
399 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
400 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
401 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
407 /* The bottom stack is covered with a triangle fan */
412 glBegin(GL_TRIANGLE_FAN);
415 glVertex3d(0,0,-radius);
417 for (j=0; j<=slices; j++)
419 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
420 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
425 /* Release sin and cos tables */
434 * Draws a wire sphere
436 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
440 /* Adjust z and radius as stacks and slices are drawn. */
445 /* Pre-computed circle */
447 double *sint1,*cost1;
448 double *sint2,*cost2;
450 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
452 fghCircleTable(&sint1,&cost1,-slices );
453 fghCircleTable(&sint2,&cost2, stacks*2);
455 /* Draw a line loop for each stack */
457 for (i=1; i<stacks; i++)
462 glBegin(GL_LINE_LOOP);
464 for(j=0; j<=slices; j++)
470 glVertex3d(x*r*radius,y*r*radius,z*radius);
476 /* Draw a line loop for each slice */
478 for (i=0; i<slices; i++)
480 glBegin(GL_LINE_STRIP);
482 for(j=0; j<=stacks; j++)
484 x = cost1[i]*sint2[j];
485 y = sint1[i]*sint2[j];
489 glVertex3d(x*radius,y*radius,z*radius);
495 /* Release sin and cos tables */
506 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
510 /* Step in z and radius as stacks are drawn. */
515 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
516 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
518 /* Scaling factors for vertex normals */
520 const double cosn = ( height / sqrt ( height * height + base * base ));
521 const double sinn = ( base / sqrt ( height * height + base * base ));
523 /* Pre-computed circle */
527 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
529 fghCircleTable(&sint,&cost,-slices);
531 /* Cover the circular base with a triangle fan... */
539 glBegin(GL_TRIANGLE_FAN);
541 glNormal3d(0.0,0.0,-1.0);
542 glVertex3d(0.0,0.0, z0 );
544 for (j=0; j<=slices; j++)
545 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
549 /* Cover each stack with a quad strip, except the top stack */
551 for( i=0; i<stacks-1; i++ )
553 glBegin(GL_QUAD_STRIP);
555 for(j=0; j<=slices; j++)
557 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
558 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
559 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
562 z0 = z1; z1 += zStep;
563 r0 = r1; r1 -= rStep;
568 /* The top stack is covered with individual triangles */
570 glBegin(GL_TRIANGLES);
572 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
574 for (j=0; j<slices; j++)
576 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
577 glVertex3d(0, 0, height);
578 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
579 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
584 /* Release sin and cos tables */
593 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
597 /* Step in z and radius as stacks are drawn. */
602 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
603 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
605 /* Scaling factors for vertex normals */
607 const double cosn = ( height / sqrt ( height * height + base * base ));
608 const double sinn = ( base / sqrt ( height * height + base * base ));
610 /* Pre-computed circle */
614 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
616 fghCircleTable(&sint,&cost,-slices);
618 /* Draw the stacks... */
620 for (i=0; i<stacks; i++)
622 glBegin(GL_LINE_LOOP);
624 for( j=0; j<slices; j++ )
626 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
627 glVertex3d(cost[j]*r, sint[j]*r, z );
636 /* Draw the slices */
642 for (j=0; j<slices; j++)
644 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
645 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
646 glVertex3d(0.0, 0.0, height);
651 /* Release sin and cos tables */
659 * Draws a solid cylinder
661 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
665 /* Step in z and radius as stacks are drawn. */
668 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
670 /* Pre-computed circle */
674 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
676 fghCircleTable(&sint,&cost,-slices);
678 /* Cover the base and top */
680 glBegin(GL_TRIANGLE_FAN);
681 glNormal3d(0.0, 0.0, -1.0 );
682 glVertex3d(0.0, 0.0, 0.0 );
683 for (j=0; j<=slices; j++)
684 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
687 glBegin(GL_TRIANGLE_FAN);
688 glNormal3d(0.0, 0.0, 1.0 );
689 glVertex3d(0.0, 0.0, height);
690 for (j=slices; j>=0; j--)
691 glVertex3d(cost[j]*radius, sint[j]*radius, height);
699 for (i=1; i<=stacks; i++)
704 glBegin(GL_QUAD_STRIP);
705 for (j=0; j<=slices; j++ )
707 glNormal3d(cost[j], sint[j], 0.0 );
708 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
709 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
713 z0 = z1; z1 += zStep;
716 /* Release sin and cos tables */
723 * Draws a wire cylinder
725 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
729 /* Step in z and radius as stacks are drawn. */
732 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
734 /* Pre-computed circle */
738 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
740 fghCircleTable(&sint,&cost,-slices);
742 /* Draw the stacks... */
744 for (i=0; i<=stacks; i++)
749 glBegin(GL_LINE_LOOP);
751 for( j=0; j<slices; j++ )
753 glNormal3d(cost[j], sint[j], 0.0);
754 glVertex3d(cost[j]*radius, sint[j]*radius, z );
762 /* Draw the slices */
766 for (j=0; j<slices; j++)
768 glNormal3d(cost[j], sint[j], 0.0 );
769 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
770 glVertex3d(cost[j]*radius, sint[j]*radius, height);
775 /* Release sin and cos tables */
784 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
786 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
787 double *vertex, *normal;
789 double spsi, cpsi, sphi, cphi ;
791 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
793 if ( nSides < 1 ) nSides = 1;
794 if ( nRings < 1 ) nRings = 1;
796 /* Allocate the vertices array */
797 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
798 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
802 dpsi = 2.0 * M_PI / (double)nRings ;
803 dphi = -2.0 * M_PI / (double)nSides ;
806 for( j=0; j<nRings; j++ )
812 for( i=0; i<nSides; i++ )
814 int offset = 3 * ( j * nSides + i ) ;
817 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
818 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
819 *(vertex + offset + 2) = sphi * iradius ;
820 *(normal + offset + 0) = cpsi * cphi ;
821 *(normal + offset + 1) = spsi * cphi ;
822 *(normal + offset + 2) = sphi ;
829 for( i=0; i<nSides; i++ )
831 glBegin( GL_LINE_LOOP );
833 for( j=0; j<nRings; j++ )
835 int offset = 3 * ( j * nSides + i ) ;
836 glNormal3dv( normal + offset );
837 glVertex3dv( vertex + offset );
843 for( j=0; j<nRings; j++ )
845 glBegin(GL_LINE_LOOP);
847 for( i=0; i<nSides; i++ )
849 int offset = 3 * ( j * nSides + i ) ;
850 glNormal3dv( normal + offset );
851 glVertex3dv( vertex + offset );
863 * Draws a solid torus
865 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
867 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
868 double *vertex, *normal;
870 double spsi, cpsi, sphi, cphi ;
872 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
874 if ( nSides < 1 ) nSides = 1;
875 if ( nRings < 1 ) nRings = 1;
877 /* Increment the number of sides and rings to allow for one more point than surface */
881 /* Allocate the vertices array */
882 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
883 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
887 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
888 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
891 for( j=0; j<nRings; j++ )
897 for( i=0; i<nSides; i++ )
899 int offset = 3 * ( j * nSides + i ) ;
902 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
903 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
904 *(vertex + offset + 2) = sphi * iradius ;
905 *(normal + offset + 0) = cpsi * cphi ;
906 *(normal + offset + 1) = spsi * cphi ;
907 *(normal + offset + 2) = sphi ;
915 for( i=0; i<nSides-1; i++ )
917 for( j=0; j<nRings-1; j++ )
919 int offset = 3 * ( j * nSides + i ) ;
920 glNormal3dv( normal + offset );
921 glVertex3dv( vertex + offset );
922 glNormal3dv( normal + offset + 3 );
923 glVertex3dv( vertex + offset + 3 );
924 glNormal3dv( normal + offset + 3 * nSides + 3 );
925 glVertex3dv( vertex + offset + 3 * nSides + 3 );
926 glNormal3dv( normal + offset + 3 * nSides );
927 glVertex3dv( vertex + offset + 3 * nSides );
941 void FGAPIENTRY glutWireDodecahedron( void )
943 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
945 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
946 * of a cube. The coordinates of the points are:
947 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
948 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
949 * x = 0.61803398875 and z = 1.61803398875.
951 glBegin ( GL_LINE_LOOP ) ;
952 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 ) ;
954 glBegin ( GL_LINE_LOOP ) ;
955 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 ) ;
957 glBegin ( GL_LINE_LOOP ) ;
958 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 ) ;
960 glBegin ( GL_LINE_LOOP ) ;
961 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 ) ;
964 glBegin ( GL_LINE_LOOP ) ;
965 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 ) ;
967 glBegin ( GL_LINE_LOOP ) ;
968 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 ) ;
970 glBegin ( GL_LINE_LOOP ) ;
971 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 ) ;
973 glBegin ( GL_LINE_LOOP ) ;
974 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 ) ;
977 glBegin ( GL_LINE_LOOP ) ;
978 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 ) ;
980 glBegin ( GL_LINE_LOOP ) ;
981 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 ) ;
983 glBegin ( GL_LINE_LOOP ) ;
984 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 ) ;
986 glBegin ( GL_LINE_LOOP ) ;
987 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 ) ;
994 void FGAPIENTRY glutSolidDodecahedron( void )
996 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
998 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
999 * of a cube. The coordinates of the points are:
1000 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1001 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1002 * x = 0.61803398875 and z = 1.61803398875.
1004 glBegin ( GL_POLYGON ) ;
1005 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 ) ;
1007 glBegin ( GL_POLYGON ) ;
1008 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 ) ;
1010 glBegin ( GL_POLYGON ) ;
1011 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 ) ;
1013 glBegin ( GL_POLYGON ) ;
1014 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 ) ;
1017 glBegin ( GL_POLYGON ) ;
1018 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 ) ;
1020 glBegin ( GL_POLYGON ) ;
1021 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 ) ;
1023 glBegin ( GL_POLYGON ) ;
1024 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 ) ;
1026 glBegin ( GL_POLYGON ) ;
1027 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 ) ;
1030 glBegin ( GL_POLYGON ) ;
1031 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 ) ;
1033 glBegin ( GL_POLYGON ) ;
1034 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 ) ;
1036 glBegin ( GL_POLYGON ) ;
1037 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 ) ;
1039 glBegin ( GL_POLYGON ) ;
1040 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 ) ;
1047 void FGAPIENTRY glutWireOctahedron( void )
1049 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1052 glBegin( GL_LINE_LOOP );
1053 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 );
1054 glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
1055 glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
1056 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 );
1057 glNormal3d(-0.577350269189, 0.577350269189, 0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
1058 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 );
1059 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 );
1060 glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
1068 void FGAPIENTRY glutSolidOctahedron( void )
1070 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1073 glBegin( GL_TRIANGLES );
1074 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 );
1075 glNormal3d( 0.577350269189, 0.577350269189,-0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
1076 glNormal3d( 0.577350269189,-0.577350269189, 0.577350269189); glVertex3d( RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
1077 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 );
1078 glNormal3d(-0.577350269189, 0.577350269189, 0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0, RADIUS ); glVertex3d( 0.0, RADIUS, 0.0 );
1079 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 );
1080 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 );
1081 glNormal3d(-0.577350269189,-0.577350269189,-0.577350269189); glVertex3d(-RADIUS, 0.0, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
1089 static double icos_r[12][3] = {
1091 { 0.447213595500, 0.894427191000, 0.0 },
1092 { 0.447213595500, 0.276393202252, 0.850650808354 },
1093 { 0.447213595500, -0.723606797748, 0.525731112119 },
1094 { 0.447213595500, -0.723606797748, -0.525731112119 },
1095 { 0.447213595500, 0.276393202252, -0.850650808354 },
1096 { -0.447213595500, -0.894427191000, 0.0 },
1097 { -0.447213595500, -0.276393202252, 0.850650808354 },
1098 { -0.447213595500, 0.723606797748, 0.525731112119 },
1099 { -0.447213595500, 0.723606797748, -0.525731112119 },
1100 { -0.447213595500, -0.276393202252, -0.850650808354 },
1104 static int icos_v [20][3] = {
1127 void FGAPIENTRY glutWireIcosahedron( void )
1131 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1133 for ( i = 0; i < 20; i++ )
1136 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] ) ;
1137 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] ) ;
1138 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] ) ;
1139 glBegin ( GL_LINE_LOOP ) ;
1140 glNormal3dv ( normal ) ;
1141 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1142 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1143 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1151 void FGAPIENTRY glutSolidIcosahedron( void )
1155 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1157 glBegin ( GL_TRIANGLES ) ;
1158 for ( i = 0; i < 20; i++ )
1161 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] ) ;
1162 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] ) ;
1163 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] ) ;
1164 glNormal3dv ( normal ) ;
1165 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1166 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1167 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1176 static double rdod_r[14][3] = {
1178 { 0.707106781187, 0.000000000000, 0.5 },
1179 { 0.000000000000, 0.707106781187, 0.5 },
1180 { -0.707106781187, 0.000000000000, 0.5 },
1181 { 0.000000000000, -0.707106781187, 0.5 },
1182 { 0.707106781187, 0.707106781187, 0.0 },
1183 { -0.707106781187, 0.707106781187, 0.0 },
1184 { -0.707106781187, -0.707106781187, 0.0 },
1185 { 0.707106781187, -0.707106781187, 0.0 },
1186 { 0.707106781187, 0.000000000000, -0.5 },
1187 { 0.000000000000, 0.707106781187, -0.5 },
1188 { -0.707106781187, 0.000000000000, -0.5 },
1189 { 0.000000000000, -0.707106781187, -0.5 },
1193 static int rdod_v [12][4] = {
1208 static double rdod_n[12][3] = {
1209 { 0.353553390594, 0.353553390594, 0.5 },
1210 { -0.353553390594, 0.353553390594, 0.5 },
1211 { -0.353553390594, -0.353553390594, 0.5 },
1212 { 0.353553390594, -0.353553390594, 0.5 },
1213 { 0.000000000000, 1.000000000000, 0.0 },
1214 { -1.000000000000, 0.000000000000, 0.0 },
1215 { 0.000000000000, -1.000000000000, 0.0 },
1216 { 1.000000000000, 0.000000000000, 0.0 },
1217 { 0.353553390594, 0.353553390594, -0.5 },
1218 { -0.353553390594, 0.353553390594, -0.5 },
1219 { -0.353553390594, -0.353553390594, -0.5 },
1220 { 0.353553390594, -0.353553390594, -0.5 }
1223 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1227 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1229 for ( i = 0; i < 12; i++ )
1231 glBegin ( GL_LINE_LOOP ) ;
1232 glNormal3dv ( rdod_n[i] ) ;
1233 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1234 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1235 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1236 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1244 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1248 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1250 glBegin ( GL_QUADS ) ;
1251 for ( i = 0; i < 12; i++ )
1253 glNormal3dv ( rdod_n[i] ) ;
1254 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1255 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1256 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1257 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1265 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1268 void FGAPIENTRY glutWireTetrahedron( void )
1270 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1271 fghTetrahedron( TRUE );
1273 void FGAPIENTRY glutSolidTetrahedron( void )
1275 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1276 fghTetrahedron( FALSE );
1279 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1281 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1282 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1284 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1286 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1287 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1291 /*** END OF FILE ***/