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 -- */
148 * In general, we build arrays with all vertices or normals.
149 * We cant compress this and use glDrawElements as all combinations of
150 * vertex and normals are unique.
154 #define CUBE_NUM_VERT 8
155 #define CUBE_NUM_FACES 6
156 #define CUBE_NUM_VERT_PER_FACE 4
157 #define CUBE_VERT_PER_CUBE CUBE_NUM_FACES*CUBE_NUM_VERT_PER_FACE
158 #define CUBE_VERT_ELEM_PER_CUBE CUBE_VERT_PER_CUBE*3
159 /* Vertex Coordinates */
160 static GLdouble cube_v[CUBE_NUM_VERT*3] =
172 static GLdouble cube_n[CUBE_NUM_FACES*3] =
183 static GLubyte cube_vi[CUBE_VERT_PER_CUBE] =
193 /* Cache of input to glDrawArrays */
194 static GLboolean cubeCached = FALSE;
195 static GLdouble cube_verts[CUBE_VERT_ELEM_PER_CUBE];
196 static GLdouble cube_norms[CUBE_VERT_ELEM_PER_CUBE];
198 static void fghCubeGenerate()
200 fghGenerateGeometry(CUBE_NUM_FACES, CUBE_NUM_VERT_PER_FACE, cube_v, cube_vi, cube_n, cube_verts, cube_norms);
203 /* -- Octahedron -- */
204 #define OCTAHEDRON_NUM_VERT 6
205 #define OCTAHEDRON_NUM_FACES 8
206 #define OCTAHEDRON_NUM_VERT_PER_FACE 3
207 #define OCTAHEDRON_VERT_PER_OCTA OCTAHEDRON_NUM_FACES*OCTAHEDRON_NUM_VERT_PER_FACE
208 #define OCTAHEDRON_VERT_ELEM_PER_OCTA OCTAHEDRON_VERT_PER_OCTA*3
210 /* Vertex Coordinates */
211 static GLdouble octahedron_v[OCTAHEDRON_NUM_VERT*3] =
222 static GLdouble octahedron_n[OCTAHEDRON_NUM_FACES*3] =
224 0.577350269189, 0.577350269189, 0.577350269189, /* sqrt(1/3) */
225 0.577350269189, 0.577350269189,-0.577350269189,
226 0.577350269189,-0.577350269189, 0.577350269189,
227 0.577350269189,-0.577350269189,-0.577350269189,
228 -0.577350269189, 0.577350269189, 0.577350269189,
229 -0.577350269189, 0.577350269189,-0.577350269189,
230 -0.577350269189,-0.577350269189, 0.577350269189,
231 -0.577350269189,-0.577350269189,-0.577350269189
236 static GLubyte octahedron_vi[OCTAHEDRON_VERT_PER_OCTA] =
248 /* Cache of input to glDrawArrays */
249 static GLboolean octahedronCached = FALSE;
250 static GLdouble octahedron_verts[OCTAHEDRON_VERT_ELEM_PER_OCTA];
251 static GLdouble octahedron_norms[OCTAHEDRON_VERT_ELEM_PER_OCTA];
253 static void fghOctahedronGenerate()
255 fghGenerateGeometry(OCTAHEDRON_NUM_FACES, OCTAHEDRON_NUM_VERT_PER_FACE, octahedron_v, octahedron_vi, octahedron_n, octahedron_verts, octahedron_norms);
258 /* -- Tetrahedron -- */
259 /* Magic Numbers: r0 = ( 1, 0, 0 )
260 * r1 = ( -1/3, 2 sqrt(2) / 3, 0 )
261 * r2 = ( -1/3, - sqrt(2) / 3, sqrt(6) / 3 )
262 * r3 = ( -1/3, - sqrt(2) / 3, -sqrt(6) / 3 )
263 * |r0| = |r1| = |r2| = |r3| = 1
264 * Distance between any two points is 2 sqrt(6) / 3
266 * Normals: The unit normals are simply the negative of the coordinates of the point not on the surface.
268 #define TETR_NUM_VERT 4
269 #define TETR_NUM_FACES 4
270 #define TETR_NUM_VERT_PER_FACE 3
271 #define TETR_VERT_PER_TETR TETR_NUM_FACES*TETR_NUM_VERT_PER_FACE
272 #define TETR_VERT_ELEM_PER_TETR TETR_VERT_PER_TETR*3
274 /* Vertex Coordinates */
275 static GLdouble tetr_v[TETR_NUM_VERT*3] =
278 -0.333333333333, 0.942809041582, 0.0,
279 -0.333333333333, -0.471404520791, 0.816496580928,
280 -0.333333333333, -0.471404520791, -0.816496580928
283 static GLdouble tetr_n[CUBE_NUM_FACES*3] =
286 0.333333333333, -0.942809041582, 0.0,
287 0.333333333333, 0.471404520791, -0.816496580928,
288 0.333333333333, 0.471404520791, 0.816496580928
292 static GLubyte tetr_vi[TETR_VERT_PER_TETR] =
300 /* Cache of input to glDrawArrays */
301 static GLboolean tetrCached = FALSE;
302 static GLdouble tetr_verts[TETR_VERT_ELEM_PER_TETR];
303 static GLdouble tetr_norms[TETR_VERT_ELEM_PER_TETR];
305 static void fghTetrahedronGenerate()
307 fghGenerateGeometry(TETR_NUM_FACES, TETR_NUM_VERT_PER_FACE, tetr_v, tetr_vi, tetr_n, tetr_verts, tetr_norms);
310 /* -- Sierpinski Sponge -- */
311 static void fghSierpinskiSpongeGenerate ( int numLevels, GLdouble offset[3], GLdouble scale, GLdouble* vertices, GLdouble* normals )
314 if ( numLevels == 0 )
316 for (i=0; i<TETR_NUM_FACES; i++)
319 int faceIdxVertIdx = i*TETR_NUM_VERT_PER_FACE;
320 for (j=0; j<TETR_NUM_VERT_PER_FACE; j++)
322 int outIdx = i*TETR_NUM_VERT_PER_FACE*3+j*3;
323 int vertIdx = tetr_vi[faceIdxVertIdx+j]*3;
325 vertices[outIdx ] = offset[0] + scale * tetr_v[vertIdx ];
326 vertices[outIdx+1] = offset[1] + scale * tetr_v[vertIdx+1];
327 vertices[outIdx+2] = offset[2] + scale * tetr_v[vertIdx+2];
329 normals [outIdx ] = tetr_n[normIdx ];
330 normals [outIdx+1] = tetr_n[normIdx+1];
331 normals [outIdx+2] = tetr_n[normIdx+2];
335 else if ( numLevels > 0 )
337 GLdouble local_offset[3] ; /* Use a local variable to avoid buildup of roundoff errors */
338 unsigned int stride = ipow(4,--numLevels)*TETR_VERT_ELEM_PER_TETR;
340 for ( i = 0 ; i < TETR_NUM_FACES ; i++ )
343 local_offset[0] = offset[0] + scale * tetr_v[idx ];
344 local_offset[1] = offset[1] + scale * tetr_v[idx+1];
345 local_offset[2] = offset[2] + scale * tetr_v[idx+2];
346 fghSierpinskiSpongeGenerate ( numLevels, local_offset, scale, vertices+i*stride, normals+i*stride );
351 /* -- Now the various shapes involving circles -- */
353 * Compute lookup table of cos and sin values forming a cirle
356 * It is the responsibility of the caller to free these tables
357 * The size of the table is (n+1) to form a connected loop
358 * The last entry is exactly the same as the first
359 * The sign of n can be flipped to get the reverse loop
361 static void fghCircleTable(double **sint,double **cost,const int n)
365 /* Table size, the sign of n flips the circle direction */
367 const int size = abs(n);
369 /* Determine the angle between samples */
371 const double angle = 2*M_PI/(double)( ( n == 0 ) ? 1 : n );
373 /* Allocate memory for n samples, plus duplicate of first entry at the end */
375 *sint = (double *) calloc(sizeof(double), size+1);
376 *cost = (double *) calloc(sizeof(double), size+1);
378 /* Bail out if memory allocation fails, fgError never returns */
380 if (!(*sint) || !(*cost))
384 fgError("Failed to allocate memory in fghCircleTable");
387 /* Compute cos and sin around the circle */
392 for (i=1; i<size; i++)
394 (*sint)[i] = sin(angle*i);
395 (*cost)[i] = cos(angle*i);
398 /* Last sample is duplicate of the first */
400 (*sint)[size] = (*sint)[0];
401 (*cost)[size] = (*cost)[0];
405 /* -- INTERNAL DRAWING functions to avoid code duplication ------------- */
407 static void fghCube( GLdouble dSize, GLboolean useWireMode )
419 /* Need to build new vertex list containing vertices for cube of different size */
420 GLdouble *vertices = malloc(CUBE_VERT_ELEM_PER_CUBE * sizeof(GLdouble));
421 for (i=0; i<CUBE_VERT_ELEM_PER_CUBE; i++)
422 vertices[i] = dSize*cube_verts[i];
424 fghDrawGeometry(GL_QUADS,vertices ,cube_norms,CUBE_VERT_PER_CUBE,useWireMode);
427 fghDrawGeometry(GL_QUADS,cube_verts,cube_norms,CUBE_VERT_PER_CUBE,useWireMode);
430 static void fghOctahedron( GLboolean useWireMode )
432 if (!octahedronCached)
434 fghOctahedronGenerate();
435 octahedronCached = TRUE;
438 fghDrawGeometry(GL_TRIANGLES,octahedron_verts,octahedron_norms,OCTAHEDRON_VERT_PER_OCTA,useWireMode);
441 static void fghTetrahedron( GLboolean useWireMode )
445 fghTetrahedronGenerate();
449 fghDrawGeometry(GL_TRIANGLES,tetr_verts,tetr_norms,TETR_VERT_PER_TETR,useWireMode);
452 static void fghSierpinskiSponge ( int numLevels, GLdouble offset[3], GLdouble scale, GLboolean useWireMode )
456 GLsizei numTetr = numLevels<0? 0 : ipow(4,numLevels); /* No sponge for numLevels below 0 */
457 GLsizei numVert = numTetr*TETR_VERT_PER_TETR;
461 /* Allocate memory */
462 vertices = malloc(numVert*3 * sizeof(GLdouble));
463 normals = malloc(numVert*3 * sizeof(GLdouble));
465 /* Generate elements */
466 fghSierpinskiSpongeGenerate ( numLevels, offset, scale, vertices, normals );
468 /* Draw and cleanup */
469 fghDrawGeometry(GL_TRIANGLES,vertices,normals,numVert,useWireMode);
476 /* -- INTERFACE FUNCTIONS ---------------------------------------------- */
480 * Draws a solid sphere
482 void FGAPIENTRY glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
486 /* Adjust z and radius as stacks are drawn. */
491 /* Pre-computed circle */
493 double *sint1,*cost1;
494 double *sint2,*cost2;
496 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSphere" );
498 fghCircleTable(&sint1,&cost1,-slices);
499 fghCircleTable(&sint2,&cost2,stacks*2);
501 /* The top stack is covered with a triangle fan */
504 z1 = cost2[(stacks>0)?1:0];
506 r1 = sint2[(stacks>0)?1:0];
508 glBegin(GL_TRIANGLE_FAN);
511 glVertex3d(0,0,radius);
513 for (j=slices; j>=0; j--)
515 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
516 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
521 /* Cover each stack with a quad strip, except the top and bottom stacks */
523 for( i=1; i<stacks-1; i++ )
525 z0 = z1; z1 = cost2[i+1];
526 r0 = r1; r1 = sint2[i+1];
528 glBegin(GL_QUAD_STRIP);
530 for(j=0; j<=slices; j++)
532 glNormal3d(cost1[j]*r1, sint1[j]*r1, z1 );
533 glVertex3d(cost1[j]*r1*radius, sint1[j]*r1*radius, z1*radius);
534 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
535 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
541 /* The bottom stack is covered with a triangle fan */
546 glBegin(GL_TRIANGLE_FAN);
549 glVertex3d(0,0,-radius);
551 for (j=0; j<=slices; j++)
553 glNormal3d(cost1[j]*r0, sint1[j]*r0, z0 );
554 glVertex3d(cost1[j]*r0*radius, sint1[j]*r0*radius, z0*radius);
559 /* Release sin and cos tables */
568 * Draws a wire sphere
570 void FGAPIENTRY glutWireSphere(GLdouble radius, GLint slices, GLint stacks)
574 /* Adjust z and radius as stacks and slices are drawn. */
579 /* Pre-computed circle */
581 double *sint1,*cost1;
582 double *sint2,*cost2;
584 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSphere" );
586 fghCircleTable(&sint1,&cost1,-slices );
587 fghCircleTable(&sint2,&cost2, stacks*2);
589 /* Draw a line loop for each stack */
591 for (i=1; i<stacks; i++)
596 glBegin(GL_LINE_LOOP);
598 for(j=0; j<=slices; j++)
604 glVertex3d(x*r*radius,y*r*radius,z*radius);
610 /* Draw a line loop for each slice */
612 for (i=0; i<slices; i++)
614 glBegin(GL_LINE_STRIP);
616 for(j=0; j<=stacks; j++)
618 x = cost1[i]*sint2[j];
619 y = sint1[i]*sint2[j];
623 glVertex3d(x*radius,y*radius,z*radius);
629 /* Release sin and cos tables */
640 void FGAPIENTRY glutSolidCone( GLdouble base, GLdouble height, GLint slices, GLint stacks )
644 /* Step in z and radius as stacks are drawn. */
649 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
650 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
652 /* Scaling factors for vertex normals */
654 const double cosn = ( height / sqrt ( height * height + base * base ));
655 const double sinn = ( base / sqrt ( height * height + base * base ));
657 /* Pre-computed circle */
661 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCone" );
663 fghCircleTable(&sint,&cost,-slices);
665 /* Cover the circular base with a triangle fan... */
673 glBegin(GL_TRIANGLE_FAN);
675 glNormal3d(0.0,0.0,-1.0);
676 glVertex3d(0.0,0.0, z0 );
678 for (j=0; j<=slices; j++)
679 glVertex3d(cost[j]*r0, sint[j]*r0, z0);
683 /* Cover each stack with a quad strip, except the top stack */
685 for( i=0; i<stacks-1; i++ )
687 glBegin(GL_QUAD_STRIP);
689 for(j=0; j<=slices; j++)
691 glNormal3d(cost[j]*cosn, sint[j]*cosn, sinn);
692 glVertex3d(cost[j]*r0, sint[j]*r0, z0 );
693 glVertex3d(cost[j]*r1, sint[j]*r1, z1 );
696 z0 = z1; z1 += zStep;
697 r0 = r1; r1 -= rStep;
702 /* The top stack is covered with individual triangles */
704 glBegin(GL_TRIANGLES);
706 glNormal3d(cost[0]*sinn, sint[0]*sinn, cosn);
708 for (j=0; j<slices; j++)
710 glVertex3d(cost[j+0]*r0, sint[j+0]*r0, z0 );
711 glVertex3d(0, 0, height);
712 glNormal3d(cost[j+1]*sinn, sint[j+1]*sinn, cosn );
713 glVertex3d(cost[j+1]*r0, sint[j+1]*r0, z0 );
718 /* Release sin and cos tables */
727 void FGAPIENTRY glutWireCone( GLdouble base, GLdouble height, GLint slices, GLint stacks)
731 /* Step in z and radius as stacks are drawn. */
736 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
737 const double rStep = base / ( ( stacks > 0 ) ? stacks : 1 );
739 /* Scaling factors for vertex normals */
741 const double cosn = ( height / sqrt ( height * height + base * base ));
742 const double sinn = ( base / sqrt ( height * height + base * base ));
744 /* Pre-computed circle */
748 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCone" );
750 fghCircleTable(&sint,&cost,-slices);
752 /* Draw the stacks... */
754 for (i=0; i<stacks; i++)
756 glBegin(GL_LINE_LOOP);
758 for( j=0; j<slices; j++ )
760 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn);
761 glVertex3d(cost[j]*r, sint[j]*r, z );
770 /* Draw the slices */
776 for (j=0; j<slices; j++)
778 glNormal3d(cost[j]*sinn, sint[j]*sinn, cosn );
779 glVertex3d(cost[j]*r, sint[j]*r, 0.0 );
780 glVertex3d(0.0, 0.0, height);
785 /* Release sin and cos tables */
793 * Draws a solid cylinder
795 void FGAPIENTRY glutSolidCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
799 /* Step in z and radius as stacks are drawn. */
802 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
804 /* Pre-computed circle */
808 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCylinder" );
810 fghCircleTable(&sint,&cost,-slices);
812 /* Cover the base and top */
814 glBegin(GL_TRIANGLE_FAN);
815 glNormal3d(0.0, 0.0, -1.0 );
816 glVertex3d(0.0, 0.0, 0.0 );
817 for (j=0; j<=slices; j++)
818 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0);
821 glBegin(GL_TRIANGLE_FAN);
822 glNormal3d(0.0, 0.0, 1.0 );
823 glVertex3d(0.0, 0.0, height);
824 for (j=slices; j>=0; j--)
825 glVertex3d(cost[j]*radius, sint[j]*radius, height);
833 for (i=1; i<=stacks; i++)
838 glBegin(GL_QUAD_STRIP);
839 for (j=0; j<=slices; j++ )
841 glNormal3d(cost[j], sint[j], 0.0 );
842 glVertex3d(cost[j]*radius, sint[j]*radius, z0 );
843 glVertex3d(cost[j]*radius, sint[j]*radius, z1 );
847 z0 = z1; z1 += zStep;
850 /* Release sin and cos tables */
857 * Draws a wire cylinder
859 void FGAPIENTRY glutWireCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks)
863 /* Step in z and radius as stacks are drawn. */
866 const double zStep = height / ( ( stacks > 0 ) ? stacks : 1 );
868 /* Pre-computed circle */
872 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCylinder" );
874 fghCircleTable(&sint,&cost,-slices);
876 /* Draw the stacks... */
878 for (i=0; i<=stacks; i++)
883 glBegin(GL_LINE_LOOP);
885 for( j=0; j<slices; j++ )
887 glNormal3d(cost[j], sint[j], 0.0);
888 glVertex3d(cost[j]*radius, sint[j]*radius, z );
896 /* Draw the slices */
900 for (j=0; j<slices; j++)
902 glNormal3d(cost[j], sint[j], 0.0 );
903 glVertex3d(cost[j]*radius, sint[j]*radius, 0.0 );
904 glVertex3d(cost[j]*radius, sint[j]*radius, height);
909 /* Release sin and cos tables */
918 void FGAPIENTRY glutWireTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
920 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
921 double *vertex, *normal;
923 double spsi, cpsi, sphi, cphi ;
925 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTorus" );
927 if ( nSides < 1 ) nSides = 1;
928 if ( nRings < 1 ) nRings = 1;
930 /* Allocate the vertices array */
931 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
932 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
936 dpsi = 2.0 * M_PI / (double)nRings ;
937 dphi = -2.0 * M_PI / (double)nSides ;
940 for( j=0; j<nRings; j++ )
946 for( i=0; i<nSides; i++ )
948 int offset = 3 * ( j * nSides + i ) ;
951 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
952 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
953 *(vertex + offset + 2) = sphi * iradius ;
954 *(normal + offset + 0) = cpsi * cphi ;
955 *(normal + offset + 1) = spsi * cphi ;
956 *(normal + offset + 2) = sphi ;
963 for( i=0; i<nSides; i++ )
965 glBegin( GL_LINE_LOOP );
967 for( j=0; j<nRings; j++ )
969 int offset = 3 * ( j * nSides + i ) ;
970 glNormal3dv( normal + offset );
971 glVertex3dv( vertex + offset );
977 for( j=0; j<nRings; j++ )
979 glBegin(GL_LINE_LOOP);
981 for( i=0; i<nSides; i++ )
983 int offset = 3 * ( j * nSides + i ) ;
984 glNormal3dv( normal + offset );
985 glVertex3dv( vertex + offset );
997 * Draws a solid torus
999 void FGAPIENTRY glutSolidTorus( GLdouble dInnerRadius, GLdouble dOuterRadius, GLint nSides, GLint nRings )
1001 double iradius = dInnerRadius, oradius = dOuterRadius, phi, psi, dpsi, dphi;
1002 double *vertex, *normal;
1004 double spsi, cpsi, sphi, cphi ;
1006 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTorus" );
1008 if ( nSides < 1 ) nSides = 1;
1009 if ( nRings < 1 ) nRings = 1;
1011 /* Increment the number of sides and rings to allow for one more point than surface */
1015 /* Allocate the vertices array */
1016 vertex = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1017 normal = (double *)calloc( sizeof(double), 3 * nSides * nRings );
1021 dpsi = 2.0 * M_PI / (double)(nRings - 1) ;
1022 dphi = -2.0 * M_PI / (double)(nSides - 1) ;
1025 for( j=0; j<nRings; j++ )
1027 cpsi = cos ( psi ) ;
1028 spsi = sin ( psi ) ;
1031 for( i=0; i<nSides; i++ )
1033 int offset = 3 * ( j * nSides + i ) ;
1034 cphi = cos ( phi ) ;
1035 sphi = sin ( phi ) ;
1036 *(vertex + offset + 0) = cpsi * ( oradius + cphi * iradius ) ;
1037 *(vertex + offset + 1) = spsi * ( oradius + cphi * iradius ) ;
1038 *(vertex + offset + 2) = sphi * iradius ;
1039 *(normal + offset + 0) = cpsi * cphi ;
1040 *(normal + offset + 1) = spsi * cphi ;
1041 *(normal + offset + 2) = sphi ;
1048 glBegin( GL_QUADS );
1049 for( i=0; i<nSides-1; i++ )
1051 for( j=0; j<nRings-1; j++ )
1053 int offset = 3 * ( j * nSides + i ) ;
1054 glNormal3dv( normal + offset );
1055 glVertex3dv( vertex + offset );
1056 glNormal3dv( normal + offset + 3 );
1057 glVertex3dv( vertex + offset + 3 );
1058 glNormal3dv( normal + offset + 3 * nSides + 3 );
1059 glVertex3dv( vertex + offset + 3 * nSides + 3 );
1060 glNormal3dv( normal + offset + 3 * nSides );
1061 glVertex3dv( vertex + offset + 3 * nSides );
1075 void FGAPIENTRY glutWireDodecahedron( void )
1077 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireDodecahedron" );
1079 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1080 * of a cube. The coordinates of the points are:
1081 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1082 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1083 * x = 0.61803398875 and z = 1.61803398875.
1085 glBegin ( GL_LINE_LOOP ) ;
1086 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 ) ;
1088 glBegin ( GL_LINE_LOOP ) ;
1089 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 ) ;
1091 glBegin ( GL_LINE_LOOP ) ;
1092 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 ) ;
1094 glBegin ( GL_LINE_LOOP ) ;
1095 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 ) ;
1098 glBegin ( GL_LINE_LOOP ) ;
1099 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 ) ;
1101 glBegin ( GL_LINE_LOOP ) ;
1102 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 ) ;
1104 glBegin ( GL_LINE_LOOP ) ;
1105 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 ) ;
1107 glBegin ( GL_LINE_LOOP ) ;
1108 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 ) ;
1111 glBegin ( GL_LINE_LOOP ) ;
1112 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 ) ;
1114 glBegin ( GL_LINE_LOOP ) ;
1115 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 ) ;
1117 glBegin ( GL_LINE_LOOP ) ;
1118 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 ) ;
1120 glBegin ( GL_LINE_LOOP ) ;
1121 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 ) ;
1128 void FGAPIENTRY glutSolidDodecahedron( void )
1130 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidDodecahedron" );
1132 /* Magic Numbers: It is possible to create a dodecahedron by attaching two pentagons to each face of
1133 * of a cube. The coordinates of the points are:
1134 * (+-x,0, z); (+-1, 1, 1); (0, z, x )
1135 * where x = (-1 + sqrt(5))/2, z = (1 + sqrt(5))/2 or
1136 * x = 0.61803398875 and z = 1.61803398875.
1138 glBegin ( GL_POLYGON ) ;
1139 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 ) ;
1141 glBegin ( GL_POLYGON ) ;
1142 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 ) ;
1144 glBegin ( GL_POLYGON ) ;
1145 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 ) ;
1147 glBegin ( GL_POLYGON ) ;
1148 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 ) ;
1151 glBegin ( GL_POLYGON ) ;
1152 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 ) ;
1154 glBegin ( GL_POLYGON ) ;
1155 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 ) ;
1157 glBegin ( GL_POLYGON ) ;
1158 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 ) ;
1160 glBegin ( GL_POLYGON ) ;
1161 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 ) ;
1164 glBegin ( GL_POLYGON ) ;
1165 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 ) ;
1167 glBegin ( GL_POLYGON ) ;
1168 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 ) ;
1170 glBegin ( GL_POLYGON ) ;
1171 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 ) ;
1173 glBegin ( GL_POLYGON ) ;
1174 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 ) ;
1181 static double icos_r[12][3] = {
1183 { 0.447213595500, 0.894427191000, 0.0 },
1184 { 0.447213595500, 0.276393202252, 0.850650808354 },
1185 { 0.447213595500, -0.723606797748, 0.525731112119 },
1186 { 0.447213595500, -0.723606797748, -0.525731112119 },
1187 { 0.447213595500, 0.276393202252, -0.850650808354 },
1188 { -0.447213595500, -0.894427191000, 0.0 },
1189 { -0.447213595500, -0.276393202252, 0.850650808354 },
1190 { -0.447213595500, 0.723606797748, 0.525731112119 },
1191 { -0.447213595500, 0.723606797748, -0.525731112119 },
1192 { -0.447213595500, -0.276393202252, -0.850650808354 },
1196 static int icos_v [20][3] = {
1219 void FGAPIENTRY glutWireIcosahedron( void )
1223 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireIcosahedron" );
1225 for ( i = 0; i < 20; i++ )
1228 normal[0] = ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) - ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) ;
1229 normal[1] = ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) - ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) ;
1230 normal[2] = ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) - ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) ;
1231 glBegin ( GL_LINE_LOOP ) ;
1232 glNormal3dv ( normal ) ;
1233 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1234 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1235 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1243 void FGAPIENTRY glutSolidIcosahedron( void )
1247 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidIcosahedron" );
1249 glBegin ( GL_TRIANGLES ) ;
1250 for ( i = 0; i < 20; i++ )
1253 normal[0] = ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) - ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) ;
1254 normal[1] = ( icos_r[icos_v[i][1]][2] - icos_r[icos_v[i][0]][2] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) - ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][2] - icos_r[icos_v[i][0]][2] ) ;
1255 normal[2] = ( icos_r[icos_v[i][1]][0] - icos_r[icos_v[i][0]][0] ) * ( icos_r[icos_v[i][2]][1] - icos_r[icos_v[i][0]][1] ) - ( icos_r[icos_v[i][1]][1] - icos_r[icos_v[i][0]][1] ) * ( icos_r[icos_v[i][2]][0] - icos_r[icos_v[i][0]][0] ) ;
1256 glNormal3dv ( normal ) ;
1257 glVertex3dv ( icos_r[icos_v[i][0]] ) ;
1258 glVertex3dv ( icos_r[icos_v[i][1]] ) ;
1259 glVertex3dv ( icos_r[icos_v[i][2]] ) ;
1268 static double rdod_r[14][3] = {
1270 { 0.707106781187, 0.000000000000, 0.5 },
1271 { 0.000000000000, 0.707106781187, 0.5 },
1272 { -0.707106781187, 0.000000000000, 0.5 },
1273 { 0.000000000000, -0.707106781187, 0.5 },
1274 { 0.707106781187, 0.707106781187, 0.0 },
1275 { -0.707106781187, 0.707106781187, 0.0 },
1276 { -0.707106781187, -0.707106781187, 0.0 },
1277 { 0.707106781187, -0.707106781187, 0.0 },
1278 { 0.707106781187, 0.000000000000, -0.5 },
1279 { 0.000000000000, 0.707106781187, -0.5 },
1280 { -0.707106781187, 0.000000000000, -0.5 },
1281 { 0.000000000000, -0.707106781187, -0.5 },
1285 static int rdod_v [12][4] = {
1300 static double rdod_n[12][3] = {
1301 { 0.353553390594, 0.353553390594, 0.5 },
1302 { -0.353553390594, 0.353553390594, 0.5 },
1303 { -0.353553390594, -0.353553390594, 0.5 },
1304 { 0.353553390594, -0.353553390594, 0.5 },
1305 { 0.000000000000, 1.000000000000, 0.0 },
1306 { -1.000000000000, 0.000000000000, 0.0 },
1307 { 0.000000000000, -1.000000000000, 0.0 },
1308 { 1.000000000000, 0.000000000000, 0.0 },
1309 { 0.353553390594, 0.353553390594, -0.5 },
1310 { -0.353553390594, 0.353553390594, -0.5 },
1311 { -0.353553390594, -0.353553390594, -0.5 },
1312 { 0.353553390594, -0.353553390594, -0.5 }
1315 void FGAPIENTRY glutWireRhombicDodecahedron( void )
1319 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireRhombicDodecahedron" );
1321 for ( i = 0; i < 12; i++ )
1323 glBegin ( GL_LINE_LOOP ) ;
1324 glNormal3dv ( rdod_n[i] ) ;
1325 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1326 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1327 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1328 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1336 void FGAPIENTRY glutSolidRhombicDodecahedron( void )
1340 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidRhombicDodecahedron" );
1342 glBegin ( GL_QUADS ) ;
1343 for ( i = 0; i < 12; i++ )
1345 glNormal3dv ( rdod_n[i] ) ;
1346 glVertex3dv ( rdod_r[rdod_v[i][0]] ) ;
1347 glVertex3dv ( rdod_r[rdod_v[i][1]] ) ;
1348 glVertex3dv ( rdod_r[rdod_v[i][2]] ) ;
1349 glVertex3dv ( rdod_r[rdod_v[i][3]] ) ;
1357 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
1359 * Draws a wireframed cube.
1361 void FGAPIENTRY glutWireCube( GLdouble dSize )
1363 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireCube" );
1364 fghCube( dSize, TRUE );
1366 void FGAPIENTRY glutSolidCube( GLdouble dSize )
1368 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidCube" );
1369 fghCube( dSize, FALSE );
1372 void FGAPIENTRY glutWireOctahedron( void )
1374 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireOctahedron" );
1375 fghOctahedron( TRUE );
1377 void FGAPIENTRY glutSolidOctahedron( void )
1379 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidOctahedron" );
1380 fghOctahedron( FALSE );
1383 void FGAPIENTRY glutWireSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1385 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireSierpinskiSponge" );
1386 fghSierpinskiSponge ( num_levels, offset, scale, TRUE );
1388 void FGAPIENTRY glutSolidSierpinskiSponge ( int num_levels, GLdouble offset[3], GLdouble scale )
1390 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidSierpinskiSponge" );
1391 fghSierpinskiSponge ( num_levels, offset, scale, FALSE );
1394 void FGAPIENTRY glutWireTetrahedron( void )
1396 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTetrahedron" );
1397 fghTetrahedron( TRUE );
1399 void FGAPIENTRY glutSolidTetrahedron( void )
1401 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTetrahedron" );
1402 fghTetrahedron( FALSE );
1406 /*** END OF FILE ***/