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
64 /* General function for drawing geometry. As for all geometry we have no
65 * redundancy (or hardly any in the case of cones and cylinders) in terms
66 * of the vertex/normal combinations, we just use glDrawArrays.
67 * useWireMode controls the drawing of solids (false) or wire frame
68 * versions (TRUE) of the geometry you pass
70 static void fghDrawGeometry(GLenum vertexMode, double* vertices, double* normals, GLsizei numVertices, GLboolean useWireMode)
74 glPushAttrib(GL_POLYGON_BIT);
75 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
78 glEnableClientState(GL_VERTEX_ARRAY);
79 glEnableClientState(GL_NORMAL_ARRAY);
81 glVertexPointer(3, GL_DOUBLE, 0, vertices);
82 glNormalPointer(GL_DOUBLE, 0, normals);
83 glDrawArrays(vertexMode,0,numVertices);
85 glDisableClientState(GL_VERTEX_ARRAY);
86 glDisableClientState(GL_NORMAL_ARRAY);
95 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
96 static unsigned int ipow (int x, unsigned int y)
98 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
101 /* -- stuff that can be cached -- */
103 * In general, we build arrays with all vertices or normals.
104 * We cant compress this and use glDrawElements as all combinations of
105 * vertex and normals are unique.
109 #define CUBE_NUM_VERT 8
110 #define CUBE_NUM_FACES 6
111 #define CUBE_NUM_VERT_PER_FACE 4
112 #define CUBE_VERT_PER_TETR CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE
113 #define CUBE_VERT_ELEM_PER_TETR CUBE_VERT_PER_TETR*3
114 /* Vertex Coordinates */
115 static GLdouble cube_v[CUBE_NUM_VERT][3] =
127 static GLdouble cube_n[CUBE_NUM_FACES][3] =
138 static GLubyte cube_vi[CUBE_NUM_FACES][CUBE_NUM_VERT_PER_FACE] =
140 {0,1,2,3}, {0,3,4,5}, {0,5,6,1}, {1,6,7,2}, {7,4,3,2}, {4,7,6,5}
143 /* Cache of input to glDrawArrays */
144 static GLboolean cubeCached = FALSE;
145 static double cube_verts[CUBE_VERT_ELEM_PER_TETR];
146 static double cube_norms[CUBE_VERT_ELEM_PER_TETR];
148 static void fghCubeGenerate()
151 for (i=0; i<CUBE_NUM_FACES; i++)
153 for (j=0; j<CUBE_NUM_VERT_PER_FACE; j++)
155 int idx = i*CUBE_NUM_VERT_PER_FACE*3+j*3;
156 cube_verts[idx ] = cube_v[cube_vi[i][j]][0];
157 cube_verts[idx+1] = cube_v[cube_vi[i][j]][1];
158 cube_verts[idx+2] = cube_v[cube_vi[i][j]][2];
160 cube_norms[idx ] = cube_n[i][0];
161 cube_norms[idx+1] = cube_n[i][1];
162 cube_norms[idx+2] = cube_n[i][2];
167 /* -- Tetrahedron -- */
168 /* Magic Numbers: r0 = ( 1, 0, 0 )
169 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
170 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
171 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
172 * |r0| = |r1| = |r2| = |r3| = 1
173 * Distance between any two points is 2 sqrt(6) / 3
175 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
177 #define TETR_NUM_VERT 4
178 #define TETR_NUM_FACES 4
179 #define TETR_NUM_VERT_PER_FACE 3
180 #define TETR_VERT_PER_TETR TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE
181 #define TETR_VERT_ELEM_PER_TETR TETR_VERT_PER_TETR*3
183 /* Vertex Coordinates */
184 static GLdouble tet_r[TETR_NUM_VERT][TETR_NUM_VERT_PER_FACE] =
187 { -0.333333333333, 0.942809041582, 0.0 },
188 { -0.333333333333, -0.471404520791, 0.816496580928 },
189 { -0.333333333333, -0.471404520791, -0.816496580928 }
192 static GLdouble tet_n[CUBE_NUM_FACES][3] =
195 { 0.333333333333, -0.942809041582, 0.0 },
196 { 0.333333333333, 0.471404520791, -0.816496580928 },
197 { 0.333333333333, 0.471404520791, 0.816496580928 }
201 static GLubyte tet_i[TETR_NUM_FACES][TETR_NUM_VERT_PER_FACE] =
203 { 1, 3, 2 }, { 0, 2, 3 }, { 0, 3, 1 }, { 0, 1, 2 }
206 /* Cache of input to glDrawArrays */
207 static GLboolean tetrCached = FALSE;
208 static double tetr_verts[TETR_VERT_ELEM_PER_TETR];
209 static double tetr_norms[TETR_VERT_ELEM_PER_TETR];
211 static void fghTetrahedronGenerate()
215 * Build array with vertices from vertex coordinates and vertex indices
216 * Do same for normals.
217 * Need to do this because of different normals at shared vertices
218 * (and because normals' coordinates need to be negated).
220 for (i=0; i<TETR_NUM_FACES; i++)
222 for (j=0; j<TETR_NUM_VERT_PER_FACE; j++)
224 int idx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
225 tetr_verts[idx ] = tet_r[tet_i[i][j]][0];
226 tetr_verts[idx+1] = tet_r[tet_i[i][j]][1];
227 tetr_verts[idx+2] = tet_r[tet_i[i][j]][2];
229 tetr_norms[idx ] = tet_n[i][0];
230 tetr_norms[idx+1] = tet_n[i][1];
231 tetr_norms[idx+2] = tet_n[i][2];
236 /* -- Sierpinski Sponge -- */
237 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, double* vertices, double* normals )
240 if ( numLevels == 0 )
242 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
244 for ( j = 0; j < TETR_NUM_VERT_PER_FACE; j++ )
246 int idx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
247 vertices[idx ] = offset[0] + scale * tet_r[tet_i[i][j]][0];
248 vertices[idx+1] = offset[1] + scale * tet_r[tet_i[i][j]][1];
249 vertices[idx+2] = offset[2] + scale * tet_r[tet_i[i][j]][2];
251 normals [idx ] = -tet_r[i][0];
252 normals [idx+1] = -tet_r[i][1];
253 normals [idx+2] = -tet_r[i][2];
257 else if ( numLevels > 0 )
259 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
260 unsigned int stride = ipow(4,--numLevels)*TETR_VERT_ELEM_PER_TETR;
262 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
264 local_offset[0] = offset[0] + scale * tet_r[i][0];
265 local_offset[1] = offset[1] + scale * tet_r[i][1];
266 local_offset[2] = offset[2] + scale * tet_r[i][2];
267 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
272 /* -- Now the various shapes involving circles -- */
274 * Compute lookup table of cos and sin values forming a cirle
277 * It is the responsibility of the caller to free these tables
278 * The size of the table is (n+1) to form a connected loop
279 * The last entry is exactly the same as the first
280 * The sign of n can be flipped to get the reverse loop
282 static void fghCircleTable(double **sint,double **cost,const int n)
286 /* Table size, the sign of n flips the circle direction */
288 const int size = abs(n);
290 /* Determine the angle between samples */
292 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
294 /* Allocate memory for n samples, plus duplicate of first entry at the end */
296 *sint = (double *) calloc(sizeof(double), size+1);
297 *cost = (double *) calloc(sizeof(double), size+1);
299 /* Bail out if memory allocation fails, fgError never returns */
301 if (!(*sint) || !(*cost))
305 fgError("Failed to allocate memory in fghCircleTable");
308 /* Compute cos and sin around the circle */
313 for (i=1; i<size; i++)
315 (*sint)[i] = sin(angle*i);
316 (*cost)[i] = cos(angle*i);
319 /* Last sample is duplicate of the first */
321 (*sint)[size] = (*sint)[0];
322 (*cost)[size] = (*cost)[0];
326 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
328 static void fghCube( GLdouble dSize, GLboolean useWireMode )
335 /* Need to build new */
336 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
339 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
342 static void fghTetrahedron( GLboolean useWireMode )
345 fghTetrahedronGenerate();
347 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
350 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
354 unsigned int numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
355 unsigned int numVert = numTetr*TETR_VERT_PER_TETR;
359 /* Allocate memory */
360 vertices = malloc(numVert*3 * sizeof(double));
361 normals = malloc(numVert*3 * sizeof(double));
363 /* Generate elements */
364 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
366 /* Draw and cleanup */
367 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
374 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
378 * Draws a solid sphere
380 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
384 /* Adjust z and radius as stacks are drawn. */
389 /* Pre-computed circle */
391 double *sint1,*cost1;
392 double *sint2,*cost2;
394 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
396 fghCircleTable(&sint1,&cost1,-slices);
397 fghCircleTable(&sint2,&cost2,stacks*2);
399 /* The top stack is covered with a triangle fan */
402 z1 = cost2[(stacks>0)?1:0];
404 r1 = sint2[(stacks>0)?1:0];
406 glBegin(GL_TRIANGLE_FAN);
409 glVertex3d(0,0,radius);
411 for (j=slices; j>=0; j--)
413 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
414 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
419 /* Cover each stack with a quad strip, except the top and bottom stacks */
421 for( i=1; i<stacks-1; i++ )
423 z0 = z1; z1 = cost2[i+1];
424 r0 = r1; r1 = sint2[i+1];
426 glBegin(GL_QUAD_STRIP);
428 for(j=0; j<=slices; j++)
430 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
431 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
432 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
433 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
439 /* The bottom stack is covered with a triangle fan */
444 glBegin(GL_TRIANGLE_FAN);
447 glVertex3d(0,0,-radius);
449 for (j=0; j<=slices; j++)
451 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
452 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
457 /* Release sin and cos tables */
466 * Draws a wire sphere
468 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
472 /* Adjust z and radius as stacks and slices are drawn. */
477 /* Pre-computed circle */
479 double *sint1,*cost1;
480 double *sint2,*cost2;
482 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
484 fghCircleTable(&sint1,&cost1,-slices );
485 fghCircleTable(&sint2,&cost2, stacks*2);
487 /* Draw a line loop for each stack */
489 for (i=1; i<stacks; i++)
494 glBegin(GL_LINE_LOOP);
496 for(j=0; j<=slices; j++)
502 glVertex3d(x*r*radius,y*r*radius,z*radius);
508 /* Draw a line loop for each slice */
510 for (i=0; i<slices; i++)
512 glBegin(GL_LINE_STRIP);
514 for(j=0; j<=stacks; j++)
516 x = cost1[i]*sint2[j];
517 y = sint1[i]*sint2[j];
521 glVertex3d(x*radius,y*radius,z*radius);
527 /* Release sin and cos tables */
538 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
542 /* Step in z and radius as stacks are drawn. */
547 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
548 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
550 /* Scaling factors for vertex normals */
552 const double cosn = ( height / sqrt ( height * height + base * base ));
553 const double sinn = ( base / sqrt ( height * height + base * base ));
555 /* Pre-computed circle */
559 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
561 fghCircleTable(&sint,&cost,-slices);
563 /* Cover the circular base with a triangle fan... */
571 glBegin(GL_TRIANGLE_FAN);
573 glNormal3d(0.0,0.0,-1.0);
574 glVertex3d(0.0,0.0, z0 );
576 for (j=0; j<=slices; j++)
577 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
581 /* Cover each stack with a quad strip, except the top stack */
583 for( i=0; i<stacks-1; i++ )
585 glBegin(GL_QUAD_STRIP);
587 for(j=0; j<=slices; j++)
589 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
590 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
591 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
594 z0 = z1; z1 += zStep;
595 r0 = r1; r1 -= rStep;
600 /* The top stack is covered with individual triangles */
602 glBegin(GL_TRIANGLES);
604 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
606 for (j=0; j<slices; j++)
608 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
609 glVertex3d(0, 0, height);
610 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
611 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
616 /* Release sin and cos tables */
625 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
629 /* Step in z and radius as stacks are drawn. */
634 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
635 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
637 /* Scaling factors for vertex normals */
639 const double cosn = ( height / sqrt ( height * height + base * base ));
640 const double sinn = ( base / sqrt ( height * height + base * base ));
642 /* Pre-computed circle */
646 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
648 fghCircleTable(&sint,&cost,-slices);
650 /* Draw the stacks... */
652 for (i=0; i<stacks; i++)
654 glBegin(GL_LINE_LOOP);
656 for( j=0; j<slices; j++ )
658 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
659 glVertex3d(cost[j]*r, sint[j]*r, z );
668 /* Draw the slices */
674 for (j=0; j<slices; j++)
676 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
677 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
678 glVertex3d(0.0, 0.0, height);
683 /* Release sin and cos tables */
691 * Draws a solid cylinder
693 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
697 /* Step in z and radius as stacks are drawn. */
700 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
702 /* Pre-computed circle */
706 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
708 fghCircleTable(&sint,&cost,-slices);
710 /* Cover the base and top */
712 glBegin(GL_TRIANGLE_FAN);
713 glNormal3d(0.0, 0.0, -1.0 );
714 glVertex3d(0.0, 0.0, 0.0 );
715 for (j=0; j<=slices; j++)
716 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
719 glBegin(GL_TRIANGLE_FAN);
720 glNormal3d(0.0, 0.0, 1.0 );
721 glVertex3d(0.0, 0.0, height);
722 for (j=slices; j>=0; j--)
723 glVertex3d(cost[j]*radius, sint[j]*radius, height);
731 for (i=1; i<=stacks; i++)
736 glBegin(GL_QUAD_STRIP);
737 for (j=0; j<=slices; j++ )
739 glNormal3d(cost[j], sint[j], 0.0 );
740 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
741 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
745 z0 = z1; z1 += zStep;
748 /* Release sin and cos tables */
755 * Draws a wire cylinder
757 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
761 /* Step in z and radius as stacks are drawn. */
764 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
766 /* Pre-computed circle */
770 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
772 fghCircleTable(&sint,&cost,-slices);
774 /* Draw the stacks... */
776 for (i=0; i<=stacks; i++)
781 glBegin(GL_LINE_LOOP);
783 for( j=0; j<slices; j++ )
785 glNormal3d(cost[j], sint[j], 0.0);
786 glVertex3d(cost[j]*radius, sint[j]*radius, z );
794 /* Draw the slices */
798 for (j=0; j<slices; j++)
800 glNormal3d(cost[j], sint[j], 0.0 );
801 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
802 glVertex3d(cost[j]*radius, sint[j]*radius, height);
807 /* Release sin and cos tables */
816 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
818 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
819 double *vertex, *normal;
821 double spsi, cpsi, sphi, cphi ;
823 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
825 if ( nSides < 1 ) nSides = 1;
826 if ( nRings < 1 ) nRings = 1;
828 /* Allocate the vertices array */
829 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
830 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
834 dpsi = 2.0 * M_PI / (double)nRings ;
835 dphi = -2.0 * M_PI / (double)nSides ;
838 for( j=0; j<nRings; j++ )
844 for( i=0; i<nSides; i++ )
846 int offset = 3 * ( j * nSides + i ) ;
849 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
850 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
851 *(vertex + offset + 2) = sphi * iradius ;
852 *(normal + offset + 0) = cpsi * cphi ;
853 *(normal + offset + 1) = spsi * cphi ;
854 *(normal + offset + 2) = sphi ;
861 for( i=0; i<nSides; i++ )
863 glBegin( GL_LINE_LOOP );
865 for( j=0; j<nRings; j++ )
867 int offset = 3 * ( j * nSides + i ) ;
868 glNormal3dv( normal + offset );
869 glVertex3dv( vertex + offset );
875 for( j=0; j<nRings; j++ )
877 glBegin(GL_LINE_LOOP);
879 for( i=0; i<nSides; i++ )
881 int offset = 3 * ( j * nSides + i ) ;
882 glNormal3dv( normal + offset );
883 glVertex3dv( vertex + offset );
895 * Draws a solid torus
897 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
899 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
900 double *vertex, *normal;
902 double spsi, cpsi, sphi, cphi ;
904 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
906 if ( nSides < 1 ) nSides = 1;
907 if ( nRings < 1 ) nRings = 1;
909 /* Increment the number of sides and rings to allow for one more point than surface */
913 /* Allocate the vertices array */
914 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
915 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
919 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
920 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
923 for( j=0; j<nRings; j++ )
929 for( i=0; i<nSides; i++ )
931 int offset = 3 * ( j * nSides + i ) ;
934 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
935 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
936 *(vertex + offset + 2) = sphi * iradius ;
937 *(normal + offset + 0) = cpsi * cphi ;
938 *(normal + offset + 1) = spsi * cphi ;
939 *(normal + offset + 2) = sphi ;
947 for( i=0; i<nSides-1; i++ )
949 for( j=0; j<nRings-1; j++ )
951 int offset = 3 * ( j * nSides + i ) ;
952 glNormal3dv( normal + offset );
953 glVertex3dv( vertex + offset );
954 glNormal3dv( normal + offset + 3 );
955 glVertex3dv( vertex + offset + 3 );
956 glNormal3dv( normal + offset + 3 * nSides + 3 );
957 glVertex3dv( vertex + offset + 3 * nSides + 3 );
958 glNormal3dv( normal + offset + 3 * nSides );
959 glVertex3dv( vertex + offset + 3 * nSides );
973 void FGAPIENTRY glutWireDodecahedron( void )
975 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
977 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
978 * of a cube. The coordinates of the points are:
979 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
980 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
981 * x = 0.61803398875 and z = 1.61803398875.
983 glBegin ( GL_LINE_LOOP ) ;
984 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 ) ;
986 glBegin ( GL_LINE_LOOP ) ;
987 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 ) ;
989 glBegin ( GL_LINE_LOOP ) ;
990 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 ) ;
992 glBegin ( GL_LINE_LOOP ) ;
993 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 ) ;
996 glBegin ( GL_LINE_LOOP ) ;
997 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 ) ;
999 glBegin ( GL_LINE_LOOP ) ;
1000 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 ) ;
1002 glBegin ( GL_LINE_LOOP ) ;
1003 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 ) ;
1005 glBegin ( GL_LINE_LOOP ) ;
1006 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 ) ;
1009 glBegin ( GL_LINE_LOOP ) ;
1010 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 ) ;
1012 glBegin ( GL_LINE_LOOP ) ;
1013 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 ) ;
1015 glBegin ( GL_LINE_LOOP ) ;
1016 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 ) ;
1018 glBegin ( GL_LINE_LOOP ) ;
1019 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 ) ;
1026 void FGAPIENTRY glutSolidDodecahedron( void )
1028 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1030 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1031 * of a cube. The coordinates of the points are:
1032 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1033 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1034 * x = 0.61803398875 and z = 1.61803398875.
1036 glBegin ( GL_POLYGON ) ;
1037 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 ) ;
1039 glBegin ( GL_POLYGON ) ;
1040 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 ) ;
1042 glBegin ( GL_POLYGON ) ;
1043 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 ) ;
1045 glBegin ( GL_POLYGON ) ;
1046 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 ) ;
1049 glBegin ( GL_POLYGON ) ;
1050 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 ) ;
1052 glBegin ( GL_POLYGON ) ;
1053 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 ) ;
1055 glBegin ( GL_POLYGON ) ;
1056 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 ) ;
1058 glBegin ( GL_POLYGON ) ;
1059 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 ) ;
1062 glBegin ( GL_POLYGON ) ;
1063 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 ) ;
1065 glBegin ( GL_POLYGON ) ;
1066 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 ) ;
1068 glBegin ( GL_POLYGON ) ;
1069 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 ) ;
1071 glBegin ( GL_POLYGON ) ;
1072 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 ) ;
1079 void FGAPIENTRY glutWireOctahedron( void )
1081 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1084 glBegin( GL_LINE_LOOP );
1085 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 );
1086 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 );
1087 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 );
1088 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 );
1089 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 );
1090 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 );
1091 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 );
1092 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 );
1100 void FGAPIENTRY glutSolidOctahedron( void )
1102 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1105 glBegin( GL_TRIANGLES );
1106 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 );
1107 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 );
1108 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 );
1109 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 );
1110 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 );
1111 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 );
1112 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 );
1113 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 );
1121 static double icos_r[12][3] = {
1123 { 0.447213595500, 0.894427191000, 0.0 },
1124 { 0.447213595500, 0.276393202252, 0.850650808354 },
1125 { 0.447213595500, -0.723606797748, 0.525731112119 },
1126 { 0.447213595500, -0.723606797748, -0.525731112119 },
1127 { 0.447213595500, 0.276393202252, -0.850650808354 },
1128 { -0.447213595500, -0.894427191000, 0.0 },
1129 { -0.447213595500, -0.276393202252, 0.850650808354 },
1130 { -0.447213595500, 0.723606797748, 0.525731112119 },
1131 { -0.447213595500, 0.723606797748, -0.525731112119 },
1132 { -0.447213595500, -0.276393202252, -0.850650808354 },
1136 static int icos_v [20][3] = {
1159 void FGAPIENTRY glutWireIcosahedron( void )
1163 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1165 for ( i = 0; i < 20; i++ )
1168 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] ) ;
1169 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] ) ;
1170 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] ) ;
1171 glBegin ( GL_LINE_LOOP ) ;
1172 glNormal3dv ( normal ) ;
1173 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1174 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1175 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1183 void FGAPIENTRY glutSolidIcosahedron( void )
1187 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1189 glBegin ( GL_TRIANGLES ) ;
1190 for ( i = 0; i < 20; i++ )
1193 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] ) ;
1194 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] ) ;
1195 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] ) ;
1196 glNormal3dv ( normal ) ;
1197 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1198 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1199 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1208 static double rdod_r[14][3] = {
1210 { 0.707106781187, 0.000000000000, 0.5 },
1211 { 0.000000000000, 0.707106781187, 0.5 },
1212 { -0.707106781187, 0.000000000000, 0.5 },
1213 { 0.000000000000, -0.707106781187, 0.5 },
1214 { 0.707106781187, 0.707106781187, 0.0 },
1215 { -0.707106781187, 0.707106781187, 0.0 },
1216 { -0.707106781187, -0.707106781187, 0.0 },
1217 { 0.707106781187, -0.707106781187, 0.0 },
1218 { 0.707106781187, 0.000000000000, -0.5 },
1219 { 0.000000000000, 0.707106781187, -0.5 },
1220 { -0.707106781187, 0.000000000000, -0.5 },
1221 { 0.000000000000, -0.707106781187, -0.5 },
1225 static int rdod_v [12][4] = {
1240 static double rdod_n[12][3] = {
1241 { 0.353553390594, 0.353553390594, 0.5 },
1242 { -0.353553390594, 0.353553390594, 0.5 },
1243 { -0.353553390594, -0.353553390594, 0.5 },
1244 { 0.353553390594, -0.353553390594, 0.5 },
1245 { 0.000000000000, 1.000000000000, 0.0 },
1246 { -1.000000000000, 0.000000000000, 0.0 },
1247 { 0.000000000000, -1.000000000000, 0.0 },
1248 { 1.000000000000, 0.000000000000, 0.0 },
1249 { 0.353553390594, 0.353553390594, -0.5 },
1250 { -0.353553390594, 0.353553390594, -0.5 },
1251 { -0.353553390594, -0.353553390594, -0.5 },
1252 { 0.353553390594, -0.353553390594, -0.5 }
1255 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1259 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1261 for ( i = 0; i < 12; i++ )
1263 glBegin ( GL_LINE_LOOP ) ;
1264 glNormal3dv ( rdod_n[i] ) ;
1265 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1266 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1267 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1268 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1276 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1280 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1282 glBegin ( GL_QUADS ) ;
1283 for ( i = 0; i < 12; i++ )
1285 glNormal3dv ( rdod_n[i] ) ;
1286 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1287 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1288 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1289 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1297 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1299 * Draws a wireframed cube.
1301 void FGAPIENTRY glutWireCube( GLdouble dSize )
1303 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1304 fghCube( dSize, TRUE );
1306 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1308 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1309 fghCube( dSize, FALSE );
1312 void FGAPIENTRY glutWireTetrahedron( void )
1314 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1315 fghTetrahedron( TRUE );
1317 void FGAPIENTRY glutSolidTetrahedron( void )
1319 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1320 fghTetrahedron( FALSE );
1323 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1325 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1326 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1328 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1330 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1331 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1335 /*** END OF FILE ***/