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 /* -- Tetrahedron -- */
329 /* Magic Numbers: r0 = ( 1, 0, 0 )
330 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
331 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
332 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
333 * |r0| = |r1| = |r2| = |r3| = 1
334 * Distance between any two points is 2 sqrt(6) / 3
336 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
338 #define TETRAHEDRON_NUM_VERT 4
339 #define TETRAHEDRON_NUM_FACES 4
340 #define TETRAHEDRON_NUM_VERT_PER_FACE 3
341 #define TETRAHEDRON_VERT_PER_OBJ TETRAHEDRON_NUM_FACES*TETRAHEDRON_NUM_VERT_PER_FACE
342 #define TETRAHEDRON_VERT_ELEM_PER_OBJ TETRAHEDRON_VERT_PER_OBJ*3
344 /* Vertex Coordinates */
345 static GLdouble tetrahedron_v[TETRAHEDRON_NUM_VERT*3] =
348 -0.333333333333, 0.942809041582, 0.0,
349 -0.333333333333, -0.471404520791, 0.816496580928,
350 -0.333333333333, -0.471404520791, -0.816496580928
353 static GLdouble tetrahedron_n[TETRAHEDRON_NUM_FACES*3] =
356 0.333333333333, -0.942809041582, 0.0,
357 0.333333333333, 0.471404520791, -0.816496580928,
358 0.333333333333, 0.471404520791, 0.816496580928
362 static GLubyte tetrahedron_vi[TETRAHEDRON_VERT_PER_OBJ] =
369 DECLARE_SHAPE_CACHE(tetrahedron,Tetrahedron,TETRAHEDRON);
371 /* -- Sierpinski Sponge -- */
372 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, GLdouble* vertices, GLdouble* normals )
375 if ( numLevels == 0 )
377 for (i=0; i<TETRAHEDRON_NUM_FACES; i++)
380 int faceIdxVertIdx = i*TETRAHEDRON_NUM_VERT_PER_FACE;
381 for (j=0; j<TETRAHEDRON_NUM_VERT_PER_FACE; j++)
383 int outIdx = i*TETRAHEDRON_NUM_VERT_PER_FACE*3+j*3;
384 int vertIdx = tetrahedron_vi[faceIdxVertIdx+j]*3;
386 vertices[outIdx ] = offset[0] + scale * tetrahedron_v[vertIdx ];
387 vertices[outIdx+1] = offset[1] + scale * tetrahedron_v[vertIdx+1];
388 vertices[outIdx+2] = offset[2] + scale * tetrahedron_v[vertIdx+2];
390 normals [outIdx ] = tetrahedron_n[normIdx ];
391 normals [outIdx+1] = tetrahedron_n[normIdx+1];
392 normals [outIdx+2] = tetrahedron_n[normIdx+2];
396 else if ( numLevels > 0 )
398 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
399 unsigned int stride = ipow(4,--numLevels)*TETRAHEDRON_VERT_ELEM_PER_OBJ;
401 for ( i = 0 ; i < TETRAHEDRON_NUM_FACES ; i++ )
404 local_offset[0] = offset[0] + scale * tetrahedron_v[idx ];
405 local_offset[1] = offset[1] + scale * tetrahedron_v[idx+1];
406 local_offset[2] = offset[2] + scale * tetrahedron_v[idx+2];
407 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
412 /* -- Now the various shapes involving circles -- */
414 * Compute lookup table of cos and sin values forming a cirle
417 * It is the responsibility of the caller to free these tables
418 * The size of the table is (n+1) to form a connected loop
419 * The last entry is exactly the same as the first
420 * The sign of n can be flipped to get the reverse loop
422 static void fghCircleTable(double **sint,double **cost,const int n)
426 /* Table size, the sign of n flips the circle direction */
428 const int size = abs(n);
430 /* Determine the angle between samples */
432 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
434 /* Allocate memory for n samples, plus duplicate of first entry at the end */
436 *sint = (double *) calloc(sizeof(double), size+1);
437 *cost = (double *) calloc(sizeof(double), size+1);
439 /* Bail out if memory allocation fails, fgError never returns */
441 if (!(*sint) || !(*cost))
445 fgError("Failed to allocate memory in fghCircleTable");
448 /* Compute cos and sin around the circle */
453 for (i=1; i<size; i++)
455 (*sint)[i] = sin(angle*i);
456 (*cost)[i] = cos(angle*i);
459 /* Last sample is duplicate of the first */
461 (*sint)[size] = (*sint)[0];
462 (*cost)[size] = (*cost)[0];
466 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
467 #define DECLARE_INTERNAL_DRAW(name,nameICaps,nameCaps)\
468 static void fgh##nameICaps( GLboolean useWireMode )\
472 fgh##nameICaps##Generate();\
473 name##Cached = TRUE;\
475 fghDrawGeometry(GL_TRIANGLES,name##_verts,name##_norms,nameCaps##_VERT_PER_OBJ,useWireMode);\
478 static void fghCube( GLdouble dSize, GLboolean useWireMode )
490 /* Need to build new vertex list containing vertices for cube of different size */
491 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_OBJ * sizeof(GLdouble));
492 for (i=0; i<CUBE_VERT_ELEM_PER_OBJ; i++)
493 vertices[i] = dSize*cube_verts[i];
495 fghDrawGeometry(GL_QUADS,vertices ,cube_norms,CUBE_VERT_PER_OBJ,useWireMode);
498 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_OBJ,useWireMode);
500 DECLARE_INTERNAL_DRAW(icosahedron,Icosahedron,ICOSAHEDRON);
501 DECLARE_INTERNAL_DRAW(octahedron,Octahedron,OCTAHEDRON);
502 DECLARE_INTERNAL_DRAW(tetrahedron,Tetrahedron,TETRAHEDRON);
504 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
508 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
509 GLsizei numVert = numTetr*TETRAHEDRON_VERT_PER_OBJ;
513 /* Allocate memory */
514 vertices = malloc(numVert*3 * sizeof(GLdouble));
515 normals = malloc(numVert*3 * sizeof(GLdouble));
517 /* Generate elements */
518 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
520 /* Draw and cleanup */
521 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
528 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
532 * Draws a solid sphere
534 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
538 /* Adjust z and radius as stacks are drawn. */
543 /* Pre-computed circle */
545 double *sint1,*cost1;
546 double *sint2,*cost2;
548 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
550 fghCircleTable(&sint1,&cost1,-slices);
551 fghCircleTable(&sint2,&cost2,stacks*2);
553 /* The top stack is covered with a triangle fan */
556 z1 = cost2[(stacks>0)?1:0];
558 r1 = sint2[(stacks>0)?1:0];
560 glBegin(GL_TRIANGLE_FAN);
563 glVertex3d(0,0,radius);
565 for (j=slices; j>=0; j--)
567 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
568 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
573 /* Cover each stack with a quad strip, except the top and bottom stacks */
575 for( i=1; i<stacks-1; i++ )
577 z0 = z1; z1 = cost2[i+1];
578 r0 = r1; r1 = sint2[i+1];
580 glBegin(GL_QUAD_STRIP);
582 for(j=0; j<=slices; j++)
584 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
585 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
586 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
587 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
593 /* The bottom stack is covered with a triangle fan */
598 glBegin(GL_TRIANGLE_FAN);
601 glVertex3d(0,0,-radius);
603 for (j=0; j<=slices; j++)
605 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
606 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
611 /* Release sin and cos tables */
620 * Draws a wire sphere
622 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
626 /* Adjust z and radius as stacks and slices are drawn. */
631 /* Pre-computed circle */
633 double *sint1,*cost1;
634 double *sint2,*cost2;
636 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
638 fghCircleTable(&sint1,&cost1,-slices );
639 fghCircleTable(&sint2,&cost2, stacks*2);
641 /* Draw a line loop for each stack */
643 for (i=1; i<stacks; i++)
648 glBegin(GL_LINE_LOOP);
650 for(j=0; j<=slices; j++)
656 glVertex3d(x*r*radius,y*r*radius,z*radius);
662 /* Draw a line loop for each slice */
664 for (i=0; i<slices; i++)
666 glBegin(GL_LINE_STRIP);
668 for(j=0; j<=stacks; j++)
670 x = cost1[i]*sint2[j];
671 y = sint1[i]*sint2[j];
675 glVertex3d(x*radius,y*radius,z*radius);
681 /* Release sin and cos tables */
692 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
696 /* Step in z and radius as stacks are drawn. */
701 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
702 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
704 /* Scaling factors for vertex normals */
706 const double cosn = ( height / sqrt ( height * height + base * base ));
707 const double sinn = ( base / sqrt ( height * height + base * base ));
709 /* Pre-computed circle */
713 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
715 fghCircleTable(&sint,&cost,-slices);
717 /* Cover the circular base with a triangle fan... */
725 glBegin(GL_TRIANGLE_FAN);
727 glNormal3d(0.0,0.0,-1.0);
728 glVertex3d(0.0,0.0, z0 );
730 for (j=0; j<=slices; j++)
731 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
735 /* Cover each stack with a quad strip, except the top stack */
737 for( i=0; i<stacks-1; i++ )
739 glBegin(GL_QUAD_STRIP);
741 for(j=0; j<=slices; j++)
743 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
744 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
745 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
748 z0 = z1; z1 += zStep;
749 r0 = r1; r1 -= rStep;
754 /* The top stack is covered with individual triangles */
756 glBegin(GL_TRIANGLES);
758 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
760 for (j=0; j<slices; j++)
762 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
763 glVertex3d(0, 0, height);
764 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
765 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
770 /* Release sin and cos tables */
779 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
783 /* Step in z and radius as stacks are drawn. */
788 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
789 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
791 /* Scaling factors for vertex normals */
793 const double cosn = ( height / sqrt ( height * height + base * base ));
794 const double sinn = ( base / sqrt ( height * height + base * base ));
796 /* Pre-computed circle */
800 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
802 fghCircleTable(&sint,&cost,-slices);
804 /* Draw the stacks... */
806 for (i=0; i<stacks; i++)
808 glBegin(GL_LINE_LOOP);
810 for( j=0; j<slices; j++ )
812 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
813 glVertex3d(cost[j]*r, sint[j]*r, z );
822 /* Draw the slices */
828 for (j=0; j<slices; j++)
830 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
831 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
832 glVertex3d(0.0, 0.0, height);
837 /* Release sin and cos tables */
845 * Draws a solid cylinder
847 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
851 /* Step in z and radius as stacks are drawn. */
854 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
856 /* Pre-computed circle */
860 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
862 fghCircleTable(&sint,&cost,-slices);
864 /* Cover the base and top */
866 glBegin(GL_TRIANGLE_FAN);
867 glNormal3d(0.0, 0.0, -1.0 );
868 glVertex3d(0.0, 0.0, 0.0 );
869 for (j=0; j<=slices; j++)
870 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
873 glBegin(GL_TRIANGLE_FAN);
874 glNormal3d(0.0, 0.0, 1.0 );
875 glVertex3d(0.0, 0.0, height);
876 for (j=slices; j>=0; j--)
877 glVertex3d(cost[j]*radius, sint[j]*radius, height);
885 for (i=1; i<=stacks; i++)
890 glBegin(GL_QUAD_STRIP);
891 for (j=0; j<=slices; j++ )
893 glNormal3d(cost[j], sint[j], 0.0 );
894 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
895 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
899 z0 = z1; z1 += zStep;
902 /* Release sin and cos tables */
909 * Draws a wire cylinder
911 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
915 /* Step in z and radius as stacks are drawn. */
918 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
920 /* Pre-computed circle */
924 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
926 fghCircleTable(&sint,&cost,-slices);
928 /* Draw the stacks... */
930 for (i=0; i<=stacks; i++)
935 glBegin(GL_LINE_LOOP);
937 for( j=0; j<slices; j++ )
939 glNormal3d(cost[j], sint[j], 0.0);
940 glVertex3d(cost[j]*radius, sint[j]*radius, z );
948 /* Draw the slices */
952 for (j=0; j<slices; j++)
954 glNormal3d(cost[j], sint[j], 0.0 );
955 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
956 glVertex3d(cost[j]*radius, sint[j]*radius, height);
961 /* Release sin and cos tables */
970 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
972 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
973 double *vertex, *normal;
975 double spsi, cpsi, sphi, cphi ;
977 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
979 if ( nSides < 1 ) nSides = 1;
980 if ( nRings < 1 ) nRings = 1;
982 /* Allocate the vertices array */
983 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
984 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
988 dpsi = 2.0 * M_PI / (double)nRings ;
989 dphi = -2.0 * M_PI / (double)nSides ;
992 for( j=0; j<nRings; j++ )
998 for( i=0; i<nSides; i++ )
1000 int offset = 3 * ( j * nSides + i ) ;
1001 cphi = cos ( phi ) ;
1002 sphi = sin ( phi ) ;
1003 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1004 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1005 *(vertex + offset + 2) = sphi * iradius ;
1006 *(normal + offset + 0) = cpsi * cphi ;
1007 *(normal + offset + 1) = spsi * cphi ;
1008 *(normal + offset + 2) = sphi ;
1015 for( i=0; i<nSides; i++ )
1017 glBegin( GL_LINE_LOOP );
1019 for( j=0; j<nRings; j++ )
1021 int offset = 3 * ( j * nSides + i ) ;
1022 glNormal3dv( normal + offset );
1023 glVertex3dv( vertex + offset );
1029 for( j=0; j<nRings; j++ )
1031 glBegin(GL_LINE_LOOP);
1033 for( i=0; i<nSides; i++ )
1035 int offset = 3 * ( j * nSides + i ) ;
1036 glNormal3dv( normal + offset );
1037 glVertex3dv( vertex + offset );
1049 * Draws a solid torus
1051 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1053 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1054 double *vertex, *normal;
1056 double spsi, cpsi, sphi, cphi ;
1058 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
1060 if ( nSides < 1 ) nSides = 1;
1061 if ( nRings < 1 ) nRings = 1;
1063 /* Increment the number of sides and rings to allow for one more point than surface */
1067 /* Allocate the vertices array */
1068 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1069 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1073 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
1074 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
1077 for( j=0; j<nRings; j++ )
1079 cpsi = cos ( psi ) ;
1080 spsi = sin ( psi ) ;
1083 for( i=0; i<nSides; i++ )
1085 int offset = 3 * ( j * nSides + i ) ;
1086 cphi = cos ( phi ) ;
1087 sphi = sin ( phi ) ;
1088 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1089 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1090 *(vertex + offset + 2) = sphi * iradius ;
1091 *(normal + offset + 0) = cpsi * cphi ;
1092 *(normal + offset + 1) = spsi * cphi ;
1093 *(normal + offset + 2) = sphi ;
1100 glBegin( GL_QUADS );
1101 for( i=0; i<nSides-1; i++ )
1103 for( j=0; j<nRings-1; j++ )
1105 int offset = 3 * ( j * nSides + i ) ;
1106 glNormal3dv( normal + offset );
1107 glVertex3dv( vertex + offset );
1108 glNormal3dv( normal + offset + 3 );
1109 glVertex3dv( vertex + offset + 3 );
1110 glNormal3dv( normal + offset + 3 * nSides + 3 );
1111 glVertex3dv( vertex + offset + 3 * nSides + 3 );
1112 glNormal3dv( normal + offset + 3 * nSides );
1113 glVertex3dv( vertex + offset + 3 * nSides );
1127 void FGAPIENTRY glutWireDodecahedron( void )
1129 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
1131 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1132 * of a cube. The coordinates of the points are:
1133 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1134 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1135 * x = 0.61803398875 and z = 1.61803398875.
1137 glBegin ( GL_LINE_LOOP ) ;
1138 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 ) ;
1140 glBegin ( GL_LINE_LOOP ) ;
1141 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 ) ;
1143 glBegin ( GL_LINE_LOOP ) ;
1144 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 ) ;
1146 glBegin ( GL_LINE_LOOP ) ;
1147 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 ) ;
1150 glBegin ( GL_LINE_LOOP ) ;
1151 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 ) ;
1153 glBegin ( GL_LINE_LOOP ) ;
1154 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 ) ;
1156 glBegin ( GL_LINE_LOOP ) ;
1157 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 ) ;
1159 glBegin ( GL_LINE_LOOP ) ;
1160 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 ) ;
1163 glBegin ( GL_LINE_LOOP ) ;
1164 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 ) ;
1166 glBegin ( GL_LINE_LOOP ) ;
1167 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 ) ;
1169 glBegin ( GL_LINE_LOOP ) ;
1170 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 ) ;
1172 glBegin ( GL_LINE_LOOP ) ;
1173 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 ) ;
1180 void FGAPIENTRY glutSolidDodecahedron( void )
1182 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1184 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1185 * of a cube. The coordinates of the points are:
1186 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1187 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1188 * x = 0.61803398875 and z = 1.61803398875.
1190 glBegin ( GL_POLYGON ) ;
1191 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 ) ;
1193 glBegin ( GL_POLYGON ) ;
1194 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 ) ;
1196 glBegin ( GL_POLYGON ) ;
1197 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 ) ;
1199 glBegin ( GL_POLYGON ) ;
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 ) ;
1203 glBegin ( GL_POLYGON ) ;
1204 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 ) ;
1206 glBegin ( GL_POLYGON ) ;
1207 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 ) ;
1209 glBegin ( GL_POLYGON ) ;
1210 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 ) ;
1212 glBegin ( GL_POLYGON ) ;
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 ) ;
1216 glBegin ( GL_POLYGON ) ;
1217 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 ) ;
1219 glBegin ( GL_POLYGON ) ;
1220 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 ) ;
1222 glBegin ( GL_POLYGON ) ;
1223 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 ) ;
1225 glBegin ( GL_POLYGON ) ;
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 ) ;
1233 static double rdod_r[14][3] = {
1235 { 0.707106781187, 0.000000000000, 0.5 },
1236 { 0.000000000000, 0.707106781187, 0.5 },
1237 { -0.707106781187, 0.000000000000, 0.5 },
1238 { 0.000000000000, -0.707106781187, 0.5 },
1239 { 0.707106781187, 0.707106781187, 0.0 },
1240 { -0.707106781187, 0.707106781187, 0.0 },
1241 { -0.707106781187, -0.707106781187, 0.0 },
1242 { 0.707106781187, -0.707106781187, 0.0 },
1243 { 0.707106781187, 0.000000000000, -0.5 },
1244 { 0.000000000000, 0.707106781187, -0.5 },
1245 { -0.707106781187, 0.000000000000, -0.5 },
1246 { 0.000000000000, -0.707106781187, -0.5 },
1250 static int rdod_v [12][4] = {
1265 static double rdod_n[12][3] = {
1266 { 0.353553390594, 0.353553390594, 0.5 },
1267 { -0.353553390594, 0.353553390594, 0.5 },
1268 { -0.353553390594, -0.353553390594, 0.5 },
1269 { 0.353553390594, -0.353553390594, 0.5 },
1270 { 0.000000000000, 1.000000000000, 0.0 },
1271 { -1.000000000000, 0.000000000000, 0.0 },
1272 { 0.000000000000, -1.000000000000, 0.0 },
1273 { 1.000000000000, 0.000000000000, 0.0 },
1274 { 0.353553390594, 0.353553390594, -0.5 },
1275 { -0.353553390594, 0.353553390594, -0.5 },
1276 { -0.353553390594, -0.353553390594, -0.5 },
1277 { 0.353553390594, -0.353553390594, -0.5 }
1280 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1284 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1286 for ( i = 0; i < 12; i++ )
1288 glBegin ( GL_LINE_LOOP ) ;
1289 glNormal3dv ( rdod_n[i] ) ;
1290 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1291 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1292 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1293 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1301 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1305 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1307 glBegin ( GL_QUADS ) ;
1308 for ( i = 0; i < 12; i++ )
1310 glNormal3dv ( rdod_n[i] ) ;
1311 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1312 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1313 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1314 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1322 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1323 /* Macro to generate interface functions */
1324 #define DECLARE_SHAPE_INTERFACE(nameICaps)\
1325 void FGAPIENTRY glutWire##nameICaps( void )\
1327 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWire"#nameICaps );\
1328 fgh##nameICaps( TRUE );\
1330 void FGAPIENTRY glutSolid##nameICaps( void )\
1332 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolid"#nameICaps );\
1333 fgh##nameICaps( FALSE );\
1336 void FGAPIENTRY glutWireCube( GLdouble dSize )
1338 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1339 fghCube( dSize, TRUE );
1341 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1343 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1344 fghCube( dSize, FALSE );
1347 DECLARE_SHAPE_INTERFACE(Icosahedron);
1348 DECLARE_SHAPE_INTERFACE(Octahedron);
1350 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1352 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1353 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1355 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1357 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1358 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1361 DECLARE_SHAPE_INTERFACE(Tetrahedron);
1364 /*** END OF FILE ***/