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][3] =
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 )
338 /* Need to build new */
339 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
342 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
345 static void fghTetrahedron( GLboolean useWireMode )
349 fghTetrahedronGenerate();
353 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
356 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
360 unsigned int numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
361 unsigned int numVert = numTetr*TETR_VERT_PER_TETR;
365 /* Allocate memory */
366 vertices = malloc(numVert*3 * sizeof(double));
367 normals = malloc(numVert*3 * sizeof(double));
369 /* Generate elements */
370 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
372 /* Draw and cleanup */
373 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
380 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
384 * Draws a solid sphere
386 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
390 /* Adjust z and radius as stacks are drawn. */
395 /* Pre-computed circle */
397 double *sint1,*cost1;
398 double *sint2,*cost2;
400 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
402 fghCircleTable(&sint1,&cost1,-slices);
403 fghCircleTable(&sint2,&cost2,stacks*2);
405 /* The top stack is covered with a triangle fan */
408 z1 = cost2[(stacks>0)?1:0];
410 r1 = sint2[(stacks>0)?1:0];
412 glBegin(GL_TRIANGLE_FAN);
415 glVertex3d(0,0,radius);
417 for (j=slices; j>=0; j--)
419 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
420 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
425 /* Cover each stack with a quad strip, except the top and bottom stacks */
427 for( i=1; i<stacks-1; i++ )
429 z0 = z1; z1 = cost2[i+1];
430 r0 = r1; r1 = sint2[i+1];
432 glBegin(GL_QUAD_STRIP);
434 for(j=0; j<=slices; j++)
436 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
437 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
438 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
439 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
445 /* The bottom stack is covered with a triangle fan */
450 glBegin(GL_TRIANGLE_FAN);
453 glVertex3d(0,0,-radius);
455 for (j=0; j<=slices; j++)
457 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
458 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
463 /* Release sin and cos tables */
472 * Draws a wire sphere
474 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
478 /* Adjust z and radius as stacks and slices are drawn. */
483 /* Pre-computed circle */
485 double *sint1,*cost1;
486 double *sint2,*cost2;
488 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
490 fghCircleTable(&sint1,&cost1,-slices );
491 fghCircleTable(&sint2,&cost2, stacks*2);
493 /* Draw a line loop for each stack */
495 for (i=1; i<stacks; i++)
500 glBegin(GL_LINE_LOOP);
502 for(j=0; j<=slices; j++)
508 glVertex3d(x*r*radius,y*r*radius,z*radius);
514 /* Draw a line loop for each slice */
516 for (i=0; i<slices; i++)
518 glBegin(GL_LINE_STRIP);
520 for(j=0; j<=stacks; j++)
522 x = cost1[i]*sint2[j];
523 y = sint1[i]*sint2[j];
527 glVertex3d(x*radius,y*radius,z*radius);
533 /* Release sin and cos tables */
544 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
548 /* Step in z and radius as stacks are drawn. */
553 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
554 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
556 /* Scaling factors for vertex normals */
558 const double cosn = ( height / sqrt ( height * height + base * base ));
559 const double sinn = ( base / sqrt ( height * height + base * base ));
561 /* Pre-computed circle */
565 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
567 fghCircleTable(&sint,&cost,-slices);
569 /* Cover the circular base with a triangle fan... */
577 glBegin(GL_TRIANGLE_FAN);
579 glNormal3d(0.0,0.0,-1.0);
580 glVertex3d(0.0,0.0, z0 );
582 for (j=0; j<=slices; j++)
583 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
587 /* Cover each stack with a quad strip, except the top stack */
589 for( i=0; i<stacks-1; i++ )
591 glBegin(GL_QUAD_STRIP);
593 for(j=0; j<=slices; j++)
595 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
596 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
597 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
600 z0 = z1; z1 += zStep;
601 r0 = r1; r1 -= rStep;
606 /* The top stack is covered with individual triangles */
608 glBegin(GL_TRIANGLES);
610 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
612 for (j=0; j<slices; j++)
614 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
615 glVertex3d(0, 0, height);
616 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
617 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
622 /* Release sin and cos tables */
631 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
635 /* Step in z and radius as stacks are drawn. */
640 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
641 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
643 /* Scaling factors for vertex normals */
645 const double cosn = ( height / sqrt ( height * height + base * base ));
646 const double sinn = ( base / sqrt ( height * height + base * base ));
648 /* Pre-computed circle */
652 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
654 fghCircleTable(&sint,&cost,-slices);
656 /* Draw the stacks... */
658 for (i=0; i<stacks; i++)
660 glBegin(GL_LINE_LOOP);
662 for( j=0; j<slices; j++ )
664 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
665 glVertex3d(cost[j]*r, sint[j]*r, z );
674 /* Draw the slices */
680 for (j=0; j<slices; j++)
682 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
683 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
684 glVertex3d(0.0, 0.0, height);
689 /* Release sin and cos tables */
697 * Draws a solid cylinder
699 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
703 /* Step in z and radius as stacks are drawn. */
706 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
708 /* Pre-computed circle */
712 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
714 fghCircleTable(&sint,&cost,-slices);
716 /* Cover the base and top */
718 glBegin(GL_TRIANGLE_FAN);
719 glNormal3d(0.0, 0.0, -1.0 );
720 glVertex3d(0.0, 0.0, 0.0 );
721 for (j=0; j<=slices; j++)
722 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
725 glBegin(GL_TRIANGLE_FAN);
726 glNormal3d(0.0, 0.0, 1.0 );
727 glVertex3d(0.0, 0.0, height);
728 for (j=slices; j>=0; j--)
729 glVertex3d(cost[j]*radius, sint[j]*radius, height);
737 for (i=1; i<=stacks; i++)
742 glBegin(GL_QUAD_STRIP);
743 for (j=0; j<=slices; j++ )
745 glNormal3d(cost[j], sint[j], 0.0 );
746 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
747 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
751 z0 = z1; z1 += zStep;
754 /* Release sin and cos tables */
761 * Draws a wire cylinder
763 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
767 /* Step in z and radius as stacks are drawn. */
770 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
772 /* Pre-computed circle */
776 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
778 fghCircleTable(&sint,&cost,-slices);
780 /* Draw the stacks... */
782 for (i=0; i<=stacks; i++)
787 glBegin(GL_LINE_LOOP);
789 for( j=0; j<slices; j++ )
791 glNormal3d(cost[j], sint[j], 0.0);
792 glVertex3d(cost[j]*radius, sint[j]*radius, z );
800 /* Draw the slices */
804 for (j=0; j<slices; j++)
806 glNormal3d(cost[j], sint[j], 0.0 );
807 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
808 glVertex3d(cost[j]*radius, sint[j]*radius, height);
813 /* Release sin and cos tables */
822 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
824 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
825 double *vertex, *normal;
827 double spsi, cpsi, sphi, cphi ;
829 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
831 if ( nSides < 1 ) nSides = 1;
832 if ( nRings < 1 ) nRings = 1;
834 /* Allocate the vertices array */
835 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
836 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
840 dpsi = 2.0 * M_PI / (double)nRings ;
841 dphi = -2.0 * M_PI / (double)nSides ;
844 for( j=0; j<nRings; j++ )
850 for( i=0; i<nSides; i++ )
852 int offset = 3 * ( j * nSides + i ) ;
855 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
856 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
857 *(vertex + offset + 2) = sphi * iradius ;
858 *(normal + offset + 0) = cpsi * cphi ;
859 *(normal + offset + 1) = spsi * cphi ;
860 *(normal + offset + 2) = sphi ;
867 for( i=0; i<nSides; i++ )
869 glBegin( GL_LINE_LOOP );
871 for( j=0; j<nRings; j++ )
873 int offset = 3 * ( j * nSides + i ) ;
874 glNormal3dv( normal + offset );
875 glVertex3dv( vertex + offset );
881 for( j=0; j<nRings; j++ )
883 glBegin(GL_LINE_LOOP);
885 for( i=0; i<nSides; i++ )
887 int offset = 3 * ( j * nSides + i ) ;
888 glNormal3dv( normal + offset );
889 glVertex3dv( vertex + offset );
901 * Draws a solid torus
903 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
905 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
906 double *vertex, *normal;
908 double spsi, cpsi, sphi, cphi ;
910 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
912 if ( nSides < 1 ) nSides = 1;
913 if ( nRings < 1 ) nRings = 1;
915 /* Increment the number of sides and rings to allow for one more point than surface */
919 /* Allocate the vertices array */
920 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
921 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
925 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
926 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
929 for( j=0; j<nRings; j++ )
935 for( i=0; i<nSides; i++ )
937 int offset = 3 * ( j * nSides + i ) ;
940 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
941 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
942 *(vertex + offset + 2) = sphi * iradius ;
943 *(normal + offset + 0) = cpsi * cphi ;
944 *(normal + offset + 1) = spsi * cphi ;
945 *(normal + offset + 2) = sphi ;
953 for( i=0; i<nSides-1; i++ )
955 for( j=0; j<nRings-1; j++ )
957 int offset = 3 * ( j * nSides + i ) ;
958 glNormal3dv( normal + offset );
959 glVertex3dv( vertex + offset );
960 glNormal3dv( normal + offset + 3 );
961 glVertex3dv( vertex + offset + 3 );
962 glNormal3dv( normal + offset + 3 * nSides + 3 );
963 glVertex3dv( vertex + offset + 3 * nSides + 3 );
964 glNormal3dv( normal + offset + 3 * nSides );
965 glVertex3dv( vertex + offset + 3 * nSides );
979 void FGAPIENTRY glutWireDodecahedron( void )
981 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
983 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
984 * of a cube. The coordinates of the points are:
985 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
986 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
987 * x = 0.61803398875 and z = 1.61803398875.
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 ) ;
995 glBegin ( GL_LINE_LOOP ) ;
996 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 ) ;
998 glBegin ( GL_LINE_LOOP ) ;
999 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 ) ;
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 ) ;
1008 glBegin ( GL_LINE_LOOP ) ;
1009 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 ) ;
1011 glBegin ( GL_LINE_LOOP ) ;
1012 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 ) ;
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 ) ;
1021 glBegin ( GL_LINE_LOOP ) ;
1022 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 ) ;
1024 glBegin ( GL_LINE_LOOP ) ;
1025 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 ) ;
1032 void FGAPIENTRY glutSolidDodecahedron( void )
1034 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1036 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1037 * of a cube. The coordinates of the points are:
1038 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1039 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1040 * x = 0.61803398875 and z = 1.61803398875.
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 ) ;
1048 glBegin ( GL_POLYGON ) ;
1049 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 ) ;
1051 glBegin ( GL_POLYGON ) ;
1052 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 ) ;
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 ) ;
1061 glBegin ( GL_POLYGON ) ;
1062 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 ) ;
1064 glBegin ( GL_POLYGON ) ;
1065 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 ) ;
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 ) ;
1074 glBegin ( GL_POLYGON ) ;
1075 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 ) ;
1077 glBegin ( GL_POLYGON ) ;
1078 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 ) ;
1085 void FGAPIENTRY glutWireOctahedron( void )
1087 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1090 glBegin( GL_LINE_LOOP );
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 );
1093 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 );
1094 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 );
1095 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 );
1096 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 );
1097 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 );
1098 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 );
1106 void FGAPIENTRY glutSolidOctahedron( void )
1108 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1111 glBegin( GL_TRIANGLES );
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 );
1114 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 );
1115 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 );
1116 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 );
1117 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 );
1118 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 );
1119 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 );
1127 static double icos_r[12][3] = {
1129 { 0.447213595500, 0.894427191000, 0.0 },
1130 { 0.447213595500, 0.276393202252, 0.850650808354 },
1131 { 0.447213595500, -0.723606797748, 0.525731112119 },
1132 { 0.447213595500, -0.723606797748, -0.525731112119 },
1133 { 0.447213595500, 0.276393202252, -0.850650808354 },
1134 { -0.447213595500, -0.894427191000, 0.0 },
1135 { -0.447213595500, -0.276393202252, 0.850650808354 },
1136 { -0.447213595500, 0.723606797748, 0.525731112119 },
1137 { -0.447213595500, 0.723606797748, -0.525731112119 },
1138 { -0.447213595500, -0.276393202252, -0.850650808354 },
1142 static int icos_v [20][3] = {
1165 void FGAPIENTRY glutWireIcosahedron( void )
1169 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1171 for ( i = 0; i < 20; i++ )
1174 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] ) ;
1175 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] ) ;
1176 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] ) ;
1177 glBegin ( GL_LINE_LOOP ) ;
1178 glNormal3dv ( normal ) ;
1179 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1180 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1181 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1189 void FGAPIENTRY glutSolidIcosahedron( void )
1193 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1195 glBegin ( GL_TRIANGLES ) ;
1196 for ( i = 0; i < 20; i++ )
1199 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] ) ;
1200 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] ) ;
1201 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] ) ;
1202 glNormal3dv ( normal ) ;
1203 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1204 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1205 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1214 static double rdod_r[14][3] = {
1216 { 0.707106781187, 0.000000000000, 0.5 },
1217 { 0.000000000000, 0.707106781187, 0.5 },
1218 { -0.707106781187, 0.000000000000, 0.5 },
1219 { 0.000000000000, -0.707106781187, 0.5 },
1220 { 0.707106781187, 0.707106781187, 0.0 },
1221 { -0.707106781187, 0.707106781187, 0.0 },
1222 { -0.707106781187, -0.707106781187, 0.0 },
1223 { 0.707106781187, -0.707106781187, 0.0 },
1224 { 0.707106781187, 0.000000000000, -0.5 },
1225 { 0.000000000000, 0.707106781187, -0.5 },
1226 { -0.707106781187, 0.000000000000, -0.5 },
1227 { 0.000000000000, -0.707106781187, -0.5 },
1231 static int rdod_v [12][4] = {
1246 static double rdod_n[12][3] = {
1247 { 0.353553390594, 0.353553390594, 0.5 },
1248 { -0.353553390594, 0.353553390594, 0.5 },
1249 { -0.353553390594, -0.353553390594, 0.5 },
1250 { 0.353553390594, -0.353553390594, 0.5 },
1251 { 0.000000000000, 1.000000000000, 0.0 },
1252 { -1.000000000000, 0.000000000000, 0.0 },
1253 { 0.000000000000, -1.000000000000, 0.0 },
1254 { 1.000000000000, 0.000000000000, 0.0 },
1255 { 0.353553390594, 0.353553390594, -0.5 },
1256 { -0.353553390594, 0.353553390594, -0.5 },
1257 { -0.353553390594, -0.353553390594, -0.5 },
1258 { 0.353553390594, -0.353553390594, -0.5 }
1261 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1265 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1267 for ( i = 0; i < 12; i++ )
1269 glBegin ( GL_LINE_LOOP ) ;
1270 glNormal3dv ( rdod_n[i] ) ;
1271 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1272 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1273 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1274 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1282 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1286 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1288 glBegin ( GL_QUADS ) ;
1289 for ( i = 0; i < 12; i++ )
1291 glNormal3dv ( rdod_n[i] ) ;
1292 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1293 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1294 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1295 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1303 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1305 * Draws a wireframed cube.
1307 void FGAPIENTRY glutWireCube( GLdouble dSize )
1309 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1310 fghCube( dSize, TRUE );
1312 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1314 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1315 fghCube( dSize, FALSE );
1318 void FGAPIENTRY glutWireTetrahedron( void )
1320 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1321 fghTetrahedron( TRUE );
1323 void FGAPIENTRY glutSolidTetrahedron( void )
1325 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1326 fghTetrahedron( FALSE );
1329 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1331 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1332 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1334 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1336 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1337 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1341 /*** END OF FILE ***/