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"
33 * Need more types of polyhedra? See CPolyhedron in MRPT
35 * TODO BEFORE THE STABLE RELEASE:
39 * Following functions have been contributed by Andreas Umbach.
41 * glutWireCube() -- looks OK
42 * glutSolidCube() -- OK
44 * Those functions have been implemented by John Fay.
46 * glutWireTorus() -- looks OK
47 * glutSolidTorus() -- looks OK
48 * glutWireDodecahedron() -- looks OK
49 * glutSolidDodecahedron() -- looks OK
50 * glutWireOctahedron() -- looks OK
51 * glutSolidOctahedron() -- looks OK
52 * glutWireTetrahedron() -- looks OK
53 * glutSolidTetrahedron() -- looks OK
54 * glutWireIcosahedron() -- looks OK
55 * glutSolidIcosahedron() -- looks OK
57 * The Following functions have been updated by Nigel Stewart, based
58 * on FreeGLUT 2.0.0 implementations:
60 * glutWireSphere() -- looks OK
61 * glutSolidSphere() -- looks OK
62 * glutWireCone() -- looks OK
63 * glutSolidCone() -- looks OK
67 /* General function for drawing geometry. As for all geometry we have no
68 * redundancy (or hardly any in the case of cones and cylinders) in terms
69 * of the vertex/normal combinations, we just use glDrawArrays.
70 * useWireMode controls the drawing of solids (false) or wire frame
71 * versions (TRUE) of the geometry you pass
73 static void fghDrawGeometry(GLenum vertexMode, GLdouble *vertices, GLdouble *normals, GLboolean *edgeFlags, GLsizei numVertices, GLboolean useWireMode)
77 glPushAttrib(GL_POLYGON_BIT);
78 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
83 glEnableClientState(GL_VERTEX_ARRAY);
84 glEnableClientState(GL_NORMAL_ARRAY);
86 glEnableClientState(GL_EDGE_FLAG_ARRAY);
88 glVertexPointer(3, GL_DOUBLE, 0, vertices);
89 glNormalPointer(GL_DOUBLE, 0, normals);
91 glEdgeFlagPointer(0,edgeFlags);
92 glDrawArrays(vertexMode, 0, numVertices);
94 glDisableClientState(GL_VERTEX_ARRAY);
95 glDisableClientState(GL_NORMAL_ARRAY);
97 glDisableClientState(GL_EDGE_FLAG_ARRAY);
103 for(i=0; i<numVertices; i++)
105 glEdgeFlag(edgeFlags[i]);
106 glNormal3dv(normals+i*3);
107 printf("n(%i) = (%1.4f,%1.4f,%1.4f)\n",i,*(normals+i*3),*(normals+i*3+1),*(normals+i*3+2));
108 glVertex3dv(vertices+i*3);
109 printf("v(%i) = (%1.4f,%1.4f,%1.4f)\n",i,*(vertices+i*3),*(vertices+i*3+1),*(vertices+i*3+2));
120 /* triangle decomposition and associated edgeFlags
121 * be careful to keep winding of all triangles counter-clockwise,
122 * assuming that input has correct winding...
124 static GLubyte vertSamp3[3] = {0,1,2};
125 static GLubyte vertSamp4[6] = {0,1,2, 0,2,3}; /* quad : 4 input vertices, 6 output (2 triangles) */
126 static GLubyte vertSamp5[9] = {0,1,2, 0,2,4, 4,2,3}; /* pentagon: 5 input vertices, 9 output (3 triangles) */
127 static GLboolean edgeFlag3[3] = {1,1,1}; /* triangles remain triangles, all edges are external */
128 static GLboolean edgeFlag4[6] = {1,1,0, 0,1,1};
129 static GLboolean edgeFlag5[9] = {1,1,0, 0,0,1, 0,1,1};
131 static void fghGenerateGeometryWithEdgeFlag(int numFaces, int numEdgePerFaceIn, GLdouble *vertices, GLubyte *vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut, GLboolean *edgeFlagsOut)
133 int i,j,numEdgePerFaceOut;
134 GLubyte *vertSamps = NULL;
135 GLboolean *edgeFlags = NULL;
136 switch (numEdgePerFaceIn)
139 vertSamps = vertSamp3;
140 edgeFlags = edgeFlag3;
141 numEdgePerFaceOut = 3; /* 3 output vertices for each face */
144 vertSamps = vertSamp4;
145 edgeFlags = edgeFlag4;
146 numEdgePerFaceOut = 6; /* 6 output vertices for each face */
149 vertSamps = vertSamp5;
150 edgeFlags = edgeFlag5;
151 numEdgePerFaceOut = 9; /* 9 output vertices for each face */
155 * Build array with vertices from vertex coordinates and vertex indices
156 * Do same for normals.
157 * Need to do this because of different normals at shared vertices
158 * (and because normals' coordinates need to be negated).
160 for (i=0; i<numFaces; i++)
163 int faceIdxVertIdx = i*numEdgePerFaceIn; // index to first element of "row" in vertex indices
164 for (j=0; j<numEdgePerFaceOut; j++)
166 int outIdx = i*numEdgePerFaceOut*3+j*3;
167 int vertIdx = vertIndices[faceIdxVertIdx+vertSamps[j]]*3;
168 printf("%i,",outIdx);
170 vertOut[outIdx ] = vertices[vertIdx ];
171 vertOut[outIdx+1] = vertices[vertIdx+1];
172 vertOut[outIdx+2] = vertices[vertIdx+2];
174 normOut[outIdx ] = normals [normIdx ];
175 normOut[outIdx+1] = normals [normIdx+1];
176 normOut[outIdx+2] = normals [normIdx+2];
179 edgeFlagsOut[i*numEdgePerFaceOut+j] = edgeFlags[j];
186 static void fghGenerateGeometry(int numFaces, int numEdgePerFace, GLdouble *vertices, GLubyte *vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut)
188 fghGenerateGeometryWithEdgeFlag(numFaces, numEdgePerFace, vertices, vertIndices, normals, vertOut, normOut, NULL);
192 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
193 static unsigned int ipow (int x, unsigned int y)
195 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
198 /* -- stuff that can be cached -- */
199 /* Cache of input to glDrawArrays */
200 #define DECLARE_SHAPE_CACHE(name,nameICaps,nameCaps)\
201 static GLboolean name##Cached = FALSE;\
202 static GLdouble name##_verts[nameCaps##_VERT_ELEM_PER_OBJ];\
203 static GLdouble name##_norms[nameCaps##_VERT_ELEM_PER_OBJ];\
204 static void fgh##nameICaps##Generate()\
206 fghGenerateGeometry(nameCaps##_NUM_FACES, nameCaps##_NUM_EDGE_PER_FACE,\
207 name##_v, name##_vi, name##_n,\
208 name##_verts, name##_norms);\
210 #define DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(name,nameICaps,nameCaps)\
211 static GLboolean name##Cached = FALSE;\
212 static GLdouble name##_verts[nameCaps##_VERT_ELEM_PER_OBJ];\
213 static GLdouble name##_norms[nameCaps##_VERT_ELEM_PER_OBJ];\
214 static GLboolean name##_edgeFlags[nameCaps##_VERT_PER_OBJ_TRI];\
215 static void fgh##nameICaps##Generate()\
217 fghGenerateGeometryWithEdgeFlag(nameCaps##_NUM_FACES, nameCaps##_NUM_EDGE_PER_FACE,\
218 name##_v, name##_vi, name##_n,\
219 name##_verts, name##_norms, name##_edgeFlags);\
222 * In general, we build arrays with all vertices or normals.
223 * We cant compress this and use glDrawElements as all combinations of
224 * vertex and normals are unique.
228 #define CUBE_NUM_VERT 8
229 #define CUBE_NUM_FACES 6
230 #define CUBE_NUM_EDGE_PER_FACE 4
231 #define CUBE_VERT_PER_OBJ (CUBE_NUM_FACES*CUBE_NUM_EDGE_PER_FACE)
232 #define CUBE_VERT_PER_OBJ_TRI (CUBE_VERT_PER_OBJ+CUBE_NUM_FACES*2) /* 2 extra edges per face when drawing quads as triangles */
233 #define CUBE_VERT_ELEM_PER_OBJ (CUBE_VERT_PER_OBJ_TRI*3)
234 /* Vertex Coordinates */
235 static GLdouble cube_v[CUBE_NUM_VERT*3] =
247 static GLdouble cube_n[CUBE_NUM_FACES*3] =
258 static GLubyte cube_vi[CUBE_VERT_PER_OBJ] =
267 DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(cube,Cube,CUBE);
270 #define ICOSAHEDRON_NUM_VERT 12
271 #define ICOSAHEDRON_NUM_FACES 20
272 #define ICOSAHEDRON_NUM_EDGE_PER_FACE 3
273 #define ICOSAHEDRON_VERT_PER_OBJ (ICOSAHEDRON_NUM_FACES*ICOSAHEDRON_NUM_EDGE_PER_FACE)
274 #define ICOSAHEDRON_VERT_PER_OBJ_TRI ICOSAHEDRON_VERT_PER_OBJ
275 #define ICOSAHEDRON_VERT_ELEM_PER_OBJ (ICOSAHEDRON_VERT_PER_OBJ_TRI*3)
276 /* Vertex Coordinates */
277 static GLdouble icosahedron_v[ICOSAHEDRON_NUM_VERT*3] =
280 0.447213595500, 0.894427191000, 0.0 ,
281 0.447213595500, 0.276393202252, 0.850650808354,
282 0.447213595500, -0.723606797748, 0.525731112119,
283 0.447213595500, -0.723606797748, -0.525731112119,
284 0.447213595500, 0.276393202252, -0.850650808354,
285 -0.447213595500, -0.894427191000, 0.0 ,
286 -0.447213595500, -0.276393202252, 0.850650808354,
287 -0.447213595500, 0.723606797748, 0.525731112119,
288 -0.447213595500, 0.723606797748, -0.525731112119,
289 -0.447213595500, -0.276393202252, -0.850650808354,
293 * icosahedron_n[i][0] = ( icosahedron_v[icosahedron_vi[i][1]][1] - icosahedron_v[icosahedron_vi[i][0]][1] ) * ( icosahedron_v[icosahedron_vi[i][2]][2] - icosahedron_v[icosahedron_vi[i][0]][2] ) - ( icosahedron_v[icosahedron_vi[i][1]][2] - icosahedron_v[icosahedron_vi[i][0]][2] ) * ( icosahedron_v[icosahedron_vi[i][2]][1] - icosahedron_v[icosahedron_vi[i][0]][1] ) ;
294 * icosahedron_n[i][1] = ( icosahedron_v[icosahedron_vi[i][1]][2] - icosahedron_v[icosahedron_vi[i][0]][2] ) * ( icosahedron_v[icosahedron_vi[i][2]][0] - icosahedron_v[icosahedron_vi[i][0]][0] ) - ( icosahedron_v[icosahedron_vi[i][1]][0] - icosahedron_v[icosahedron_vi[i][0]][0] ) * ( icosahedron_v[icosahedron_vi[i][2]][2] - icosahedron_v[icosahedron_vi[i][0]][2] ) ;
295 * icosahedron_n[i][2] = ( icosahedron_v[icosahedron_vi[i][1]][0] - icosahedron_v[icosahedron_vi[i][0]][0] ) * ( icosahedron_v[icosahedron_vi[i][2]][1] - icosahedron_v[icosahedron_vi[i][0]][1] ) - ( icosahedron_v[icosahedron_vi[i][1]][1] - icosahedron_v[icosahedron_vi[i][0]][1] ) * ( icosahedron_v[icosahedron_vi[i][2]][0] - icosahedron_v[icosahedron_vi[i][0]][0] ) ;
297 static GLdouble icosahedron_n[ICOSAHEDRON_NUM_FACES*3] =
299 0.760845213037948, 0.470228201835026, 0.341640786498800,
300 0.760845213036861, -0.179611190632978, 0.552786404500000,
301 0.760845213033849, -0.581234022404097, 0,
302 0.760845213036861, -0.179611190632978, -0.552786404500000,
303 0.760845213037948, 0.470228201835026, -0.341640786498800,
304 0.179611190628666, 0.760845213037948, 0.552786404498399,
305 0.179611190634277, -0.290617011204044, 0.894427191000000,
306 0.179611190633958, -0.940456403667806, 0,
307 0.179611190634278, -0.290617011204044, -0.894427191000000,
308 0.179611190628666, 0.760845213037948, -0.552786404498399,
309 -0.179611190633958, 0.940456403667806, 0,
310 -0.179611190634277, 0.290617011204044, 0.894427191000000,
311 -0.179611190628666, -0.760845213037948, 0.552786404498399,
312 -0.179611190628666, -0.760845213037948, -0.552786404498399,
313 -0.179611190634277, 0.290617011204044, -0.894427191000000,
314 -0.760845213036861, 0.179611190632978, -0.552786404500000,
315 -0.760845213033849, 0.581234022404097, 0,
316 -0.760845213036861, 0.179611190632978, 0.552786404500000,
317 -0.760845213037948, -0.470228201835026, 0.341640786498800,
318 -0.760845213037948, -0.470228201835026, -0.341640786498800,
322 static GLubyte icosahedron_vi[ICOSAHEDRON_VERT_PER_OBJ] =
345 DECLARE_SHAPE_CACHE(icosahedron,Icosahedron,ICOSAHEDRON);
347 /* -- Octahedron -- */
348 #define OCTAHEDRON_NUM_VERT 6
349 #define OCTAHEDRON_NUM_FACES 8
350 #define OCTAHEDRON_NUM_EDGE_PER_FACE 3
351 #define OCTAHEDRON_VERT_PER_OBJ (OCTAHEDRON_NUM_FACES*OCTAHEDRON_NUM_EDGE_PER_FACE)
352 #define OCTAHEDRON_VERT_PER_OBJ_TRI OCTAHEDRON_VERT_PER_OBJ
353 #define OCTAHEDRON_VERT_ELEM_PER_OBJ (OCTAHEDRON_VERT_PER_OBJ_TRI*3)
355 /* Vertex Coordinates */
356 static GLdouble octahedron_v[OCTAHEDRON_NUM_VERT*3] =
367 static GLdouble octahedron_n[OCTAHEDRON_NUM_FACES*3] =
369 0.577350269189, 0.577350269189, 0.577350269189, /* sqrt(1/3) */
370 0.577350269189, 0.577350269189,-0.577350269189,
371 0.577350269189,-0.577350269189, 0.577350269189,
372 0.577350269189,-0.577350269189,-0.577350269189,
373 -0.577350269189, 0.577350269189, 0.577350269189,
374 -0.577350269189, 0.577350269189,-0.577350269189,
375 -0.577350269189,-0.577350269189, 0.577350269189,
376 -0.577350269189,-0.577350269189,-0.577350269189
381 static GLubyte octahedron_vi[OCTAHEDRON_VERT_PER_OBJ] =
392 DECLARE_SHAPE_CACHE(octahedron,Octahedron,OCTAHEDRON);
394 /* -- RhombicDodecahedron -- */
395 #define RHOMBICDODECAHEDRON_NUM_VERT 14
396 #define RHOMBICDODECAHEDRON_NUM_FACES 12
397 #define RHOMBICDODECAHEDRON_NUM_EDGE_PER_FACE 4
398 #define RHOMBICDODECAHEDRON_VERT_PER_OBJ (RHOMBICDODECAHEDRON_NUM_FACES*RHOMBICDODECAHEDRON_NUM_EDGE_PER_FACE)
399 #define RHOMBICDODECAHEDRON_VERT_PER_OBJ_TRI (RHOMBICDODECAHEDRON_VERT_PER_OBJ+RHOMBICDODECAHEDRON_NUM_FACES*2) /* 2 extra edges per face when drawing quads as triangles */
400 #define RHOMBICDODECAHEDRON_VERT_ELEM_PER_OBJ (RHOMBICDODECAHEDRON_VERT_PER_OBJ_TRI*3)
402 /* Vertex Coordinates */
403 static GLdouble rhombicdodecahedron_v[RHOMBICDODECAHEDRON_NUM_VERT*3] =
406 0.707106781187, 0.0 , 0.5,
407 0.0 , 0.707106781187, 0.5,
408 -0.707106781187, 0.0 , 0.5,
409 0.0 , -0.707106781187, 0.5,
410 0.707106781187, 0.707106781187, 0.0,
411 -0.707106781187, 0.707106781187, 0.0,
412 -0.707106781187, -0.707106781187, 0.0,
413 0.707106781187, -0.707106781187, 0.0,
414 0.707106781187, 0.0 , -0.5,
415 0.0 , 0.707106781187, -0.5,
416 -0.707106781187, 0.0 , -0.5,
417 0.0 , -0.707106781187, -0.5,
421 static GLdouble rhombicdodecahedron_n[RHOMBICDODECAHEDRON_NUM_FACES*3] =
423 0.353553390594, 0.353553390594, 0.5,
424 -0.353553390594, 0.353553390594, 0.5,
425 -0.353553390594, -0.353553390594, 0.5,
426 0.353553390594, -0.353553390594, 0.5,
431 0.353553390594, 0.353553390594, -0.5,
432 -0.353553390594, 0.353553390594, -0.5,
433 -0.353553390594, -0.353553390594, -0.5,
434 0.353553390594, -0.353553390594, -0.5
438 static GLubyte rhombicdodecahedron_vi[RHOMBICDODECAHEDRON_VERT_PER_OBJ] =
453 DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
455 /* -- Tetrahedron -- */
456 /* Magic Numbers: r0 = ( 1, 0, 0 )
457 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
458 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
459 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
460 * |r0| = |r1| = |r2| = |r3| = 1
461 * Distance between any two points is 2 sqrt(6) / 3
463 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
465 #define TETRAHEDRON_NUM_VERT 4
466 #define TETRAHEDRON_NUM_FACES 4
467 #define TETRAHEDRON_NUM_EDGE_PER_FACE 3
468 #define TETRAHEDRON_VERT_PER_OBJ (TETRAHEDRON_NUM_FACES*TETRAHEDRON_NUM_EDGE_PER_FACE)
469 #define TETRAHEDRON_VERT_PER_OBJ_TRI TETRAHEDRON_VERT_PER_OBJ
470 #define TETRAHEDRON_VERT_ELEM_PER_OBJ (TETRAHEDRON_VERT_PER_OBJ_TRI*3)
472 /* Vertex Coordinates */
473 static GLdouble tetrahedron_v[TETRAHEDRON_NUM_VERT*3] =
476 -0.333333333333, 0.942809041582, 0.0,
477 -0.333333333333, -0.471404520791, 0.816496580928,
478 -0.333333333333, -0.471404520791, -0.816496580928
481 static GLdouble tetrahedron_n[TETRAHEDRON_NUM_FACES*3] =
484 0.333333333333, -0.942809041582, 0.0,
485 0.333333333333, 0.471404520791, -0.816496580928,
486 0.333333333333, 0.471404520791, 0.816496580928
490 static GLubyte tetrahedron_vi[TETRAHEDRON_VERT_PER_OBJ] =
497 DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON);
499 /* -- Sierpinski Sponge -- */
500 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, GLdouble* vertices, GLdouble* normals )
503 if ( numLevels == 0 )
505 for (i=0; i<TETRAHEDRON_NUM_FACES; i++)
508 int faceIdxVertIdx = i*TETRAHEDRON_NUM_EDGE_PER_FACE;
509 for (j=0; j<TETRAHEDRON_NUM_EDGE_PER_FACE; j++)
511 int outIdx = i*TETRAHEDRON_NUM_EDGE_PER_FACE*3+j*3;
512 int vertIdx = tetrahedron_vi[faceIdxVertIdx+j]*3;
514 vertices[outIdx ] = offset[0] + scale * tetrahedron_v[vertIdx ];
515 vertices[outIdx+1] = offset[1] + scale * tetrahedron_v[vertIdx+1];
516 vertices[outIdx+2] = offset[2] + scale * tetrahedron_v[vertIdx+2];
518 normals [outIdx ] = tetrahedron_n[normIdx ];
519 normals [outIdx+1] = tetrahedron_n[normIdx+1];
520 normals [outIdx+2] = tetrahedron_n[normIdx+2];
524 else if ( numLevels > 0 )
526 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
527 unsigned int stride = ipow(4,--numLevels)*TETRAHEDRON_VERT_ELEM_PER_OBJ;
529 for ( i = 0 ; i < TETRAHEDRON_NUM_FACES ; i++ )
532 local_offset[0] = offset[0] + scale * tetrahedron_v[idx ];
533 local_offset[1] = offset[1] + scale * tetrahedron_v[idx+1];
534 local_offset[2] = offset[2] + scale * tetrahedron_v[idx+2];
535 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
540 /* -- Now the various shapes involving circles -- */
542 * Compute lookup table of cos and sin values forming a cirle
545 * It is the responsibility of the caller to free these tables
546 * The size of the table is (n+1) to form a connected loop
547 * The last entry is exactly the same as the first
548 * The sign of n can be flipped to get the reverse loop
550 static void fghCircleTable(double **sint,double **cost,const int n)
554 /* Table size, the sign of n flips the circle direction */
556 const int size = abs(n);
558 /* Determine the angle between samples */
560 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
562 /* Allocate memory for n samples, plus duplicate of first entry at the end */
564 *sint = (double *) calloc(sizeof(double), size+1);
565 *cost = (double *) calloc(sizeof(double), size+1);
567 /* Bail out if memory allocation fails, fgError never returns */
569 if (!(*sint) || !(*cost))
573 fgError("Failed to allocate memory in fghCircleTable");
576 /* Compute cos and sin around the circle */
581 for (i=1; i<size; i++)
583 (*sint)[i] = sin(angle*i);
584 (*cost)[i] = cos(angle*i);
587 /* Last sample is duplicate of the first */
589 (*sint)[size] = (*sint)[0];
590 (*cost)[size] = (*cost)[0];
594 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
595 #define DECLARE_INTERNAL_DRAW(vertexMode,name,nameICaps,nameCaps)\
596 static void fgh##nameICaps( GLboolean useWireMode )\
600 fgh##nameICaps##Generate();\
601 name##Cached = GL_TRUE;\
603 fghDrawGeometry(vertexMode,name##_verts,name##_norms,NULL,nameCaps##_VERT_PER_OBJ_TRI,useWireMode);\
606 static void fghCube( GLdouble dSize, GLboolean useWireMode )
611 cubeCached = GL_TRUE;
618 /* Need to build new vertex list containing vertices for cube of different size */
619 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_OBJ * sizeof(GLdouble));
620 for (i=0; i<CUBE_VERT_ELEM_PER_OBJ; i++)
621 vertices[i] = dSize*cube_verts[i];
623 fghDrawGeometry(GL_TRIANGLES,vertices ,cube_norms,cube_edgeFlags,CUBE_VERT_PER_OBJ_TRI,useWireMode);
626 fghDrawGeometry(GL_TRIANGLES,cube_verts,cube_norms,cube_edgeFlags,CUBE_VERT_PER_OBJ_TRI,useWireMode);
629 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,icosahedron,Icosahedron,ICOSAHEDRON);
630 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,octahedron,Octahedron,OCTAHEDRON);
631 DECLARE_INTERNAL_DRAW(GL_QUADS,rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
632 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,tetrahedron,Tetrahedron,TETRAHEDRON);
634 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
638 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
639 GLsizei numVert = numTetr*TETRAHEDRON_VERT_PER_OBJ;
643 /* Allocate memory */
644 vertices = malloc(numVert*3 * sizeof(GLdouble));
645 normals = malloc(numVert*3 * sizeof(GLdouble));
647 /* Generate elements */
648 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
650 /* Draw and cleanup */
651 fghDrawGeometry(GL_TRIANGLES,vertices,normals,NULL,numVert,useWireMode);
658 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
662 * Draws a solid sphere
664 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
668 /* Adjust z and radius as stacks are drawn. */
673 /* Pre-computed circle */
675 double *sint1,*cost1;
676 double *sint2,*cost2;
678 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
680 fghCircleTable(&sint1,&cost1,-slices);
681 fghCircleTable(&sint2,&cost2,stacks*2);
683 /* The top stack is covered with a triangle fan */
686 z1 = cost2[(stacks>0)?1:0];
688 r1 = sint2[(stacks>0)?1:0];
690 glBegin(GL_TRIANGLE_FAN);
693 glVertex3d(0,0,radius);
695 for (j=slices; j>=0; j--)
697 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
698 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
703 /* Cover each stack with a quad strip, except the top and bottom stacks */
705 for( i=1; i<stacks-1; i++ )
707 z0 = z1; z1 = cost2[i+1];
708 r0 = r1; r1 = sint2[i+1];
710 glBegin(GL_QUAD_STRIP);
712 for(j=0; j<=slices; j++)
714 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
715 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
716 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
717 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
723 /* The bottom stack is covered with a triangle fan */
728 glBegin(GL_TRIANGLE_FAN);
731 glVertex3d(0,0,-radius);
733 for (j=0; j<=slices; j++)
735 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
736 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
741 /* Release sin and cos tables */
750 * Draws a wire sphere
752 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
756 /* Adjust z and radius as stacks and slices are drawn. */
761 /* Pre-computed circle */
763 double *sint1,*cost1;
764 double *sint2,*cost2;
766 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
768 fghCircleTable(&sint1,&cost1,-slices );
769 fghCircleTable(&sint2,&cost2, stacks*2);
771 /* Draw a line loop for each stack */
773 for (i=1; i<stacks; i++)
778 glBegin(GL_LINE_LOOP);
780 for(j=0; j<=slices; j++)
786 glVertex3d(x*r*radius,y*r*radius,z*radius);
792 /* Draw a line loop for each slice */
794 for (i=0; i<slices; i++)
796 glBegin(GL_LINE_STRIP);
798 for(j=0; j<=stacks; j++)
800 x = cost1[i]*sint2[j];
801 y = sint1[i]*sint2[j];
805 glVertex3d(x*radius,y*radius,z*radius);
811 /* Release sin and cos tables */
822 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
826 /* Step in z and radius as stacks are drawn. */
831 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
832 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
834 /* Scaling factors for vertex normals */
836 const double cosn = ( height / sqrt ( height * height + base * base ));
837 const double sinn = ( base / sqrt ( height * height + base * base ));
839 /* Pre-computed circle */
843 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
845 fghCircleTable(&sint,&cost,-slices);
847 /* Cover the circular base with a triangle fan... */
855 glBegin(GL_TRIANGLE_FAN);
857 glNormal3d(0.0,0.0,-1.0);
858 glVertex3d(0.0,0.0, z0 );
860 for (j=0; j<=slices; j++)
861 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
865 /* Cover each stack with a quad strip, except the top stack */
867 for( i=0; i<stacks-1; i++ )
869 glBegin(GL_QUAD_STRIP);
871 for(j=0; j<=slices; j++)
873 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
874 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
875 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
878 z0 = z1; z1 += zStep;
879 r0 = r1; r1 -= rStep;
884 /* The top stack is covered with individual triangles */
886 glBegin(GL_TRIANGLES);
888 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
890 for (j=0; j<slices; j++)
892 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
893 glVertex3d(0, 0, height);
894 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
895 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
900 /* Release sin and cos tables */
909 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
913 /* Step in z and radius as stacks are drawn. */
918 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
919 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
921 /* Scaling factors for vertex normals */
923 const double cosn = ( height / sqrt ( height * height + base * base ));
924 const double sinn = ( base / sqrt ( height * height + base * base ));
926 /* Pre-computed circle */
930 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
932 fghCircleTable(&sint,&cost,-slices);
934 /* Draw the stacks... */
936 for (i=0; i<stacks; i++)
938 glBegin(GL_LINE_LOOP);
940 for( j=0; j<slices; j++ )
942 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
943 glVertex3d(cost[j]*r, sint[j]*r, z );
952 /* Draw the slices */
958 for (j=0; j<slices; j++)
960 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
961 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
962 glVertex3d(0.0, 0.0, height);
967 /* Release sin and cos tables */
975 * Draws a solid cylinder
977 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
981 /* Step in z and radius as stacks are drawn. */
984 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
986 /* Pre-computed circle */
990 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
992 fghCircleTable(&sint,&cost,-slices);
994 /* Cover the base and top */
996 glBegin(GL_TRIANGLE_FAN);
997 glNormal3d(0.0, 0.0, -1.0 );
998 glVertex3d(0.0, 0.0, 0.0 );
999 for (j=0; j<=slices; j++)
1000 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
1003 glBegin(GL_TRIANGLE_FAN);
1004 glNormal3d(0.0, 0.0, 1.0 );
1005 glVertex3d(0.0, 0.0, height);
1006 for (j=slices; j>=0; j--)
1007 glVertex3d(cost[j]*radius, sint[j]*radius, height);
1015 for (i=1; i<=stacks; i++)
1020 glBegin(GL_QUAD_STRIP);
1021 for (j=0; j<=slices; j++ )
1023 glNormal3d(cost[j], sint[j], 0.0 );
1024 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
1025 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
1029 z0 = z1; z1 += zStep;
1032 /* Release sin and cos tables */
1039 * Draws a wire cylinder
1041 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
1045 /* Step in z and radius as stacks are drawn. */
1048 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
1050 /* Pre-computed circle */
1054 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
1056 fghCircleTable(&sint,&cost,-slices);
1058 /* Draw the stacks... */
1060 for (i=0; i<=stacks; i++)
1065 glBegin(GL_LINE_LOOP);
1067 for( j=0; j<slices; j++ )
1069 glNormal3d(cost[j], sint[j], 0.0);
1070 glVertex3d(cost[j]*radius, sint[j]*radius, z );
1078 /* Draw the slices */
1082 for (j=0; j<slices; j++)
1084 glNormal3d(cost[j], sint[j], 0.0 );
1085 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
1086 glVertex3d(cost[j]*radius, sint[j]*radius, height);
1091 /* Release sin and cos tables */
1098 * Draws a wire torus
1100 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1102 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1103 double *vertex, *normal;
1105 double spsi, cpsi, sphi, cphi ;
1107 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
1109 if ( nSides < 1 ) nSides = 1;
1110 if ( nRings < 1 ) nRings = 1;
1112 /* Allocate the vertices array */
1113 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1114 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1118 dpsi = 2.0 * M_PI / (double)nRings ;
1119 dphi = -2.0 * M_PI / (double)nSides ;
1122 for( j=0; j<nRings; j++ )
1124 cpsi = cos ( psi ) ;
1125 spsi = sin ( psi ) ;
1128 for( i=0; i<nSides; i++ )
1130 int offset = 3 * ( j * nSides + i ) ;
1131 cphi = cos ( phi ) ;
1132 sphi = sin ( phi ) ;
1133 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1134 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1135 *(vertex + offset + 2) = sphi * iradius ;
1136 *(normal + offset + 0) = cpsi * cphi ;
1137 *(normal + offset + 1) = spsi * cphi ;
1138 *(normal + offset + 2) = sphi ;
1145 for( i=0; i<nSides; i++ )
1147 glBegin( GL_LINE_LOOP );
1149 for( j=0; j<nRings; j++ )
1151 int offset = 3 * ( j * nSides + i ) ;
1152 glNormal3dv( normal + offset );
1153 glVertex3dv( vertex + offset );
1159 for( j=0; j<nRings; j++ )
1161 glBegin(GL_LINE_LOOP);
1163 for( i=0; i<nSides; i++ )
1165 int offset = 3 * ( j * nSides + i ) ;
1166 glNormal3dv( normal + offset );
1167 glVertex3dv( vertex + offset );
1179 * Draws a solid torus
1181 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1183 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1184 double *vertex, *normal;
1186 double spsi, cpsi, sphi, cphi ;
1188 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
1190 if ( nSides < 1 ) nSides = 1;
1191 if ( nRings < 1 ) nRings = 1;
1193 /* Increment the number of sides and rings to allow for one more point than surface */
1197 /* Allocate the vertices array */
1198 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1199 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1203 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
1204 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
1207 for( j=0; j<nRings; j++ )
1209 cpsi = cos ( psi ) ;
1210 spsi = sin ( psi ) ;
1213 for( i=0; i<nSides; i++ )
1215 int offset = 3 * ( j * nSides + i ) ;
1216 cphi = cos ( phi ) ;
1217 sphi = sin ( phi ) ;
1218 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1219 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1220 *(vertex + offset + 2) = sphi * iradius ;
1221 *(normal + offset + 0) = cpsi * cphi ;
1222 *(normal + offset + 1) = spsi * cphi ;
1223 *(normal + offset + 2) = sphi ;
1230 glBegin( GL_QUADS );
1231 for( i=0; i<nSides-1; i++ )
1233 for( j=0; j<nRings-1; j++ )
1235 int offset = 3 * ( j * nSides + i ) ;
1236 glNormal3dv( normal + offset );
1237 glVertex3dv( vertex + offset );
1238 glNormal3dv( normal + offset + 3 );
1239 glVertex3dv( vertex + offset + 3 );
1240 glNormal3dv( normal + offset + 3 * nSides + 3 );
1241 glVertex3dv( vertex + offset + 3 * nSides + 3 );
1242 glNormal3dv( normal + offset + 3 * nSides );
1243 glVertex3dv( vertex + offset + 3 * nSides );
1257 void FGAPIENTRY glutWireDodecahedron( void )
1259 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
1261 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1262 * of a cube. The coordinates of the points are:
1263 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1264 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1265 * x = 0.61803398875 and z = 1.61803398875.
1267 glBegin ( GL_LINE_LOOP ) ;
1268 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 ) ;
1270 glBegin ( GL_LINE_LOOP ) ;
1271 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 ) ;
1273 glBegin ( GL_LINE_LOOP ) ;
1274 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 ) ;
1276 glBegin ( GL_LINE_LOOP ) ;
1277 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 ) ;
1280 glBegin ( GL_LINE_LOOP ) ;
1281 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 ) ;
1283 glBegin ( GL_LINE_LOOP ) ;
1284 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 ) ;
1286 glBegin ( GL_LINE_LOOP ) ;
1287 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 ) ;
1289 glBegin ( GL_LINE_LOOP ) ;
1290 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 ) ;
1293 glBegin ( GL_LINE_LOOP ) ;
1294 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 ) ;
1296 glBegin ( GL_LINE_LOOP ) ;
1297 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 ) ;
1299 glBegin ( GL_LINE_LOOP ) ;
1300 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 ) ;
1302 glBegin ( GL_LINE_LOOP ) ;
1303 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 ) ;
1310 void FGAPIENTRY glutSolidDodecahedron( void )
1312 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1314 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1315 * of a cube. The coordinates of the points are:
1316 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1317 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1318 * x = 0.61803398875 and z = 1.61803398875.
1320 glBegin ( GL_POLYGON ) ;
1321 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 ) ;
1323 glBegin ( GL_POLYGON ) ;
1324 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 ) ;
1326 glBegin ( GL_POLYGON ) ;
1327 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 ) ;
1329 glBegin ( GL_POLYGON ) ;
1330 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 ) ;
1333 glBegin ( GL_POLYGON ) ;
1334 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 ) ;
1336 glBegin ( GL_POLYGON ) ;
1337 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 ) ;
1339 glBegin ( GL_POLYGON ) ;
1340 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 ) ;
1342 glBegin ( GL_POLYGON ) ;
1343 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 ) ;
1346 glBegin ( GL_POLYGON ) ;
1347 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 ) ;
1349 glBegin ( GL_POLYGON ) ;
1350 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 ) ;
1352 glBegin ( GL_POLYGON ) ;
1353 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 ) ;
1355 glBegin ( GL_POLYGON ) ;
1356 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 ) ;
1362 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1363 /* Macro to generate interface functions */
1364 #define DECLARE_SHAPE_INTERFACE(nameICaps)\
1365 void FGAPIENTRY glutWire##nameICaps( void )\
1367 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWire"#nameICaps );\
1368 fgh##nameICaps( TRUE );\
1370 void FGAPIENTRY glutSolid##nameICaps( void )\
1372 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolid"#nameICaps );\
1373 fgh##nameICaps( FALSE );\
1376 void FGAPIENTRY glutWireCube( GLdouble dSize )
1378 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1379 fghCube( dSize, TRUE );
1381 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1383 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1384 fghCube( dSize, FALSE );
1387 DECLARE_SHAPE_INTERFACE(Icosahedron);
1388 DECLARE_SHAPE_INTERFACE(Octahedron);
1389 DECLARE_SHAPE_INTERFACE(RhombicDodecahedron);
1391 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1393 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1394 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1396 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1398 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1399 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1402 DECLARE_SHAPE_INTERFACE(Tetrahedron);
1405 /*** END OF FILE ***/