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);
94 static void fghGenerateGeometry(int numFaces, int numVertPerFace, GLdouble *vertices, GLubyte* vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut)
98 * Build array with vertices from vertex coordinates and vertex indices
99 * Do same for normals.
100 * Need to do this because of different normals at shared vertices
101 * (and because normals' coordinates need to be negated).
103 for (i=0; i<numFaces; i++)
106 int faceIdxVertIdx = i*numVertPerFace;
107 for (j=0; j<numVertPerFace; j++)
109 int outIdx = i*numVertPerFace*3+j*3;
110 int vertIdx = vertIndices[faceIdxVertIdx+j]*3;
112 vertOut[outIdx ] = vertices[vertIdx ];
113 vertOut[outIdx+1] = vertices[vertIdx+1];
114 vertOut[outIdx+2] = vertices[vertIdx+2];
116 normOut[outIdx ] = normals [normIdx ];
117 normOut[outIdx+1] = normals [normIdx+1];
118 normOut[outIdx+2] = normals [normIdx+2];
124 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
125 static unsigned int ipow (int x, unsigned int y)
127 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
130 /* -- stuff that can be cached -- */
132 * In general, we build arrays with all vertices or normals.
133 * We cant compress this and use glDrawElements as all combinations of
134 * vertex and normals are unique.
138 #define CUBE_NUM_VERT 8
139 #define CUBE_NUM_FACES 6
140 #define CUBE_NUM_VERT_PER_FACE 4
141 #define CUBE_VERT_PER_CUBE CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE
142 #define CUBE_VERT_ELEM_PER_CUBE CUBE_VERT_PER_CUBE*3
143 /* Vertex Coordinates */
144 static GLdouble cube_v[CUBE_NUM_VERT*3] =
156 static GLdouble cube_n[CUBE_NUM_FACES*3] =
167 static GLubyte cube_vi[CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE] =
177 /* Cache of input to glDrawArrays */
178 static GLboolean cubeCached = FALSE;
179 static double cube_verts[CUBE_VERT_ELEM_PER_CUBE];
180 static double cube_norms[CUBE_VERT_ELEM_PER_CUBE];
182 static void fghCubeGenerate()
184 fghGenerateGeometry(CUBE_NUM_FACES, CUBE_NUM_VERT_PER_FACE, cube_v, cube_vi, cube_n, cube_verts, cube_norms);
187 /* -- Tetrahedron -- */
188 /* Magic Numbers: r0 = ( 1, 0, 0 )
189 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
190 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
191 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
192 * |r0| = |r1| = |r2| = |r3| = 1
193 * Distance between any two points is 2 sqrt(6) / 3
195 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
197 #define TETR_NUM_VERT 4
198 #define TETR_NUM_FACES 4
199 #define TETR_NUM_VERT_PER_FACE 3
200 #define TETR_VERT_PER_TETR TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE
201 #define TETR_VERT_ELEM_PER_TETR TETR_VERT_PER_TETR*3
203 /* Vertex Coordinates */
204 static GLdouble tetr_v[TETR_NUM_VERT*3] =
207 -0.333333333333, 0.942809041582, 0.0,
208 -0.333333333333, -0.471404520791, 0.816496580928,
209 -0.333333333333, -0.471404520791, -0.816496580928
212 static GLdouble tetr_n[CUBE_NUM_FACES*3] =
215 0.333333333333, -0.942809041582, 0.0,
216 0.333333333333, 0.471404520791, -0.816496580928,
217 0.333333333333, 0.471404520791, 0.816496580928
221 static GLubyte tetr_vi[TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE] =
229 /* Cache of input to glDrawArrays */
230 static GLboolean tetrCached = FALSE;
231 static double tetr_verts[TETR_VERT_ELEM_PER_TETR];
232 static double tetr_norms[TETR_VERT_ELEM_PER_TETR];
234 static void fghTetrahedronGenerate()
236 fghGenerateGeometry(TETR_NUM_FACES, TETR_NUM_VERT_PER_FACE, tetr_v, tetr_vi, tetr_n, tetr_verts, tetr_norms);
239 /* -- Sierpinski Sponge -- */
240 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, double* vertices, double* normals )
243 if ( numLevels == 0 )
245 for (i=0; i<TETR_NUM_FACES; i++)
248 int faceIdxVertIdx = i*TETR_NUM_VERT_PER_FACE;
249 for (j=0; j<TETR_NUM_VERT_PER_FACE; j++)
251 int outIdx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
252 int vertIdx = tetr_vi[faceIdxVertIdx+j]*3;
254 vertices[outIdx ] = offset[0] + scale * tetr_v[vertIdx ];
255 vertices[outIdx+1] = offset[1] + scale * tetr_v[vertIdx+1];
256 vertices[outIdx+2] = offset[2] + scale * tetr_v[vertIdx+2];
258 normals [outIdx ] = tetr_n[normIdx ];
259 normals [outIdx+1] = tetr_n[normIdx+1];
260 normals [outIdx+2] = tetr_n[normIdx+2];
264 else if ( numLevels > 0 )
266 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
267 unsigned int stride = ipow(4,--numLevels)*TETR_VERT_ELEM_PER_TETR;
269 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
272 local_offset[0] = offset[0] + scale * tetr_v[idx ];
273 local_offset[1] = offset[1] + scale * tetr_v[idx+1];
274 local_offset[2] = offset[2] + scale * tetr_v[idx+2];
275 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
280 /* -- Now the various shapes involving circles -- */
282 * Compute lookup table of cos and sin values forming a cirle
285 * It is the responsibility of the caller to free these tables
286 * The size of the table is (n+1) to form a connected loop
287 * The last entry is exactly the same as the first
288 * The sign of n can be flipped to get the reverse loop
290 static void fghCircleTable(double **sint,double **cost,const int n)
294 /* Table size, the sign of n flips the circle direction */
296 const int size = abs(n);
298 /* Determine the angle between samples */
300 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
302 /* Allocate memory for n samples, plus duplicate of first entry at the end */
304 *sint = (double *) calloc(sizeof(double), size+1);
305 *cost = (double *) calloc(sizeof(double), size+1);
307 /* Bail out if memory allocation fails, fgError never returns */
309 if (!(*sint) || !(*cost))
313 fgError("Failed to allocate memory in fghCircleTable");
316 /* Compute cos and sin around the circle */
321 for (i=1; i<size; i++)
323 (*sint)[i] = sin(angle*i);
324 (*cost)[i] = cos(angle*i);
327 /* Last sample is duplicate of the first */
329 (*sint)[size] = (*sint)[0];
330 (*cost)[size] = (*cost)[0];
334 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
336 static void fghCube( GLdouble dSize, GLboolean useWireMode )
348 /* Need to build new vertex list containing vertices for cube of different size */
349 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_CUBE * sizeof(double));
350 for (i=0; i<CUBE_VERT_ELEM_PER_CUBE; i++)
351 vertices[i] = dSize*cube_verts[i];
353 fghDrawGeometry(GL_QUADS,vertices ,cube_norms,CUBE_VERT_PER_CUBE,useWireMode);
356 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_CUBE,useWireMode);
359 static void fghTetrahedron( GLboolean useWireMode )
363 fghTetrahedronGenerate();
367 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
370 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
374 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
375 GLsizei numVert = numTetr*TETR_VERT_PER_TETR;
379 /* Allocate memory */
380 vertices = malloc(numVert*3 * sizeof(double));
381 normals = malloc(numVert*3 * sizeof(double));
383 /* Generate elements */
384 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
386 /* Draw and cleanup */
387 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
394 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
398 * Draws a solid sphere
400 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
404 /* Adjust z and radius as stacks are drawn. */
409 /* Pre-computed circle */
411 double *sint1,*cost1;
412 double *sint2,*cost2;
414 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
416 fghCircleTable(&sint1,&cost1,-slices);
417 fghCircleTable(&sint2,&cost2,stacks*2);
419 /* The top stack is covered with a triangle fan */
422 z1 = cost2[(stacks>0)?1:0];
424 r1 = sint2[(stacks>0)?1:0];
426 glBegin(GL_TRIANGLE_FAN);
429 glVertex3d(0,0,radius);
431 for (j=slices; j>=0; j--)
433 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
434 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
439 /* Cover each stack with a quad strip, except the top and bottom stacks */
441 for( i=1; i<stacks-1; i++ )
443 z0 = z1; z1 = cost2[i+1];
444 r0 = r1; r1 = sint2[i+1];
446 glBegin(GL_QUAD_STRIP);
448 for(j=0; j<=slices; j++)
450 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
451 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
452 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
453 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
459 /* The bottom stack is covered with a triangle fan */
464 glBegin(GL_TRIANGLE_FAN);
467 glVertex3d(0,0,-radius);
469 for (j=0; j<=slices; j++)
471 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
472 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
477 /* Release sin and cos tables */
486 * Draws a wire sphere
488 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
492 /* Adjust z and radius as stacks and slices are drawn. */
497 /* Pre-computed circle */
499 double *sint1,*cost1;
500 double *sint2,*cost2;
502 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
504 fghCircleTable(&sint1,&cost1,-slices );
505 fghCircleTable(&sint2,&cost2, stacks*2);
507 /* Draw a line loop for each stack */
509 for (i=1; i<stacks; i++)
514 glBegin(GL_LINE_LOOP);
516 for(j=0; j<=slices; j++)
522 glVertex3d(x*r*radius,y*r*radius,z*radius);
528 /* Draw a line loop for each slice */
530 for (i=0; i<slices; i++)
532 glBegin(GL_LINE_STRIP);
534 for(j=0; j<=stacks; j++)
536 x = cost1[i]*sint2[j];
537 y = sint1[i]*sint2[j];
541 glVertex3d(x*radius,y*radius,z*radius);
547 /* Release sin and cos tables */
558 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
562 /* Step in z and radius as stacks are drawn. */
567 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
568 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
570 /* Scaling factors for vertex normals */
572 const double cosn = ( height / sqrt ( height * height + base * base ));
573 const double sinn = ( base / sqrt ( height * height + base * base ));
575 /* Pre-computed circle */
579 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
581 fghCircleTable(&sint,&cost,-slices);
583 /* Cover the circular base with a triangle fan... */
591 glBegin(GL_TRIANGLE_FAN);
593 glNormal3d(0.0,0.0,-1.0);
594 glVertex3d(0.0,0.0, z0 );
596 for (j=0; j<=slices; j++)
597 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
601 /* Cover each stack with a quad strip, except the top stack */
603 for( i=0; i<stacks-1; i++ )
605 glBegin(GL_QUAD_STRIP);
607 for(j=0; j<=slices; j++)
609 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
610 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
611 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
614 z0 = z1; z1 += zStep;
615 r0 = r1; r1 -= rStep;
620 /* The top stack is covered with individual triangles */
622 glBegin(GL_TRIANGLES);
624 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
626 for (j=0; j<slices; j++)
628 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
629 glVertex3d(0, 0, height);
630 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
631 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
636 /* Release sin and cos tables */
645 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
649 /* Step in z and radius as stacks are drawn. */
654 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
655 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
657 /* Scaling factors for vertex normals */
659 const double cosn = ( height / sqrt ( height * height + base * base ));
660 const double sinn = ( base / sqrt ( height * height + base * base ));
662 /* Pre-computed circle */
666 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
668 fghCircleTable(&sint,&cost,-slices);
670 /* Draw the stacks... */
672 for (i=0; i<stacks; i++)
674 glBegin(GL_LINE_LOOP);
676 for( j=0; j<slices; j++ )
678 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
679 glVertex3d(cost[j]*r, sint[j]*r, z );
688 /* Draw the slices */
694 for (j=0; j<slices; j++)
696 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
697 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
698 glVertex3d(0.0, 0.0, height);
703 /* Release sin and cos tables */
711 * Draws a solid cylinder
713 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
717 /* Step in z and radius as stacks are drawn. */
720 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
722 /* Pre-computed circle */
726 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
728 fghCircleTable(&sint,&cost,-slices);
730 /* Cover the base and top */
732 glBegin(GL_TRIANGLE_FAN);
733 glNormal3d(0.0, 0.0, -1.0 );
734 glVertex3d(0.0, 0.0, 0.0 );
735 for (j=0; j<=slices; j++)
736 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
739 glBegin(GL_TRIANGLE_FAN);
740 glNormal3d(0.0, 0.0, 1.0 );
741 glVertex3d(0.0, 0.0, height);
742 for (j=slices; j>=0; j--)
743 glVertex3d(cost[j]*radius, sint[j]*radius, height);
751 for (i=1; i<=stacks; i++)
756 glBegin(GL_QUAD_STRIP);
757 for (j=0; j<=slices; j++ )
759 glNormal3d(cost[j], sint[j], 0.0 );
760 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
761 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
765 z0 = z1; z1 += zStep;
768 /* Release sin and cos tables */
775 * Draws a wire cylinder
777 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
781 /* Step in z and radius as stacks are drawn. */
784 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
786 /* Pre-computed circle */
790 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
792 fghCircleTable(&sint,&cost,-slices);
794 /* Draw the stacks... */
796 for (i=0; i<=stacks; i++)
801 glBegin(GL_LINE_LOOP);
803 for( j=0; j<slices; j++ )
805 glNormal3d(cost[j], sint[j], 0.0);
806 glVertex3d(cost[j]*radius, sint[j]*radius, z );
814 /* Draw the slices */
818 for (j=0; j<slices; j++)
820 glNormal3d(cost[j], sint[j], 0.0 );
821 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
822 glVertex3d(cost[j]*radius, sint[j]*radius, height);
827 /* Release sin and cos tables */
836 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
838 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
839 double *vertex, *normal;
841 double spsi, cpsi, sphi, cphi ;
843 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
845 if ( nSides < 1 ) nSides = 1;
846 if ( nRings < 1 ) nRings = 1;
848 /* Allocate the vertices array */
849 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
850 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
854 dpsi = 2.0 * M_PI / (double)nRings ;
855 dphi = -2.0 * M_PI / (double)nSides ;
858 for( j=0; j<nRings; j++ )
864 for( i=0; i<nSides; i++ )
866 int offset = 3 * ( j * nSides + i ) ;
869 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
870 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
871 *(vertex + offset + 2) = sphi * iradius ;
872 *(normal + offset + 0) = cpsi * cphi ;
873 *(normal + offset + 1) = spsi * cphi ;
874 *(normal + offset + 2) = sphi ;
881 for( i=0; i<nSides; i++ )
883 glBegin( GL_LINE_LOOP );
885 for( j=0; j<nRings; j++ )
887 int offset = 3 * ( j * nSides + i ) ;
888 glNormal3dv( normal + offset );
889 glVertex3dv( vertex + offset );
895 for( j=0; j<nRings; j++ )
897 glBegin(GL_LINE_LOOP);
899 for( i=0; i<nSides; i++ )
901 int offset = 3 * ( j * nSides + i ) ;
902 glNormal3dv( normal + offset );
903 glVertex3dv( vertex + offset );
915 * Draws a solid torus
917 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
919 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
920 double *vertex, *normal;
922 double spsi, cpsi, sphi, cphi ;
924 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
926 if ( nSides < 1 ) nSides = 1;
927 if ( nRings < 1 ) nRings = 1;
929 /* Increment the number of sides and rings to allow for one more point than surface */
933 /* Allocate the vertices array */
934 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
935 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
939 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
940 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
943 for( j=0; j<nRings; j++ )
949 for( i=0; i<nSides; i++ )
951 int offset = 3 * ( j * nSides + i ) ;
954 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
955 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
956 *(vertex + offset + 2) = sphi * iradius ;
957 *(normal + offset + 0) = cpsi * cphi ;
958 *(normal + offset + 1) = spsi * cphi ;
959 *(normal + offset + 2) = sphi ;
967 for( i=0; i<nSides-1; i++ )
969 for( j=0; j<nRings-1; j++ )
971 int offset = 3 * ( j * nSides + i ) ;
972 glNormal3dv( normal + offset );
973 glVertex3dv( vertex + offset );
974 glNormal3dv( normal + offset + 3 );
975 glVertex3dv( vertex + offset + 3 );
976 glNormal3dv( normal + offset + 3 * nSides + 3 );
977 glVertex3dv( vertex + offset + 3 * nSides + 3 );
978 glNormal3dv( normal + offset + 3 * nSides );
979 glVertex3dv( vertex + offset + 3 * nSides );
993 void FGAPIENTRY glutWireDodecahedron( void )
995 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
997 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
998 * of a cube. The coordinates of the points are:
999 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1000 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1001 * x = 0.61803398875 and z = 1.61803398875.
1003 glBegin ( GL_LINE_LOOP ) ;
1004 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 ) ;
1006 glBegin ( GL_LINE_LOOP ) ;
1007 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 ) ;
1009 glBegin ( GL_LINE_LOOP ) ;
1010 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 ) ;
1012 glBegin ( GL_LINE_LOOP ) ;
1013 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 ) ;
1016 glBegin ( GL_LINE_LOOP ) ;
1017 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 ) ;
1019 glBegin ( GL_LINE_LOOP ) ;
1020 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 ) ;
1022 glBegin ( GL_LINE_LOOP ) ;
1023 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 ) ;
1025 glBegin ( GL_LINE_LOOP ) ;
1026 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 ) ;
1029 glBegin ( GL_LINE_LOOP ) ;
1030 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 glBegin ( GL_LINE_LOOP ) ;
1033 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 ) ;
1035 glBegin ( GL_LINE_LOOP ) ;
1036 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 ) ;
1038 glBegin ( GL_LINE_LOOP ) ;
1039 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 ) ;
1046 void FGAPIENTRY glutSolidDodecahedron( void )
1048 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1050 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1051 * of a cube. The coordinates of the points are:
1052 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1053 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1054 * x = 0.61803398875 and z = 1.61803398875.
1056 glBegin ( GL_POLYGON ) ;
1057 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 ) ;
1059 glBegin ( GL_POLYGON ) ;
1060 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 ) ;
1062 glBegin ( GL_POLYGON ) ;
1063 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 ) ;
1065 glBegin ( GL_POLYGON ) ;
1066 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 ) ;
1069 glBegin ( GL_POLYGON ) ;
1070 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 ) ;
1072 glBegin ( GL_POLYGON ) ;
1073 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 ) ;
1075 glBegin ( GL_POLYGON ) ;
1076 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 ) ;
1078 glBegin ( GL_POLYGON ) ;
1079 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 ) ;
1082 glBegin ( GL_POLYGON ) ;
1083 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 glBegin ( GL_POLYGON ) ;
1086 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 ) ;
1088 glBegin ( GL_POLYGON ) ;
1089 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 ) ;
1091 glBegin ( GL_POLYGON ) ;
1092 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 ) ;
1099 void FGAPIENTRY glutWireOctahedron( void )
1101 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1104 glBegin( GL_LINE_LOOP );
1105 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 );
1106 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 );
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,-RADIUS, 0.0 ); glVertex3d( 0.0, 0.0,-RADIUS );
1109 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 );
1110 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 );
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, 0.0,-RADIUS ); glVertex3d( 0.0,-RADIUS, 0.0 );
1120 void FGAPIENTRY glutSolidOctahedron( void )
1122 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1125 glBegin( GL_TRIANGLES );
1126 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 );
1127 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 );
1128 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 );
1129 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 );
1130 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 );
1131 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 );
1132 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 );
1133 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 );
1141 static double icos_r[12][3] = {
1143 { 0.447213595500, 0.894427191000, 0.0 },
1144 { 0.447213595500, 0.276393202252, 0.850650808354 },
1145 { 0.447213595500, -0.723606797748, 0.525731112119 },
1146 { 0.447213595500, -0.723606797748, -0.525731112119 },
1147 { 0.447213595500, 0.276393202252, -0.850650808354 },
1148 { -0.447213595500, -0.894427191000, 0.0 },
1149 { -0.447213595500, -0.276393202252, 0.850650808354 },
1150 { -0.447213595500, 0.723606797748, 0.525731112119 },
1151 { -0.447213595500, 0.723606797748, -0.525731112119 },
1152 { -0.447213595500, -0.276393202252, -0.850650808354 },
1156 static int icos_v [20][3] = {
1179 void FGAPIENTRY glutWireIcosahedron( void )
1183 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1185 for ( i = 0; i < 20; i++ )
1188 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] ) ;
1189 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] ) ;
1190 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] ) ;
1191 glBegin ( GL_LINE_LOOP ) ;
1192 glNormal3dv ( normal ) ;
1193 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1194 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1195 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1203 void FGAPIENTRY glutSolidIcosahedron( void )
1207 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1209 glBegin ( GL_TRIANGLES ) ;
1210 for ( i = 0; i < 20; i++ )
1213 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] ) ;
1214 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] ) ;
1215 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] ) ;
1216 glNormal3dv ( normal ) ;
1217 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1218 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1219 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1228 static double rdod_r[14][3] = {
1230 { 0.707106781187, 0.000000000000, 0.5 },
1231 { 0.000000000000, 0.707106781187, 0.5 },
1232 { -0.707106781187, 0.000000000000, 0.5 },
1233 { 0.000000000000, -0.707106781187, 0.5 },
1234 { 0.707106781187, 0.707106781187, 0.0 },
1235 { -0.707106781187, 0.707106781187, 0.0 },
1236 { -0.707106781187, -0.707106781187, 0.0 },
1237 { 0.707106781187, -0.707106781187, 0.0 },
1238 { 0.707106781187, 0.000000000000, -0.5 },
1239 { 0.000000000000, 0.707106781187, -0.5 },
1240 { -0.707106781187, 0.000000000000, -0.5 },
1241 { 0.000000000000, -0.707106781187, -0.5 },
1245 static int rdod_v [12][4] = {
1260 static double rdod_n[12][3] = {
1261 { 0.353553390594, 0.353553390594, 0.5 },
1262 { -0.353553390594, 0.353553390594, 0.5 },
1263 { -0.353553390594, -0.353553390594, 0.5 },
1264 { 0.353553390594, -0.353553390594, 0.5 },
1265 { 0.000000000000, 1.000000000000, 0.0 },
1266 { -1.000000000000, 0.000000000000, 0.0 },
1267 { 0.000000000000, -1.000000000000, 0.0 },
1268 { 1.000000000000, 0.000000000000, 0.0 },
1269 { 0.353553390594, 0.353553390594, -0.5 },
1270 { -0.353553390594, 0.353553390594, -0.5 },
1271 { -0.353553390594, -0.353553390594, -0.5 },
1272 { 0.353553390594, -0.353553390594, -0.5 }
1275 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1279 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1281 for ( i = 0; i < 12; i++ )
1283 glBegin ( GL_LINE_LOOP ) ;
1284 glNormal3dv ( rdod_n[i] ) ;
1285 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1286 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1287 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1288 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1296 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1300 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1302 glBegin ( GL_QUADS ) ;
1303 for ( i = 0; i < 12; i++ )
1305 glNormal3dv ( rdod_n[i] ) ;
1306 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1307 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1308 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1309 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1317 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1319 * Draws a wireframed cube.
1321 void FGAPIENTRY glutWireCube( GLdouble dSize )
1323 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1324 fghCube( dSize, TRUE );
1326 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1328 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1329 fghCube( dSize, FALSE );
1332 void FGAPIENTRY glutWireTetrahedron( void )
1334 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1335 fghTetrahedron( TRUE );
1337 void FGAPIENTRY glutSolidTetrahedron( void )
1339 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1340 fghTetrahedron( FALSE );
1343 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1345 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1346 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1348 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1350 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1351 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1355 /*** END OF FILE ***/