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;
169 vertOut[outIdx ] = vertices[vertIdx ];
170 vertOut[outIdx+1] = vertices[vertIdx+1];
171 vertOut[outIdx+2] = vertices[vertIdx+2];
173 normOut[outIdx ] = normals [normIdx ];
174 normOut[outIdx+1] = normals [normIdx+1];
175 normOut[outIdx+2] = normals [normIdx+2];
178 edgeFlagsOut[i*numEdgePerFaceOut+j] = edgeFlags[j];
183 static void fghGenerateGeometry(int numFaces, int numEdgePerFace, GLdouble *vertices, GLubyte *vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut)
185 fghGenerateGeometryWithEdgeFlag(numFaces, numEdgePerFace, vertices, vertIndices, normals, vertOut, normOut, NULL);
189 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
190 static unsigned int ipow (int x, unsigned int y)
192 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
195 /* -- stuff that can be cached -- */
196 /* Cache of input to glDrawArrays */
197 #define DECLARE_SHAPE_CACHE(name,nameICaps,nameCaps)\
198 static GLboolean name##Cached = FALSE;\
199 static GLdouble name##_verts[nameCaps##_VERT_ELEM_PER_OBJ];\
200 static GLdouble name##_norms[nameCaps##_VERT_ELEM_PER_OBJ];\
201 static void fgh##nameICaps##Generate()\
203 fghGenerateGeometry(nameCaps##_NUM_FACES, nameCaps##_NUM_EDGE_PER_FACE,\
204 name##_v, name##_vi, name##_n,\
205 name##_verts, name##_norms);\
207 #define DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(name,nameICaps,nameCaps)\
208 static GLboolean name##Cached = FALSE;\
209 static GLdouble name##_verts[nameCaps##_VERT_ELEM_PER_OBJ];\
210 static GLdouble name##_norms[nameCaps##_VERT_ELEM_PER_OBJ];\
211 static GLboolean name##_edgeFlags[nameCaps##_VERT_PER_OBJ_TRI];\
212 static void fgh##nameICaps##Generate()\
214 fghGenerateGeometryWithEdgeFlag(nameCaps##_NUM_FACES, nameCaps##_NUM_EDGE_PER_FACE,\
215 name##_v, name##_vi, name##_n,\
216 name##_verts, name##_norms, name##_edgeFlags);\
219 * In general, we build arrays with all vertices or normals.
220 * We cant compress this and use glDrawElements as all combinations of
221 * vertex and normals are unique.
225 #define CUBE_NUM_VERT 8
226 #define CUBE_NUM_FACES 6
227 #define CUBE_NUM_EDGE_PER_FACE 4
228 #define CUBE_VERT_PER_OBJ (CUBE_NUM_FACES*CUBE_NUM_EDGE_PER_FACE)
229 #define CUBE_VERT_PER_OBJ_TRI (CUBE_VERT_PER_OBJ+CUBE_NUM_FACES*2) /* 2 extra edges per face when drawing quads as triangles */
230 #define CUBE_VERT_ELEM_PER_OBJ (CUBE_VERT_PER_OBJ_TRI*3)
231 /* Vertex Coordinates */
232 static GLdouble cube_v[CUBE_NUM_VERT*3] =
244 static GLdouble cube_n[CUBE_NUM_FACES*3] =
255 static GLubyte cube_vi[CUBE_VERT_PER_OBJ] =
264 DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(cube,Cube,CUBE);
267 #define ICOSAHEDRON_NUM_VERT 12
268 #define ICOSAHEDRON_NUM_FACES 20
269 #define ICOSAHEDRON_NUM_EDGE_PER_FACE 3
270 #define ICOSAHEDRON_VERT_PER_OBJ (ICOSAHEDRON_NUM_FACES*ICOSAHEDRON_NUM_EDGE_PER_FACE)
271 #define ICOSAHEDRON_VERT_PER_OBJ_TRI ICOSAHEDRON_VERT_PER_OBJ
272 #define ICOSAHEDRON_VERT_ELEM_PER_OBJ (ICOSAHEDRON_VERT_PER_OBJ_TRI*3)
273 /* Vertex Coordinates */
274 static GLdouble icosahedron_v[ICOSAHEDRON_NUM_VERT*3] =
277 0.447213595500, 0.894427191000, 0.0 ,
278 0.447213595500, 0.276393202252, 0.850650808354,
279 0.447213595500, -0.723606797748, 0.525731112119,
280 0.447213595500, -0.723606797748, -0.525731112119,
281 0.447213595500, 0.276393202252, -0.850650808354,
282 -0.447213595500, -0.894427191000, 0.0 ,
283 -0.447213595500, -0.276393202252, 0.850650808354,
284 -0.447213595500, 0.723606797748, 0.525731112119,
285 -0.447213595500, 0.723606797748, -0.525731112119,
286 -0.447213595500, -0.276393202252, -0.850650808354,
290 * 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] ) ;
291 * 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] ) ;
292 * 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] ) ;
294 static GLdouble icosahedron_n[ICOSAHEDRON_NUM_FACES*3] =
296 0.760845213037948, 0.470228201835026, 0.341640786498800,
297 0.760845213036861, -0.179611190632978, 0.552786404500000,
298 0.760845213033849, -0.581234022404097, 0,
299 0.760845213036861, -0.179611190632978, -0.552786404500000,
300 0.760845213037948, 0.470228201835026, -0.341640786498800,
301 0.179611190628666, 0.760845213037948, 0.552786404498399,
302 0.179611190634277, -0.290617011204044, 0.894427191000000,
303 0.179611190633958, -0.940456403667806, 0,
304 0.179611190634278, -0.290617011204044, -0.894427191000000,
305 0.179611190628666, 0.760845213037948, -0.552786404498399,
306 -0.179611190633958, 0.940456403667806, 0,
307 -0.179611190634277, 0.290617011204044, 0.894427191000000,
308 -0.179611190628666, -0.760845213037948, 0.552786404498399,
309 -0.179611190628666, -0.760845213037948, -0.552786404498399,
310 -0.179611190634277, 0.290617011204044, -0.894427191000000,
311 -0.760845213036861, 0.179611190632978, -0.552786404500000,
312 -0.760845213033849, 0.581234022404097, 0,
313 -0.760845213036861, 0.179611190632978, 0.552786404500000,
314 -0.760845213037948, -0.470228201835026, 0.341640786498800,
315 -0.760845213037948, -0.470228201835026, -0.341640786498800,
319 static GLubyte icosahedron_vi[ICOSAHEDRON_VERT_PER_OBJ] =
342 DECLARE_SHAPE_CACHE(icosahedron,Icosahedron,ICOSAHEDRON);
344 /* -- Octahedron -- */
345 #define OCTAHEDRON_NUM_VERT 6
346 #define OCTAHEDRON_NUM_FACES 8
347 #define OCTAHEDRON_NUM_EDGE_PER_FACE 3
348 #define OCTAHEDRON_VERT_PER_OBJ (OCTAHEDRON_NUM_FACES*OCTAHEDRON_NUM_EDGE_PER_FACE)
349 #define OCTAHEDRON_VERT_PER_OBJ_TRI OCTAHEDRON_VERT_PER_OBJ
350 #define OCTAHEDRON_VERT_ELEM_PER_OBJ (OCTAHEDRON_VERT_PER_OBJ_TRI*3)
352 /* Vertex Coordinates */
353 static GLdouble octahedron_v[OCTAHEDRON_NUM_VERT*3] =
364 static GLdouble octahedron_n[OCTAHEDRON_NUM_FACES*3] =
366 0.577350269189, 0.577350269189, 0.577350269189, /* sqrt(1/3) */
367 0.577350269189, 0.577350269189,-0.577350269189,
368 0.577350269189,-0.577350269189, 0.577350269189,
369 0.577350269189,-0.577350269189,-0.577350269189,
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
378 static GLubyte octahedron_vi[OCTAHEDRON_VERT_PER_OBJ] =
389 DECLARE_SHAPE_CACHE(octahedron,Octahedron,OCTAHEDRON);
391 /* -- RhombicDodecahedron -- */
392 #define RHOMBICDODECAHEDRON_NUM_VERT 14
393 #define RHOMBICDODECAHEDRON_NUM_FACES 12
394 #define RHOMBICDODECAHEDRON_NUM_EDGE_PER_FACE 4
395 #define RHOMBICDODECAHEDRON_VERT_PER_OBJ (RHOMBICDODECAHEDRON_NUM_FACES*RHOMBICDODECAHEDRON_NUM_EDGE_PER_FACE)
396 #define RHOMBICDODECAHEDRON_VERT_PER_OBJ_TRI (RHOMBICDODECAHEDRON_VERT_PER_OBJ+RHOMBICDODECAHEDRON_NUM_FACES*2) /* 2 extra edges per face when drawing quads as triangles */
397 #define RHOMBICDODECAHEDRON_VERT_ELEM_PER_OBJ (RHOMBICDODECAHEDRON_VERT_PER_OBJ_TRI*3)
399 /* Vertex Coordinates */
400 static GLdouble rhombicdodecahedron_v[RHOMBICDODECAHEDRON_NUM_VERT*3] =
403 0.707106781187, 0.0 , 0.5,
404 0.0 , 0.707106781187, 0.5,
405 -0.707106781187, 0.0 , 0.5,
406 0.0 , -0.707106781187, 0.5,
407 0.707106781187, 0.707106781187, 0.0,
408 -0.707106781187, 0.707106781187, 0.0,
409 -0.707106781187, -0.707106781187, 0.0,
410 0.707106781187, -0.707106781187, 0.0,
411 0.707106781187, 0.0 , -0.5,
412 0.0 , 0.707106781187, -0.5,
413 -0.707106781187, 0.0 , -0.5,
414 0.0 , -0.707106781187, -0.5,
418 static GLdouble rhombicdodecahedron_n[RHOMBICDODECAHEDRON_NUM_FACES*3] =
420 0.353553390594, 0.353553390594, 0.5,
421 -0.353553390594, 0.353553390594, 0.5,
422 -0.353553390594, -0.353553390594, 0.5,
423 0.353553390594, -0.353553390594, 0.5,
428 0.353553390594, 0.353553390594, -0.5,
429 -0.353553390594, 0.353553390594, -0.5,
430 -0.353553390594, -0.353553390594, -0.5,
431 0.353553390594, -0.353553390594, -0.5
435 static GLubyte rhombicdodecahedron_vi[RHOMBICDODECAHEDRON_VERT_PER_OBJ] =
450 DECLARE_SHAPE_CACHE_DECOMPOSE_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
452 /* -- Tetrahedron -- */
453 /* Magic Numbers: r0 = ( 1, 0, 0 )
454 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
455 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
456 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
457 * |r0| = |r1| = |r2| = |r3| = 1
458 * Distance between any two points is 2 sqrt(6) / 3
460 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
462 #define TETRAHEDRON_NUM_VERT 4
463 #define TETRAHEDRON_NUM_FACES 4
464 #define TETRAHEDRON_NUM_EDGE_PER_FACE 3
465 #define TETRAHEDRON_VERT_PER_OBJ (TETRAHEDRON_NUM_FACES*TETRAHEDRON_NUM_EDGE_PER_FACE)
466 #define TETRAHEDRON_VERT_PER_OBJ_TRI TETRAHEDRON_VERT_PER_OBJ
467 #define TETRAHEDRON_VERT_ELEM_PER_OBJ (TETRAHEDRON_VERT_PER_OBJ_TRI*3)
469 /* Vertex Coordinates */
470 static GLdouble tetrahedron_v[TETRAHEDRON_NUM_VERT*3] =
473 -0.333333333333, 0.942809041582, 0.0,
474 -0.333333333333, -0.471404520791, 0.816496580928,
475 -0.333333333333, -0.471404520791, -0.816496580928
478 static GLdouble tetrahedron_n[TETRAHEDRON_NUM_FACES*3] =
481 0.333333333333, -0.942809041582, 0.0,
482 0.333333333333, 0.471404520791, -0.816496580928,
483 0.333333333333, 0.471404520791, 0.816496580928
487 static GLubyte tetrahedron_vi[TETRAHEDRON_VERT_PER_OBJ] =
494 DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON);
496 /* -- Sierpinski Sponge -- */
497 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, GLdouble* vertices, GLdouble* normals )
500 if ( numLevels == 0 )
502 for (i=0; i<TETRAHEDRON_NUM_FACES; i++)
505 int faceIdxVertIdx = i*TETRAHEDRON_NUM_EDGE_PER_FACE;
506 for (j=0; j<TETRAHEDRON_NUM_EDGE_PER_FACE; j++)
508 int outIdx = i*TETRAHEDRON_NUM_EDGE_PER_FACE*3+j*3;
509 int vertIdx = tetrahedron_vi[faceIdxVertIdx+j]*3;
511 vertices[outIdx ] = offset[0] + scale * tetrahedron_v[vertIdx ];
512 vertices[outIdx+1] = offset[1] + scale * tetrahedron_v[vertIdx+1];
513 vertices[outIdx+2] = offset[2] + scale * tetrahedron_v[vertIdx+2];
515 normals [outIdx ] = tetrahedron_n[normIdx ];
516 normals [outIdx+1] = tetrahedron_n[normIdx+1];
517 normals [outIdx+2] = tetrahedron_n[normIdx+2];
521 else if ( numLevels > 0 )
523 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
524 unsigned int stride = ipow(4,--numLevels)*TETRAHEDRON_VERT_ELEM_PER_OBJ;
526 for ( i = 0 ; i < TETRAHEDRON_NUM_FACES ; i++ )
529 local_offset[0] = offset[0] + scale * tetrahedron_v[idx ];
530 local_offset[1] = offset[1] + scale * tetrahedron_v[idx+1];
531 local_offset[2] = offset[2] + scale * tetrahedron_v[idx+2];
532 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
537 /* -- Now the various shapes involving circles -- */
539 * Compute lookup table of cos and sin values forming a cirle
542 * It is the responsibility of the caller to free these tables
543 * The size of the table is (n+1) to form a connected loop
544 * The last entry is exactly the same as the first
545 * The sign of n can be flipped to get the reverse loop
547 static void fghCircleTable(double **sint,double **cost,const int n)
551 /* Table size, the sign of n flips the circle direction */
553 const int size = abs(n);
555 /* Determine the angle between samples */
557 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
559 /* Allocate memory for n samples, plus duplicate of first entry at the end */
561 *sint = (double *) calloc(sizeof(double), size+1);
562 *cost = (double *) calloc(sizeof(double), size+1);
564 /* Bail out if memory allocation fails, fgError never returns */
566 if (!(*sint) || !(*cost))
570 fgError("Failed to allocate memory in fghCircleTable");
573 /* Compute cos and sin around the circle */
578 for (i=1; i<size; i++)
580 (*sint)[i] = sin(angle*i);
581 (*cost)[i] = cos(angle*i);
584 /* Last sample is duplicate of the first */
586 (*sint)[size] = (*sint)[0];
587 (*cost)[size] = (*cost)[0];
591 /* -- INTERNAL DRAWING functions --------------------------------------- */
592 #define _DECLARE_INTERNAL_DRAW_DO_DECLARE(name,nameICaps,nameCaps,edgeFlags)\
593 static void fgh##nameICaps( GLboolean useWireMode )\
597 fgh##nameICaps##Generate();\
598 name##Cached = GL_TRUE;\
600 fghDrawGeometry(GL_TRIANGLES,name##_verts,name##_norms,edgeFlags,nameCaps##_VERT_PER_OBJ_TRI,useWireMode);\
602 #define DECLARE_INTERNAL_DRAW(name,nameICaps,nameCaps) _DECLARE_INTERNAL_DRAW_DO_DECLARE(name,nameICaps,nameCaps,NULL)
603 #define DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(name,nameICaps,nameCaps) _DECLARE_INTERNAL_DRAW_DO_DECLARE(name,nameICaps,nameCaps,name##_edgeFlags)
605 static void fghCube( GLdouble dSize, GLboolean useWireMode )
610 cubeCached = GL_TRUE;
617 /* Need to build new vertex list containing vertices for cube of different size */
618 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_OBJ * sizeof(GLdouble));
619 for (i=0; i<CUBE_VERT_ELEM_PER_OBJ; i++)
620 vertices[i] = dSize*cube_verts[i];
622 fghDrawGeometry(GL_TRIANGLES,vertices ,cube_norms,cube_edgeFlags,CUBE_VERT_PER_OBJ_TRI,useWireMode);
625 fghDrawGeometry(GL_TRIANGLES,cube_verts,cube_norms,cube_edgeFlags,CUBE_VERT_PER_OBJ_TRI,useWireMode);
628 DECLARE_INTERNAL_DRAW(icosahedron,Icosahedron,ICOSAHEDRON);
629 DECLARE_INTERNAL_DRAW(octahedron,Octahedron,OCTAHEDRON);
630 DECLARE_INTERNAL_DRAW_DECOMPOSED_TO_TRIANGLE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
631 DECLARE_INTERNAL_DRAW(tetrahedron,Tetrahedron,TETRAHEDRON);
633 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
637 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
638 GLsizei numVert = numTetr*TETRAHEDRON_VERT_PER_OBJ;
642 /* Allocate memory */
643 vertices = malloc(numVert*3 * sizeof(GLdouble));
644 normals = malloc(numVert*3 * sizeof(GLdouble));
646 /* Generate elements */
647 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
649 /* Draw and cleanup */
650 fghDrawGeometry(GL_TRIANGLES,vertices,normals,NULL,numVert,useWireMode);
657 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
661 * Draws a solid sphere
663 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
667 /* Adjust z and radius as stacks are drawn. */
672 /* Pre-computed circle */
674 double *sint1,*cost1;
675 double *sint2,*cost2;
677 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
679 fghCircleTable(&sint1,&cost1,-slices);
680 fghCircleTable(&sint2,&cost2,stacks*2);
682 /* The top stack is covered with a triangle fan */
685 z1 = cost2[(stacks>0)?1:0];
687 r1 = sint2[(stacks>0)?1:0];
689 glBegin(GL_TRIANGLE_FAN);
692 glVertex3d(0,0,radius);
694 for (j=slices; j>=0; j--)
696 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
697 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
702 /* Cover each stack with a quad strip, except the top and bottom stacks */
704 for( i=1; i<stacks-1; i++ )
706 z0 = z1; z1 = cost2[i+1];
707 r0 = r1; r1 = sint2[i+1];
709 glBegin(GL_QUAD_STRIP);
711 for(j=0; j<=slices; j++)
713 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
714 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
715 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
716 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
722 /* The bottom stack is covered with a triangle fan */
727 glBegin(GL_TRIANGLE_FAN);
730 glVertex3d(0,0,-radius);
732 for (j=0; j<=slices; j++)
734 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
735 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
740 /* Release sin and cos tables */
749 * Draws a wire sphere
751 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
755 /* Adjust z and radius as stacks and slices are drawn. */
760 /* Pre-computed circle */
762 double *sint1,*cost1;
763 double *sint2,*cost2;
765 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
767 fghCircleTable(&sint1,&cost1,-slices );
768 fghCircleTable(&sint2,&cost2, stacks*2);
770 /* Draw a line loop for each stack */
772 for (i=1; i<stacks; i++)
777 glBegin(GL_LINE_LOOP);
779 for(j=0; j<=slices; j++)
785 glVertex3d(x*r*radius,y*r*radius,z*radius);
791 /* Draw a line loop for each slice */
793 for (i=0; i<slices; i++)
795 glBegin(GL_LINE_STRIP);
797 for(j=0; j<=stacks; j++)
799 x = cost1[i]*sint2[j];
800 y = sint1[i]*sint2[j];
804 glVertex3d(x*radius,y*radius,z*radius);
810 /* Release sin and cos tables */
821 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
825 /* Step in z and radius as stacks are drawn. */
830 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
831 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
833 /* Scaling factors for vertex normals */
835 const double cosn = ( height / sqrt ( height * height + base * base ));
836 const double sinn = ( base / sqrt ( height * height + base * base ));
838 /* Pre-computed circle */
842 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
844 fghCircleTable(&sint,&cost,-slices);
846 /* Cover the circular base with a triangle fan... */
854 glBegin(GL_TRIANGLE_FAN);
856 glNormal3d(0.0,0.0,-1.0);
857 glVertex3d(0.0,0.0, z0 );
859 for (j=0; j<=slices; j++)
860 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
864 /* Cover each stack with a quad strip, except the top stack */
866 for( i=0; i<stacks-1; i++ )
868 glBegin(GL_QUAD_STRIP);
870 for(j=0; j<=slices; j++)
872 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
873 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
874 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
877 z0 = z1; z1 += zStep;
878 r0 = r1; r1 -= rStep;
883 /* The top stack is covered with individual triangles */
885 glBegin(GL_TRIANGLES);
887 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
889 for (j=0; j<slices; j++)
891 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
892 glVertex3d(0, 0, height);
893 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
894 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
899 /* Release sin and cos tables */
908 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
912 /* Step in z and radius as stacks are drawn. */
917 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
918 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
920 /* Scaling factors for vertex normals */
922 const double cosn = ( height / sqrt ( height * height + base * base ));
923 const double sinn = ( base / sqrt ( height * height + base * base ));
925 /* Pre-computed circle */
929 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
931 fghCircleTable(&sint,&cost,-slices);
933 /* Draw the stacks... */
935 for (i=0; i<stacks; i++)
937 glBegin(GL_LINE_LOOP);
939 for( j=0; j<slices; j++ )
941 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
942 glVertex3d(cost[j]*r, sint[j]*r, z );
951 /* Draw the slices */
957 for (j=0; j<slices; j++)
959 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
960 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
961 glVertex3d(0.0, 0.0, height);
966 /* Release sin and cos tables */
974 * Draws a solid cylinder
976 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
980 /* Step in z and radius as stacks are drawn. */
983 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
985 /* Pre-computed circle */
989 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
991 fghCircleTable(&sint,&cost,-slices);
993 /* Cover the base and top */
995 glBegin(GL_TRIANGLE_FAN);
996 glNormal3d(0.0, 0.0, -1.0 );
997 glVertex3d(0.0, 0.0, 0.0 );
998 for (j=0; j<=slices; j++)
999 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
1002 glBegin(GL_TRIANGLE_FAN);
1003 glNormal3d(0.0, 0.0, 1.0 );
1004 glVertex3d(0.0, 0.0, height);
1005 for (j=slices; j>=0; j--)
1006 glVertex3d(cost[j]*radius, sint[j]*radius, height);
1014 for (i=1; i<=stacks; i++)
1019 glBegin(GL_QUAD_STRIP);
1020 for (j=0; j<=slices; j++ )
1022 glNormal3d(cost[j], sint[j], 0.0 );
1023 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
1024 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
1028 z0 = z1; z1 += zStep;
1031 /* Release sin and cos tables */
1038 * Draws a wire cylinder
1040 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
1044 /* Step in z and radius as stacks are drawn. */
1047 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
1049 /* Pre-computed circle */
1053 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
1055 fghCircleTable(&sint,&cost,-slices);
1057 /* Draw the stacks... */
1059 for (i=0; i<=stacks; i++)
1064 glBegin(GL_LINE_LOOP);
1066 for( j=0; j<slices; j++ )
1068 glNormal3d(cost[j], sint[j], 0.0);
1069 glVertex3d(cost[j]*radius, sint[j]*radius, z );
1077 /* Draw the slices */
1081 for (j=0; j<slices; j++)
1083 glNormal3d(cost[j], sint[j], 0.0 );
1084 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
1085 glVertex3d(cost[j]*radius, sint[j]*radius, height);
1090 /* Release sin and cos tables */
1097 * Draws a wire torus
1099 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1101 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1102 double *vertex, *normal;
1104 double spsi, cpsi, sphi, cphi ;
1106 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
1108 if ( nSides < 1 ) nSides = 1;
1109 if ( nRings < 1 ) nRings = 1;
1111 /* Allocate the vertices array */
1112 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1113 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1117 dpsi = 2.0 * M_PI / (double)nRings ;
1118 dphi = -2.0 * M_PI / (double)nSides ;
1121 for( j=0; j<nRings; j++ )
1123 cpsi = cos ( psi ) ;
1124 spsi = sin ( psi ) ;
1127 for( i=0; i<nSides; i++ )
1129 int offset = 3 * ( j * nSides + i ) ;
1130 cphi = cos ( phi ) ;
1131 sphi = sin ( phi ) ;
1132 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1133 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1134 *(vertex + offset + 2) = sphi * iradius ;
1135 *(normal + offset + 0) = cpsi * cphi ;
1136 *(normal + offset + 1) = spsi * cphi ;
1137 *(normal + offset + 2) = sphi ;
1144 for( i=0; i<nSides; i++ )
1146 glBegin( GL_LINE_LOOP );
1148 for( j=0; j<nRings; j++ )
1150 int offset = 3 * ( j * nSides + i ) ;
1151 glNormal3dv( normal + offset );
1152 glVertex3dv( vertex + offset );
1158 for( j=0; j<nRings; j++ )
1160 glBegin(GL_LINE_LOOP);
1162 for( i=0; i<nSides; i++ )
1164 int offset = 3 * ( j * nSides + i ) ;
1165 glNormal3dv( normal + offset );
1166 glVertex3dv( vertex + offset );
1178 * Draws a solid torus
1180 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1182 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1183 double *vertex, *normal;
1185 double spsi, cpsi, sphi, cphi ;
1187 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
1189 if ( nSides < 1 ) nSides = 1;
1190 if ( nRings < 1 ) nRings = 1;
1192 /* Increment the number of sides and rings to allow for one more point than surface */
1196 /* Allocate the vertices array */
1197 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1198 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1202 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
1203 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
1206 for( j=0; j<nRings; j++ )
1208 cpsi = cos ( psi ) ;
1209 spsi = sin ( psi ) ;
1212 for( i=0; i<nSides; i++ )
1214 int offset = 3 * ( j * nSides + i ) ;
1215 cphi = cos ( phi ) ;
1216 sphi = sin ( phi ) ;
1217 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1218 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1219 *(vertex + offset + 2) = sphi * iradius ;
1220 *(normal + offset + 0) = cpsi * cphi ;
1221 *(normal + offset + 1) = spsi * cphi ;
1222 *(normal + offset + 2) = sphi ;
1229 glBegin( GL_QUADS );
1230 for( i=0; i<nSides-1; i++ )
1232 for( j=0; j<nRings-1; j++ )
1234 int offset = 3 * ( j * nSides + i ) ;
1235 glNormal3dv( normal + offset );
1236 glVertex3dv( vertex + offset );
1237 glNormal3dv( normal + offset + 3 );
1238 glVertex3dv( vertex + offset + 3 );
1239 glNormal3dv( normal + offset + 3 * nSides + 3 );
1240 glVertex3dv( vertex + offset + 3 * nSides + 3 );
1241 glNormal3dv( normal + offset + 3 * nSides );
1242 glVertex3dv( vertex + offset + 3 * nSides );
1256 void FGAPIENTRY glutWireDodecahedron( void )
1258 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
1260 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1261 * of a cube. The coordinates of the points are:
1262 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1263 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1264 * x = 0.61803398875 and z = 1.61803398875.
1266 glBegin ( GL_LINE_LOOP ) ;
1267 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 ) ;
1269 glBegin ( GL_LINE_LOOP ) ;
1270 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 ) ;
1272 glBegin ( GL_LINE_LOOP ) ;
1273 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 ) ;
1275 glBegin ( GL_LINE_LOOP ) ;
1276 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 ) ;
1279 glBegin ( GL_LINE_LOOP ) ;
1280 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 ) ;
1282 glBegin ( GL_LINE_LOOP ) ;
1283 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 ) ;
1285 glBegin ( GL_LINE_LOOP ) ;
1286 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 ) ;
1288 glBegin ( GL_LINE_LOOP ) ;
1289 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 ) ;
1292 glBegin ( GL_LINE_LOOP ) ;
1293 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 ) ;
1295 glBegin ( GL_LINE_LOOP ) ;
1296 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 ) ;
1298 glBegin ( GL_LINE_LOOP ) ;
1299 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 ) ;
1301 glBegin ( GL_LINE_LOOP ) ;
1302 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 ) ;
1309 void FGAPIENTRY glutSolidDodecahedron( void )
1311 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1313 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1314 * of a cube. The coordinates of the points are:
1315 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1316 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1317 * x = 0.61803398875 and z = 1.61803398875.
1319 glBegin ( GL_POLYGON ) ;
1320 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 ) ;
1322 glBegin ( GL_POLYGON ) ;
1323 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 ) ;
1325 glBegin ( GL_POLYGON ) ;
1326 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 ) ;
1328 glBegin ( GL_POLYGON ) ;
1329 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 ) ;
1332 glBegin ( GL_POLYGON ) ;
1333 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 ) ;
1335 glBegin ( GL_POLYGON ) ;
1336 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 ) ;
1338 glBegin ( GL_POLYGON ) ;
1339 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 ) ;
1341 glBegin ( GL_POLYGON ) ;
1342 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 ) ;
1345 glBegin ( GL_POLYGON ) ;
1346 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 ) ;
1348 glBegin ( GL_POLYGON ) ;
1349 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 ) ;
1351 glBegin ( GL_POLYGON ) ;
1352 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 ) ;
1354 glBegin ( GL_POLYGON ) ;
1355 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 ) ;
1361 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1362 /* Macro to generate interface functions */
1363 #define DECLARE_SHAPE_INTERFACE(nameICaps)\
1364 void FGAPIENTRY glutWire##nameICaps( void )\
1366 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWire"#nameICaps );\
1367 fgh##nameICaps( TRUE );\
1369 void FGAPIENTRY glutSolid##nameICaps( void )\
1371 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolid"#nameICaps );\
1372 fgh##nameICaps( FALSE );\
1375 void FGAPIENTRY glutWireCube( GLdouble dSize )
1377 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1378 fghCube( dSize, TRUE );
1380 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1382 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1383 fghCube( dSize, FALSE );
1386 DECLARE_SHAPE_INTERFACE(Icosahedron);
1387 DECLARE_SHAPE_INTERFACE(Octahedron);
1388 DECLARE_SHAPE_INTERFACE(RhombicDodecahedron);
1390 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1392 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1393 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1395 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1397 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1398 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1401 DECLARE_SHAPE_INTERFACE(Tetrahedron);
1404 /*** END OF FILE ***/