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, GLdouble* vertices, GLdouble* normals, GLsizei numVertices, GLboolean useWireMode)
74 glPushAttrib(GL_POLYGON_BIT);
75 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
80 glEnableClientState(GL_VERTEX_ARRAY);
81 glEnableClientState(GL_NORMAL_ARRAY);
83 glVertexPointer(3, GL_DOUBLE, 0, vertices);
84 glNormalPointer(GL_DOUBLE, 0, normals);
85 glDrawArrays(vertexMode, 0, numVertices);
87 glDisableClientState(GL_VERTEX_ARRAY);
88 glDisableClientState(GL_NORMAL_ARRAY);
94 for(i=0; i<numVertices; i++)
96 glNormal3dv(normals+i*3);
97 printf("n(%i) = (%1.4f,%1.4f,%1.4f)\n",i,*(normals+i*3),*(normals+i*3+1),*(normals+i*3+2));
98 glVertex3dv(vertices+i*3);
99 printf("v(%i) = (%1.4f,%1.4f,%1.4f)\n",i,*(vertices+i*3),*(vertices+i*3+1),*(vertices+i*3+2));
110 static void fghGenerateGeometry(int numFaces, int numVertPerFace, GLdouble *vertices, GLubyte* vertIndices, GLdouble *normals, GLdouble *vertOut, GLdouble *normOut)
114 * Build array with vertices from vertex coordinates and vertex indices
115 * Do same for normals.
116 * Need to do this because of different normals at shared vertices
117 * (and because normals' coordinates need to be negated).
119 for (i=0; i<numFaces; i++)
122 int faceIdxVertIdx = i*numVertPerFace;
123 for (j=0; j<numVertPerFace; j++)
125 int outIdx = i*numVertPerFace*3+j*3;
126 int vertIdx = vertIndices[faceIdxVertIdx+j]*3;
128 vertOut[outIdx ] = vertices[vertIdx ];
129 vertOut[outIdx+1] = vertices[vertIdx+1];
130 vertOut[outIdx+2] = vertices[vertIdx+2];
132 normOut[outIdx ] = normals [normIdx ];
133 normOut[outIdx+1] = normals [normIdx+1];
134 normOut[outIdx+2] = normals [normIdx+2];
140 /* -- INTERNAL SETUP OF GEOMETRY --------------------------------------- */
141 static unsigned int ipow (int x, unsigned int y)
143 return y==0? 1: y==1? x: (y%2? x: 1) * ipow(x*x, y/2);
146 /* -- stuff that can be cached -- */
147 /* Cache of input to glDrawArrays */
148 #define DECLARE_SHAPE_CACHE(name,nameICaps,nameCaps)\
149 static GLboolean name##Cached = FALSE;\
150 static GLdouble name##_verts[nameCaps##_VERT_ELEM_PER_OBJ];\
151 static GLdouble name##_norms[nameCaps##_VERT_ELEM_PER_OBJ];\
152 static void fgh##nameICaps##Generate()\
154 fghGenerateGeometry(nameCaps##_NUM_FACES, nameCaps##_NUM_VERT_PER_FACE,\
155 name##_v, name##_vi, name##_n,\
156 name##_verts, name##_norms);\
159 * In general, we build arrays with all vertices or normals.
160 * We cant compress this and use glDrawElements as all combinations of
161 * vertex and normals are unique.
165 #define CUBE_NUM_VERT 8
166 #define CUBE_NUM_FACES 6
167 #define CUBE_NUM_VERT_PER_FACE 4
168 #define CUBE_VERT_PER_OBJ CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE
169 #define CUBE_VERT_ELEM_PER_OBJ CUBE_VERT_PER_OBJ*3
170 /* Vertex Coordinates */
171 static GLdouble cube_v[CUBE_NUM_VERT*3] =
183 static GLdouble cube_n[CUBE_NUM_FACES*3] =
194 static GLubyte cube_vi[CUBE_VERT_PER_OBJ] =
203 DECLARE_SHAPE_CACHE(cube,Cube,CUBE);
206 #define ICOSAHEDRON_NUM_VERT 12
207 #define ICOSAHEDRON_NUM_FACES 20
208 #define ICOSAHEDRON_NUM_VERT_PER_FACE 3
209 #define ICOSAHEDRON_VERT_PER_OBJ ICOSAHEDRON_NUM_FACES*ICOSAHEDRON_NUM_VERT_PER_FACE
210 #define ICOSAHEDRON_VERT_ELEM_PER_OBJ ICOSAHEDRON_VERT_PER_OBJ*3
211 /* Vertex Coordinates */
212 static GLdouble icosahedron_v[ICOSAHEDRON_NUM_VERT*3] =
215 0.447213595500, 0.894427191000, 0.0 ,
216 0.447213595500, 0.276393202252, 0.850650808354,
217 0.447213595500, -0.723606797748, 0.525731112119,
218 0.447213595500, -0.723606797748, -0.525731112119,
219 0.447213595500, 0.276393202252, -0.850650808354,
220 -0.447213595500, -0.894427191000, 0.0 ,
221 -0.447213595500, -0.276393202252, 0.850650808354,
222 -0.447213595500, 0.723606797748, 0.525731112119,
223 -0.447213595500, 0.723606797748, -0.525731112119,
224 -0.447213595500, -0.276393202252, -0.850650808354,
228 * 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] ) ;
229 * 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] ) ;
230 * 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] ) ;
232 static GLdouble icosahedron_n[ICOSAHEDRON_NUM_FACES*3] =
234 0.760845213037948, 0.470228201835026, 0.341640786498800,
235 0.760845213036861, -0.179611190632978, 0.552786404500000,
236 0.760845213033849, -0.581234022404097, 0,
237 0.760845213036861, -0.179611190632978, -0.552786404500000,
238 0.760845213037948, 0.470228201835026, -0.341640786498800,
239 0.179611190628666, 0.760845213037948, 0.552786404498399,
240 0.179611190634277, -0.290617011204044, 0.894427191000000,
241 0.179611190633958, -0.940456403667806, 0,
242 0.179611190634278, -0.290617011204044, -0.894427191000000,
243 0.179611190628666, 0.760845213037948, -0.552786404498399,
244 -0.179611190633958, 0.940456403667806, 0,
245 -0.179611190634277, 0.290617011204044, 0.894427191000000,
246 -0.179611190628666, -0.760845213037948, 0.552786404498399,
247 -0.179611190628666, -0.760845213037948, -0.552786404498399,
248 -0.179611190634277, 0.290617011204044, -0.894427191000000,
249 -0.760845213036861, 0.179611190632978, -0.552786404500000,
250 -0.760845213033849, 0.581234022404097, 0,
251 -0.760845213036861, 0.179611190632978, 0.552786404500000,
252 -0.760845213037948, -0.470228201835026, 0.341640786498800,
253 -0.760845213037948, -0.470228201835026, -0.341640786498800,
257 static GLubyte icosahedron_vi[ICOSAHEDRON_VERT_PER_OBJ] =
280 DECLARE_SHAPE_CACHE(icosahedron,Icosahedron,ICOSAHEDRON);
282 /* -- Octahedron -- */
283 #define OCTAHEDRON_NUM_VERT 6
284 #define OCTAHEDRON_NUM_FACES 8
285 #define OCTAHEDRON_NUM_VERT_PER_FACE 3
286 #define OCTAHEDRON_VERT_PER_OBJ OCTAHEDRON_NUM_FACES*OCTAHEDRON_NUM_VERT_PER_FACE
287 #define OCTAHEDRON_VERT_ELEM_PER_OBJ OCTAHEDRON_VERT_PER_OBJ*3
289 /* Vertex Coordinates */
290 static GLdouble octahedron_v[OCTAHEDRON_NUM_VERT*3] =
301 static GLdouble octahedron_n[OCTAHEDRON_NUM_FACES*3] =
303 0.577350269189, 0.577350269189, 0.577350269189, /* sqrt(1/3) */
304 0.577350269189, 0.577350269189,-0.577350269189,
305 0.577350269189,-0.577350269189, 0.577350269189,
306 0.577350269189,-0.577350269189,-0.577350269189,
307 -0.577350269189, 0.577350269189, 0.577350269189,
308 -0.577350269189, 0.577350269189,-0.577350269189,
309 -0.577350269189,-0.577350269189, 0.577350269189,
310 -0.577350269189,-0.577350269189,-0.577350269189
315 static GLubyte octahedron_vi[OCTAHEDRON_VERT_PER_OBJ] =
326 DECLARE_SHAPE_CACHE(octahedron,Octahedron,OCTAHEDRON);
328 /* -- RhombicDodecahedron -- */
329 #define RHOMBICDODECAHEDRON_NUM_VERT 14
330 #define RHOMBICDODECAHEDRON_NUM_FACES 12
331 #define RHOMBICDODECAHEDRON_NUM_VERT_PER_FACE 4
332 #define RHOMBICDODECAHEDRON_VERT_PER_OBJ RHOMBICDODECAHEDRON_NUM_FACES*RHOMBICDODECAHEDRON_NUM_VERT_PER_FACE
333 #define RHOMBICDODECAHEDRON_VERT_ELEM_PER_OBJ RHOMBICDODECAHEDRON_VERT_PER_OBJ*3
335 /* Vertex Coordinates */
336 static GLdouble rhombicdodecahedron_v[RHOMBICDODECAHEDRON_NUM_VERT*3] =
339 0.707106781187, 0.0 , 0.5,
340 0.0 , 0.707106781187, 0.5,
341 -0.707106781187, 0.0 , 0.5,
342 0.0 , -0.707106781187, 0.5,
343 0.707106781187, 0.707106781187, 0.0,
344 -0.707106781187, 0.707106781187, 0.0,
345 -0.707106781187, -0.707106781187, 0.0,
346 0.707106781187, -0.707106781187, 0.0,
347 0.707106781187, 0.0 , -0.5,
348 0.0 , 0.707106781187, -0.5,
349 -0.707106781187, 0.0 , -0.5,
350 0.0 , -0.707106781187, -0.5,
354 static GLdouble rhombicdodecahedron_n[RHOMBICDODECAHEDRON_NUM_FACES*3] =
356 0.353553390594, 0.353553390594, 0.5,
357 -0.353553390594, 0.353553390594, 0.5,
358 -0.353553390594, -0.353553390594, 0.5,
359 0.353553390594, -0.353553390594, 0.5,
364 0.353553390594, 0.353553390594, -0.5,
365 -0.353553390594, 0.353553390594, -0.5,
366 -0.353553390594, -0.353553390594, -0.5,
367 0.353553390594, -0.353553390594, -0.5
371 static GLubyte rhombicdodecahedron_vi[RHOMBICDODECAHEDRON_VERT_PER_OBJ] =
386 DECLARE_SHAPE_CACHE(rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
388 /* -- Tetrahedron -- */
389 /* Magic Numbers: r0 = ( 1, 0, 0 )
390 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
391 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
392 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
393 * |r0| = |r1| = |r2| = |r3| = 1
394 * Distance between any two points is 2 sqrt(6) / 3
396 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
398 #define TETRAHEDRON_NUM_VERT 4
399 #define TETRAHEDRON_NUM_FACES 4
400 #define TETRAHEDRON_NUM_VERT_PER_FACE 3
401 #define TETRAHEDRON_VERT_PER_OBJ TETRAHEDRON_NUM_FACES*TETRAHEDRON_NUM_VERT_PER_FACE
402 #define TETRAHEDRON_VERT_ELEM_PER_OBJ TETRAHEDRON_VERT_PER_OBJ*3
404 /* Vertex Coordinates */
405 static GLdouble tetrahedron_v[TETRAHEDRON_NUM_VERT*3] =
408 -0.333333333333, 0.942809041582, 0.0,
409 -0.333333333333, -0.471404520791, 0.816496580928,
410 -0.333333333333, -0.471404520791, -0.816496580928
413 static GLdouble tetrahedron_n[TETRAHEDRON_NUM_FACES*3] =
416 0.333333333333, -0.942809041582, 0.0,
417 0.333333333333, 0.471404520791, -0.816496580928,
418 0.333333333333, 0.471404520791, 0.816496580928
422 static GLubyte tetrahedron_vi[TETRAHEDRON_VERT_PER_OBJ] =
429 DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON);
431 /* -- Sierpinski Sponge -- */
432 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, GLdouble* vertices, GLdouble* normals )
435 if ( numLevels == 0 )
437 for (i=0; i<TETRAHEDRON_NUM_FACES; i++)
440 int faceIdxVertIdx = i*TETRAHEDRON_NUM_VERT_PER_FACE;
441 for (j=0; j<TETRAHEDRON_NUM_VERT_PER_FACE; j++)
443 int outIdx = i*TETRAHEDRON_NUM_VERT_PER_FACE*3+j*3;
444 int vertIdx = tetrahedron_vi[faceIdxVertIdx+j]*3;
446 vertices[outIdx ] = offset[0] + scale * tetrahedron_v[vertIdx ];
447 vertices[outIdx+1] = offset[1] + scale * tetrahedron_v[vertIdx+1];
448 vertices[outIdx+2] = offset[2] + scale * tetrahedron_v[vertIdx+2];
450 normals [outIdx ] = tetrahedron_n[normIdx ];
451 normals [outIdx+1] = tetrahedron_n[normIdx+1];
452 normals [outIdx+2] = tetrahedron_n[normIdx+2];
456 else if ( numLevels > 0 )
458 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
459 unsigned int stride = ipow(4,--numLevels)*TETRAHEDRON_VERT_ELEM_PER_OBJ;
461 for ( i = 0 ; i < TETRAHEDRON_NUM_FACES ; i++ )
464 local_offset[0] = offset[0] + scale * tetrahedron_v[idx ];
465 local_offset[1] = offset[1] + scale * tetrahedron_v[idx+1];
466 local_offset[2] = offset[2] + scale * tetrahedron_v[idx+2];
467 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
472 /* -- Now the various shapes involving circles -- */
474 * Compute lookup table of cos and sin values forming a cirle
477 * It is the responsibility of the caller to free these tables
478 * The size of the table is (n+1) to form a connected loop
479 * The last entry is exactly the same as the first
480 * The sign of n can be flipped to get the reverse loop
482 static void fghCircleTable(double **sint,double **cost,const int n)
486 /* Table size, the sign of n flips the circle direction */
488 const int size = abs(n);
490 /* Determine the angle between samples */
492 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
494 /* Allocate memory for n samples, plus duplicate of first entry at the end */
496 *sint = (double *) calloc(sizeof(double), size+1);
497 *cost = (double *) calloc(sizeof(double), size+1);
499 /* Bail out if memory allocation fails, fgError never returns */
501 if (!(*sint) || !(*cost))
505 fgError("Failed to allocate memory in fghCircleTable");
508 /* Compute cos and sin around the circle */
513 for (i=1; i<size; i++)
515 (*sint)[i] = sin(angle*i);
516 (*cost)[i] = cos(angle*i);
519 /* Last sample is duplicate of the first */
521 (*sint)[size] = (*sint)[0];
522 (*cost)[size] = (*cost)[0];
526 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
527 #define DECLARE_INTERNAL_DRAW(vertexMode,name,nameICaps,nameCaps)\
528 static void fgh##nameICaps( GLboolean useWireMode )\
532 fgh##nameICaps##Generate();\
533 name##Cached = TRUE;\
535 fghDrawGeometry(vertexMode,name##_verts,name##_norms,nameCaps##_VERT_PER_OBJ,useWireMode);\
538 static void fghCube( GLdouble dSize, GLboolean useWireMode )
550 /* Need to build new vertex list containing vertices for cube of different size */
551 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_OBJ * sizeof(GLdouble));
552 for (i=0; i<CUBE_VERT_ELEM_PER_OBJ; i++)
553 vertices[i] = dSize*cube_verts[i];
555 fghDrawGeometry(GL_QUADS,vertices ,cube_norms,CUBE_VERT_PER_OBJ,useWireMode);
558 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_OBJ,useWireMode);
561 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,icosahedron,Icosahedron,ICOSAHEDRON);
562 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,octahedron,Octahedron,OCTAHEDRON);
563 DECLARE_INTERNAL_DRAW(GL_QUADS,rhombicdodecahedron,RhombicDodecahedron,RHOMBICDODECAHEDRON);
564 DECLARE_INTERNAL_DRAW(GL_TRIANGLES,tetrahedron,Tetrahedron,TETRAHEDRON);
566 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
570 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
571 GLsizei numVert = numTetr*TETRAHEDRON_VERT_PER_OBJ;
575 /* Allocate memory */
576 vertices = malloc(numVert*3 * sizeof(GLdouble));
577 normals = malloc(numVert*3 * sizeof(GLdouble));
579 /* Generate elements */
580 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
582 /* Draw and cleanup */
583 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
590 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
594 * Draws a solid sphere
596 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
600 /* Adjust z and radius as stacks are drawn. */
605 /* Pre-computed circle */
607 double *sint1,*cost1;
608 double *sint2,*cost2;
610 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
612 fghCircleTable(&sint1,&cost1,-slices);
613 fghCircleTable(&sint2,&cost2,stacks*2);
615 /* The top stack is covered with a triangle fan */
618 z1 = cost2[(stacks>0)?1:0];
620 r1 = sint2[(stacks>0)?1:0];
622 glBegin(GL_TRIANGLE_FAN);
625 glVertex3d(0,0,radius);
627 for (j=slices; j>=0; j--)
629 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
630 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
635 /* Cover each stack with a quad strip, except the top and bottom stacks */
637 for( i=1; i<stacks-1; i++ )
639 z0 = z1; z1 = cost2[i+1];
640 r0 = r1; r1 = sint2[i+1];
642 glBegin(GL_QUAD_STRIP);
644 for(j=0; j<=slices; j++)
646 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
647 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
648 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
649 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
655 /* The bottom stack is covered with a triangle fan */
660 glBegin(GL_TRIANGLE_FAN);
663 glVertex3d(0,0,-radius);
665 for (j=0; j<=slices; j++)
667 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
668 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
673 /* Release sin and cos tables */
682 * Draws a wire sphere
684 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
688 /* Adjust z and radius as stacks and slices are drawn. */
693 /* Pre-computed circle */
695 double *sint1,*cost1;
696 double *sint2,*cost2;
698 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
700 fghCircleTable(&sint1,&cost1,-slices );
701 fghCircleTable(&sint2,&cost2, stacks*2);
703 /* Draw a line loop for each stack */
705 for (i=1; i<stacks; i++)
710 glBegin(GL_LINE_LOOP);
712 for(j=0; j<=slices; j++)
718 glVertex3d(x*r*radius,y*r*radius,z*radius);
724 /* Draw a line loop for each slice */
726 for (i=0; i<slices; i++)
728 glBegin(GL_LINE_STRIP);
730 for(j=0; j<=stacks; j++)
732 x = cost1[i]*sint2[j];
733 y = sint1[i]*sint2[j];
737 glVertex3d(x*radius,y*radius,z*radius);
743 /* Release sin and cos tables */
754 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
758 /* Step in z and radius as stacks are drawn. */
763 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
764 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
766 /* Scaling factors for vertex normals */
768 const double cosn = ( height / sqrt ( height * height + base * base ));
769 const double sinn = ( base / sqrt ( height * height + base * base ));
771 /* Pre-computed circle */
775 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
777 fghCircleTable(&sint,&cost,-slices);
779 /* Cover the circular base with a triangle fan... */
787 glBegin(GL_TRIANGLE_FAN);
789 glNormal3d(0.0,0.0,-1.0);
790 glVertex3d(0.0,0.0, z0 );
792 for (j=0; j<=slices; j++)
793 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
797 /* Cover each stack with a quad strip, except the top stack */
799 for( i=0; i<stacks-1; i++ )
801 glBegin(GL_QUAD_STRIP);
803 for(j=0; j<=slices; j++)
805 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
806 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
807 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
810 z0 = z1; z1 += zStep;
811 r0 = r1; r1 -= rStep;
816 /* The top stack is covered with individual triangles */
818 glBegin(GL_TRIANGLES);
820 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
822 for (j=0; j<slices; j++)
824 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
825 glVertex3d(0, 0, height);
826 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
827 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
832 /* Release sin and cos tables */
841 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
845 /* Step in z and radius as stacks are drawn. */
850 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
851 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
853 /* Scaling factors for vertex normals */
855 const double cosn = ( height / sqrt ( height * height + base * base ));
856 const double sinn = ( base / sqrt ( height * height + base * base ));
858 /* Pre-computed circle */
862 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
864 fghCircleTable(&sint,&cost,-slices);
866 /* Draw the stacks... */
868 for (i=0; i<stacks; i++)
870 glBegin(GL_LINE_LOOP);
872 for( j=0; j<slices; j++ )
874 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
875 glVertex3d(cost[j]*r, sint[j]*r, z );
884 /* Draw the slices */
890 for (j=0; j<slices; j++)
892 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
893 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
894 glVertex3d(0.0, 0.0, height);
899 /* Release sin and cos tables */
907 * Draws a solid cylinder
909 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
913 /* Step in z and radius as stacks are drawn. */
916 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
918 /* Pre-computed circle */
922 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
924 fghCircleTable(&sint,&cost,-slices);
926 /* Cover the base and top */
928 glBegin(GL_TRIANGLE_FAN);
929 glNormal3d(0.0, 0.0, -1.0 );
930 glVertex3d(0.0, 0.0, 0.0 );
931 for (j=0; j<=slices; j++)
932 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
935 glBegin(GL_TRIANGLE_FAN);
936 glNormal3d(0.0, 0.0, 1.0 );
937 glVertex3d(0.0, 0.0, height);
938 for (j=slices; j>=0; j--)
939 glVertex3d(cost[j]*radius, sint[j]*radius, height);
947 for (i=1; i<=stacks; i++)
952 glBegin(GL_QUAD_STRIP);
953 for (j=0; j<=slices; j++ )
955 glNormal3d(cost[j], sint[j], 0.0 );
956 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
957 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
961 z0 = z1; z1 += zStep;
964 /* Release sin and cos tables */
971 * Draws a wire cylinder
973 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
977 /* Step in z and radius as stacks are drawn. */
980 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
982 /* Pre-computed circle */
986 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
988 fghCircleTable(&sint,&cost,-slices);
990 /* Draw the stacks... */
992 for (i=0; i<=stacks; i++)
997 glBegin(GL_LINE_LOOP);
999 for( j=0; j<slices; j++ )
1001 glNormal3d(cost[j], sint[j], 0.0);
1002 glVertex3d(cost[j]*radius, sint[j]*radius, z );
1010 /* Draw the slices */
1014 for (j=0; j<slices; j++)
1016 glNormal3d(cost[j], sint[j], 0.0 );
1017 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
1018 glVertex3d(cost[j]*radius, sint[j]*radius, height);
1023 /* Release sin and cos tables */
1030 * Draws a wire torus
1032 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1034 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1035 double *vertex, *normal;
1037 double spsi, cpsi, sphi, cphi ;
1039 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
1041 if ( nSides < 1 ) nSides = 1;
1042 if ( nRings < 1 ) nRings = 1;
1044 /* Allocate the vertices array */
1045 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1046 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1050 dpsi = 2.0 * M_PI / (double)nRings ;
1051 dphi = -2.0 * M_PI / (double)nSides ;
1054 for( j=0; j<nRings; j++ )
1056 cpsi = cos ( psi ) ;
1057 spsi = sin ( psi ) ;
1060 for( i=0; i<nSides; i++ )
1062 int offset = 3 * ( j * nSides + i ) ;
1063 cphi = cos ( phi ) ;
1064 sphi = sin ( phi ) ;
1065 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1066 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1067 *(vertex + offset + 2) = sphi * iradius ;
1068 *(normal + offset + 0) = cpsi * cphi ;
1069 *(normal + offset + 1) = spsi * cphi ;
1070 *(normal + offset + 2) = sphi ;
1077 for( i=0; i<nSides; i++ )
1079 glBegin( GL_LINE_LOOP );
1081 for( j=0; j<nRings; j++ )
1083 int offset = 3 * ( j * nSides + i ) ;
1084 glNormal3dv( normal + offset );
1085 glVertex3dv( vertex + offset );
1091 for( j=0; j<nRings; j++ )
1093 glBegin(GL_LINE_LOOP);
1095 for( i=0; i<nSides; i++ )
1097 int offset = 3 * ( j * nSides + i ) ;
1098 glNormal3dv( normal + offset );
1099 glVertex3dv( vertex + offset );
1111 * Draws a solid torus
1113 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1115 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1116 double *vertex, *normal;
1118 double spsi, cpsi, sphi, cphi ;
1120 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
1122 if ( nSides < 1 ) nSides = 1;
1123 if ( nRings < 1 ) nRings = 1;
1125 /* Increment the number of sides and rings to allow for one more point than surface */
1129 /* Allocate the vertices array */
1130 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1131 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1135 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
1136 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
1139 for( j=0; j<nRings; j++ )
1141 cpsi = cos ( psi ) ;
1142 spsi = sin ( psi ) ;
1145 for( i=0; i<nSides; i++ )
1147 int offset = 3 * ( j * nSides + i ) ;
1148 cphi = cos ( phi ) ;
1149 sphi = sin ( phi ) ;
1150 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1151 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1152 *(vertex + offset + 2) = sphi * iradius ;
1153 *(normal + offset + 0) = cpsi * cphi ;
1154 *(normal + offset + 1) = spsi * cphi ;
1155 *(normal + offset + 2) = sphi ;
1162 glBegin( GL_QUADS );
1163 for( i=0; i<nSides-1; i++ )
1165 for( j=0; j<nRings-1; j++ )
1167 int offset = 3 * ( j * nSides + i ) ;
1168 glNormal3dv( normal + offset );
1169 glVertex3dv( vertex + offset );
1170 glNormal3dv( normal + offset + 3 );
1171 glVertex3dv( vertex + offset + 3 );
1172 glNormal3dv( normal + offset + 3 * nSides + 3 );
1173 glVertex3dv( vertex + offset + 3 * nSides + 3 );
1174 glNormal3dv( normal + offset + 3 * nSides );
1175 glVertex3dv( vertex + offset + 3 * nSides );
1189 void FGAPIENTRY glutWireDodecahedron( void )
1191 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
1193 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1194 * of a cube. The coordinates of the points are:
1195 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1196 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1197 * x = 0.61803398875 and z = 1.61803398875.
1199 glBegin ( GL_LINE_LOOP ) ;
1200 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 ) ;
1202 glBegin ( GL_LINE_LOOP ) ;
1203 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 ) ;
1205 glBegin ( GL_LINE_LOOP ) ;
1206 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 ) ;
1208 glBegin ( GL_LINE_LOOP ) ;
1209 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 ) ;
1212 glBegin ( GL_LINE_LOOP ) ;
1213 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 ) ;
1215 glBegin ( GL_LINE_LOOP ) ;
1216 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 ) ;
1218 glBegin ( GL_LINE_LOOP ) ;
1219 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 ) ;
1221 glBegin ( GL_LINE_LOOP ) ;
1222 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 ) ;
1225 glBegin ( GL_LINE_LOOP ) ;
1226 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 ) ;
1228 glBegin ( GL_LINE_LOOP ) ;
1229 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 ) ;
1231 glBegin ( GL_LINE_LOOP ) ;
1232 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 ) ;
1234 glBegin ( GL_LINE_LOOP ) ;
1235 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 ) ;
1242 void FGAPIENTRY glutSolidDodecahedron( void )
1244 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1246 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1247 * of a cube. The coordinates of the points are:
1248 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1249 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1250 * x = 0.61803398875 and z = 1.61803398875.
1252 glBegin ( GL_POLYGON ) ;
1253 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 ) ;
1255 glBegin ( GL_POLYGON ) ;
1256 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 ) ;
1258 glBegin ( GL_POLYGON ) ;
1259 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 ) ;
1261 glBegin ( GL_POLYGON ) ;
1262 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 ) ;
1265 glBegin ( GL_POLYGON ) ;
1266 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 ) ;
1268 glBegin ( GL_POLYGON ) ;
1269 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 ) ;
1271 glBegin ( GL_POLYGON ) ;
1272 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 ) ;
1274 glBegin ( GL_POLYGON ) ;
1275 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 ) ;
1278 glBegin ( GL_POLYGON ) ;
1279 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 ) ;
1281 glBegin ( GL_POLYGON ) ;
1282 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 ) ;
1284 glBegin ( GL_POLYGON ) ;
1285 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 ) ;
1287 glBegin ( GL_POLYGON ) ;
1288 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 ) ;
1294 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1295 /* Macro to generate interface functions */
1296 #define DECLARE_SHAPE_INTERFACE(nameICaps)\
1297 void FGAPIENTRY glutWire##nameICaps( void )\
1299 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWire"#nameICaps );\
1300 fgh##nameICaps( TRUE );\
1302 void FGAPIENTRY glutSolid##nameICaps( void )\
1304 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolid"#nameICaps );\
1305 fgh##nameICaps( FALSE );\
1308 void FGAPIENTRY glutWireCube( GLdouble dSize )
1310 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1311 fghCube( dSize, TRUE );
1313 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1315 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1316 fghCube( dSize, FALSE );
1319 DECLARE_SHAPE_INTERFACE(Icosahedron);
1320 DECLARE_SHAPE_INTERFACE(Octahedron);
1321 DECLARE_SHAPE_INTERFACE(RhombicDodecahedron);
1323 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1325 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1326 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1328 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1330 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1331 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1334 DECLARE_SHAPE_INTERFACE(Tetrahedron);
1337 /*** END OF FILE ***/