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_TETR CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE
142 #define CUBE_VERT_ELEM_PER_TETR CUBE_VERT_PER_TETR*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_TETR];
180 static double cube_norms[CUBE_VERT_ELEM_PER_TETR];
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 )
346 /* Need to build new */
347 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
350 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_TETR,useWireMode);
353 static void fghTetrahedron( GLboolean useWireMode )
357 fghTetrahedronGenerate();
361 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
364 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
368 unsigned int numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
369 unsigned int numVert = numTetr*TETR_VERT_PER_TETR;
373 /* Allocate memory */
374 vertices = malloc(numVert*3 * sizeof(double));
375 normals = malloc(numVert*3 * sizeof(double));
377 /* Generate elements */
378 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
380 /* Draw and cleanup */
381 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
388 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
392 * Draws a solid sphere
394 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
398 /* Adjust z and radius as stacks are drawn. */
403 /* Pre-computed circle */
405 double *sint1,*cost1;
406 double *sint2,*cost2;
408 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
410 fghCircleTable(&sint1,&cost1,-slices);
411 fghCircleTable(&sint2,&cost2,stacks*2);
413 /* The top stack is covered with a triangle fan */
416 z1 = cost2[(stacks>0)?1:0];
418 r1 = sint2[(stacks>0)?1:0];
420 glBegin(GL_TRIANGLE_FAN);
423 glVertex3d(0,0,radius);
425 for (j=slices; j>=0; j--)
427 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
428 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
433 /* Cover each stack with a quad strip, except the top and bottom stacks */
435 for( i=1; i<stacks-1; i++ )
437 z0 = z1; z1 = cost2[i+1];
438 r0 = r1; r1 = sint2[i+1];
440 glBegin(GL_QUAD_STRIP);
442 for(j=0; j<=slices; j++)
444 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
445 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
446 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
447 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
453 /* The bottom stack is covered with a triangle fan */
458 glBegin(GL_TRIANGLE_FAN);
461 glVertex3d(0,0,-radius);
463 for (j=0; j<=slices; j++)
465 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
466 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
471 /* Release sin and cos tables */
480 * Draws a wire sphere
482 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
486 /* Adjust z and radius as stacks and slices are drawn. */
491 /* Pre-computed circle */
493 double *sint1,*cost1;
494 double *sint2,*cost2;
496 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
498 fghCircleTable(&sint1,&cost1,-slices );
499 fghCircleTable(&sint2,&cost2, stacks*2);
501 /* Draw a line loop for each stack */
503 for (i=1; i<stacks; i++)
508 glBegin(GL_LINE_LOOP);
510 for(j=0; j<=slices; j++)
516 glVertex3d(x*r*radius,y*r*radius,z*radius);
522 /* Draw a line loop for each slice */
524 for (i=0; i<slices; i++)
526 glBegin(GL_LINE_STRIP);
528 for(j=0; j<=stacks; j++)
530 x = cost1[i]*sint2[j];
531 y = sint1[i]*sint2[j];
535 glVertex3d(x*radius,y*radius,z*radius);
541 /* Release sin and cos tables */
552 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
556 /* Step in z and radius as stacks are drawn. */
561 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
562 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
564 /* Scaling factors for vertex normals */
566 const double cosn = ( height / sqrt ( height * height + base * base ));
567 const double sinn = ( base / sqrt ( height * height + base * base ));
569 /* Pre-computed circle */
573 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
575 fghCircleTable(&sint,&cost,-slices);
577 /* Cover the circular base with a triangle fan... */
585 glBegin(GL_TRIANGLE_FAN);
587 glNormal3d(0.0,0.0,-1.0);
588 glVertex3d(0.0,0.0, z0 );
590 for (j=0; j<=slices; j++)
591 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
595 /* Cover each stack with a quad strip, except the top stack */
597 for( i=0; i<stacks-1; i++ )
599 glBegin(GL_QUAD_STRIP);
601 for(j=0; j<=slices; j++)
603 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
604 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
605 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
608 z0 = z1; z1 += zStep;
609 r0 = r1; r1 -= rStep;
614 /* The top stack is covered with individual triangles */
616 glBegin(GL_TRIANGLES);
618 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
620 for (j=0; j<slices; j++)
622 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
623 glVertex3d(0, 0, height);
624 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
625 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
630 /* Release sin and cos tables */
639 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
643 /* Step in z and radius as stacks are drawn. */
648 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
649 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
651 /* Scaling factors for vertex normals */
653 const double cosn = ( height / sqrt ( height * height + base * base ));
654 const double sinn = ( base / sqrt ( height * height + base * base ));
656 /* Pre-computed circle */
660 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
662 fghCircleTable(&sint,&cost,-slices);
664 /* Draw the stacks... */
666 for (i=0; i<stacks; i++)
668 glBegin(GL_LINE_LOOP);
670 for( j=0; j<slices; j++ )
672 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
673 glVertex3d(cost[j]*r, sint[j]*r, z );
682 /* Draw the slices */
688 for (j=0; j<slices; j++)
690 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
691 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
692 glVertex3d(0.0, 0.0, height);
697 /* Release sin and cos tables */
705 * Draws a solid cylinder
707 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
711 /* Step in z and radius as stacks are drawn. */
714 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
716 /* Pre-computed circle */
720 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
722 fghCircleTable(&sint,&cost,-slices);
724 /* Cover the base and top */
726 glBegin(GL_TRIANGLE_FAN);
727 glNormal3d(0.0, 0.0, -1.0 );
728 glVertex3d(0.0, 0.0, 0.0 );
729 for (j=0; j<=slices; j++)
730 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
733 glBegin(GL_TRIANGLE_FAN);
734 glNormal3d(0.0, 0.0, 1.0 );
735 glVertex3d(0.0, 0.0, height);
736 for (j=slices; j>=0; j--)
737 glVertex3d(cost[j]*radius, sint[j]*radius, height);
745 for (i=1; i<=stacks; i++)
750 glBegin(GL_QUAD_STRIP);
751 for (j=0; j<=slices; j++ )
753 glNormal3d(cost[j], sint[j], 0.0 );
754 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
755 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
759 z0 = z1; z1 += zStep;
762 /* Release sin and cos tables */
769 * Draws a wire cylinder
771 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
775 /* Step in z and radius as stacks are drawn. */
778 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
780 /* Pre-computed circle */
784 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
786 fghCircleTable(&sint,&cost,-slices);
788 /* Draw the stacks... */
790 for (i=0; i<=stacks; i++)
795 glBegin(GL_LINE_LOOP);
797 for( j=0; j<slices; j++ )
799 glNormal3d(cost[j], sint[j], 0.0);
800 glVertex3d(cost[j]*radius, sint[j]*radius, z );
808 /* Draw the slices */
812 for (j=0; j<slices; j++)
814 glNormal3d(cost[j], sint[j], 0.0 );
815 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
816 glVertex3d(cost[j]*radius, sint[j]*radius, height);
821 /* Release sin and cos tables */
830 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
832 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
833 double *vertex, *normal;
835 double spsi, cpsi, sphi, cphi ;
837 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
839 if ( nSides < 1 ) nSides = 1;
840 if ( nRings < 1 ) nRings = 1;
842 /* Allocate the vertices array */
843 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
844 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
848 dpsi = 2.0 * M_PI / (double)nRings ;
849 dphi = -2.0 * M_PI / (double)nSides ;
852 for( j=0; j<nRings; j++ )
858 for( i=0; i<nSides; i++ )
860 int offset = 3 * ( j * nSides + i ) ;
863 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
864 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
865 *(vertex + offset + 2) = sphi * iradius ;
866 *(normal + offset + 0) = cpsi * cphi ;
867 *(normal + offset + 1) = spsi * cphi ;
868 *(normal + offset + 2) = sphi ;
875 for( i=0; i<nSides; i++ )
877 glBegin( GL_LINE_LOOP );
879 for( j=0; j<nRings; j++ )
881 int offset = 3 * ( j * nSides + i ) ;
882 glNormal3dv( normal + offset );
883 glVertex3dv( vertex + offset );
889 for( j=0; j<nRings; j++ )
891 glBegin(GL_LINE_LOOP);
893 for( i=0; i<nSides; i++ )
895 int offset = 3 * ( j * nSides + i ) ;
896 glNormal3dv( normal + offset );
897 glVertex3dv( vertex + offset );
909 * Draws a solid torus
911 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
913 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
914 double *vertex, *normal;
916 double spsi, cpsi, sphi, cphi ;
918 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
920 if ( nSides < 1 ) nSides = 1;
921 if ( nRings < 1 ) nRings = 1;
923 /* Increment the number of sides and rings to allow for one more point than surface */
927 /* Allocate the vertices array */
928 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
929 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
933 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
934 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
937 for( j=0; j<nRings; j++ )
943 for( i=0; i<nSides; i++ )
945 int offset = 3 * ( j * nSides + i ) ;
948 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
949 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
950 *(vertex + offset + 2) = sphi * iradius ;
951 *(normal + offset + 0) = cpsi * cphi ;
952 *(normal + offset + 1) = spsi * cphi ;
953 *(normal + offset + 2) = sphi ;
961 for( i=0; i<nSides-1; i++ )
963 for( j=0; j<nRings-1; j++ )
965 int offset = 3 * ( j * nSides + i ) ;
966 glNormal3dv( normal + offset );
967 glVertex3dv( vertex + offset );
968 glNormal3dv( normal + offset + 3 );
969 glVertex3dv( vertex + offset + 3 );
970 glNormal3dv( normal + offset + 3 * nSides + 3 );
971 glVertex3dv( vertex + offset + 3 * nSides + 3 );
972 glNormal3dv( normal + offset + 3 * nSides );
973 glVertex3dv( vertex + offset + 3 * nSides );
987 void FGAPIENTRY glutWireDodecahedron( void )
989 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
991 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
992 * of a cube. The coordinates of the points are:
993 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
994 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
995 * x = 0.61803398875 and z = 1.61803398875.
997 glBegin ( GL_LINE_LOOP ) ;
998 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 ) ;
1000 glBegin ( GL_LINE_LOOP ) ;
1001 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 ) ;
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 ) ;
1010 glBegin ( GL_LINE_LOOP ) ;
1011 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 ) ;
1013 glBegin ( GL_LINE_LOOP ) ;
1014 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 ) ;
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 ) ;
1023 glBegin ( GL_LINE_LOOP ) ;
1024 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 glBegin ( GL_LINE_LOOP ) ;
1027 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 ) ;
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 ) ;
1040 void FGAPIENTRY glutSolidDodecahedron( void )
1042 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1044 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1045 * of a cube. The coordinates of the points are:
1046 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1047 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1048 * x = 0.61803398875 and z = 1.61803398875.
1050 glBegin ( GL_POLYGON ) ;
1051 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 ) ;
1053 glBegin ( GL_POLYGON ) ;
1054 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 ) ;
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 ) ;
1063 glBegin ( GL_POLYGON ) ;
1064 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 ) ;
1066 glBegin ( GL_POLYGON ) ;
1067 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 ) ;
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 ) ;
1076 glBegin ( GL_POLYGON ) ;
1077 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 glBegin ( GL_POLYGON ) ;
1080 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 ) ;
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 ) ;
1093 void FGAPIENTRY glutWireOctahedron( void )
1095 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1098 glBegin( GL_LINE_LOOP );
1099 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 );
1100 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 );
1101 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 );
1102 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 );
1103 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 );
1104 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 );
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 );
1114 void FGAPIENTRY glutSolidOctahedron( void )
1116 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1119 glBegin( GL_TRIANGLES );
1120 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 );
1121 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 );
1122 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 );
1123 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 );
1124 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 );
1125 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 );
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 );
1135 static double icos_r[12][3] = {
1137 { 0.447213595500, 0.894427191000, 0.0 },
1138 { 0.447213595500, 0.276393202252, 0.850650808354 },
1139 { 0.447213595500, -0.723606797748, 0.525731112119 },
1140 { 0.447213595500, -0.723606797748, -0.525731112119 },
1141 { 0.447213595500, 0.276393202252, -0.850650808354 },
1142 { -0.447213595500, -0.894427191000, 0.0 },
1143 { -0.447213595500, -0.276393202252, 0.850650808354 },
1144 { -0.447213595500, 0.723606797748, 0.525731112119 },
1145 { -0.447213595500, 0.723606797748, -0.525731112119 },
1146 { -0.447213595500, -0.276393202252, -0.850650808354 },
1150 static int icos_v [20][3] = {
1173 void FGAPIENTRY glutWireIcosahedron( void )
1177 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1179 for ( i = 0; i < 20; i++ )
1182 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] ) ;
1183 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] ) ;
1184 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] ) ;
1185 glBegin ( GL_LINE_LOOP ) ;
1186 glNormal3dv ( normal ) ;
1187 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1188 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1189 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1197 void FGAPIENTRY glutSolidIcosahedron( void )
1201 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1203 glBegin ( GL_TRIANGLES ) ;
1204 for ( i = 0; i < 20; i++ )
1207 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] ) ;
1208 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] ) ;
1209 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] ) ;
1210 glNormal3dv ( normal ) ;
1211 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1212 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1213 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1222 static double rdod_r[14][3] = {
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 },
1228 { 0.707106781187, 0.707106781187, 0.0 },
1229 { -0.707106781187, 0.707106781187, 0.0 },
1230 { -0.707106781187, -0.707106781187, 0.0 },
1231 { 0.707106781187, -0.707106781187, 0.0 },
1232 { 0.707106781187, 0.000000000000, -0.5 },
1233 { 0.000000000000, 0.707106781187, -0.5 },
1234 { -0.707106781187, 0.000000000000, -0.5 },
1235 { 0.000000000000, -0.707106781187, -0.5 },
1239 static int rdod_v [12][4] = {
1254 static double rdod_n[12][3] = {
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 },
1259 { 0.000000000000, 1.000000000000, 0.0 },
1260 { -1.000000000000, 0.000000000000, 0.0 },
1261 { 0.000000000000, -1.000000000000, 0.0 },
1262 { 1.000000000000, 0.000000000000, 0.0 },
1263 { 0.353553390594, 0.353553390594, -0.5 },
1264 { -0.353553390594, 0.353553390594, -0.5 },
1265 { -0.353553390594, -0.353553390594, -0.5 },
1266 { 0.353553390594, -0.353553390594, -0.5 }
1269 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1273 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1275 for ( i = 0; i < 12; i++ )
1277 glBegin ( GL_LINE_LOOP ) ;
1278 glNormal3dv ( rdod_n[i] ) ;
1279 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1280 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1281 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1282 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1290 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1294 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1296 glBegin ( GL_QUADS ) ;
1297 for ( i = 0; i < 12; i++ )
1299 glNormal3dv ( rdod_n[i] ) ;
1300 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1301 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1302 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1303 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1311 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1313 * Draws a wireframed cube.
1315 void FGAPIENTRY glutWireCube( GLdouble dSize )
1317 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1318 fghCube( dSize, TRUE );
1320 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1322 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1323 fghCube( dSize, FALSE );
1326 void FGAPIENTRY glutWireTetrahedron( void )
1328 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1329 fghTetrahedron( TRUE );
1331 void FGAPIENTRY glutSolidTetrahedron( void )
1333 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1334 fghTetrahedron( FALSE );
1337 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1339 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1340 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1342 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1344 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1345 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1349 /*** END OF FILE ***/