Doxygen Source Code Documentation
glut_shapes.c File Reference
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "glutint.h"
Go to the source code of this file.
Defines | |
#define | QUAD_OBJ_INIT() { if(!quadObj) initQuadObj(); } |
#define | DIFF3(_a, _b, _c) |
#define | X .525731112119133606 |
#define | Z .850650808352039932 |
#define | T 1.73205080756887729 |
Functions | |
void | initQuadObj (void) |
void | glutWireSphere (GLdouble radius, GLint slices, GLint stacks) |
void | glutSolidSphere (GLdouble radius, GLint slices, GLint stacks) |
void | glutWireCone (GLdouble base, GLdouble height, GLint slices, GLint stacks) |
void | glutSolidCone (GLdouble base, GLdouble height, GLint slices, GLint stacks) |
void | drawBox (GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1, GLfloat z0, GLfloat z1, GLenum type) |
void | glutWireCube (GLdouble size) |
void | glutSolidCube (GLdouble size) |
void | doughnut (GLfloat r, GLfloat R, GLint nsides, GLint rings, GLenum type) |
void | glutWireTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings) |
void | glutSolidTorus (GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings) |
void | initDodecahedron (void) |
void | crossprod (GLfloat v1[3], GLfloat v2[3], GLfloat prod[3]) |
void | normalize (GLfloat v[3]) |
void | pentagon (int a, int b, int c, int d, int e, GLenum shadeType) |
void | dodecahedron (GLenum type) |
void | glutWireDodecahedron (void) |
void | glutSolidDodecahedron (void) |
void | recorditem (GLfloat *n1, GLfloat *n2, GLfloat *n3, GLenum shadeType) |
void | subdivide (GLfloat *v0, GLfloat *v1, GLfloat *v2, GLenum shadeType) |
void | drawtriangle (int i, GLfloat data[][3], int ndx[][3], GLenum shadeType) |
void | octahedron (GLenum shadeType) |
void | glutWireOctahedron (void) |
void | glutSolidOctahedron (void) |
void | icosahedron (GLenum shadeType) |
void | glutWireIcosahedron (void) |
void | glutSolidIcosahedron (void) |
void | tetrahedron (GLenum shadeType) |
void | glutWireTetrahedron (void) |
void | glutSolidTetrahedron (void) |
Variables | |
GLUquadricObj * | quadObj |
GLfloat | dodec [20][3] |
GLfloat | odata [6][3] |
int | ondex [8][3] |
GLfloat | idata [12][3] |
int | index [20][3] |
GLfloat | tdata [4][3] |
int | tndex [4][3] |
Define Documentation
|
Value: { \ (_c)[0] = (_a)[0] - (_b)[0]; \ (_c)[1] = (_a)[1] - (_b)[1]; \ (_c)[2] = (_a)[2] - (_b)[2]; \ } Definition at line 300 of file glut_shapes.c. Referenced by pentagon(), and recorditem(). |
|
Definition at line 55 of file glut_shapes.c. Referenced by glutSolidCone(), glutSolidSphere(), glutWireCone(), and glutWireSphere(). |
|
Definition at line 574 of file glut_shapes.c. |
|
Definition at line 507 of file glut_shapes.c. |
|
Definition at line 508 of file glut_shapes.c. |
Function Documentation
|
Definition at line 307 of file glut_shapes.c. Referenced by pentagon(), and recorditem().
|
|
Definition at line 356 of file glut_shapes.c. References initDodecahedron(), and pentagon(). Referenced by glutSolidDodecahedron(), and glutWireDodecahedron().
00357 { 00358 static int inited = 0; 00359 00360 if (inited == 0) { 00361 inited = 1; 00362 initDodecahedron(); 00363 } 00364 pentagon(0, 1, 9, 16, 5, type); 00365 pentagon(1, 0, 3, 18, 7, type); 00366 pentagon(1, 7, 11, 10, 9, type); 00367 pentagon(11, 7, 18, 19, 6, type); 00368 pentagon(8, 17, 16, 9, 10, type); 00369 pentagon(2, 14, 15, 6, 19, type); 00370 pentagon(2, 13, 12, 4, 14, type); 00371 pentagon(2, 19, 18, 3, 13, type); 00372 pentagon(3, 0, 5, 12, 13, type); 00373 pentagon(6, 15, 8, 10, 11, type); 00374 pentagon(4, 17, 8, 15, 14, type); 00375 pentagon(4, 12, 5, 16, 17, type); 00376 } |
|
Definition at line 192 of file glut_shapes.c. References i, n0, n1, n2, and r. Referenced by glutSolidTorus(), and glutWireTorus().
00194 { 00195 int i, j; 00196 GLfloat theta, phi, theta1, phi1; 00197 GLfloat p0[03], p1[3], p2[3], p3[3]; 00198 GLfloat n0[3], n1[3], n2[3], n3[3]; 00199 00200 for (i = 0; i < rings; i++) { 00201 theta = (GLfloat) i *2.0 * M_PI / rings; 00202 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings; 00203 for (j = 0; j < nsides; j++) { 00204 phi = (GLfloat) j *2.0 * M_PI / nsides; 00205 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides; 00206 00207 p0[0] = cos(theta) * (R + r * cos(phi)); 00208 p0[1] = -sin(theta) * (R + r * cos(phi)); 00209 p0[2] = r * sin(phi); 00210 00211 p1[0] = cos(theta1) * (R + r * cos(phi)); 00212 p1[1] = -sin(theta1) * (R + r * cos(phi)); 00213 p1[2] = r * sin(phi); 00214 00215 p2[0] = cos(theta1) * (R + r * cos(phi1)); 00216 p2[1] = -sin(theta1) * (R + r * cos(phi1)); 00217 p2[2] = r * sin(phi1); 00218 00219 p3[0] = cos(theta) * (R + r * cos(phi1)); 00220 p3[1] = -sin(theta) * (R + r * cos(phi1)); 00221 p3[2] = r * sin(phi1); 00222 00223 n0[0] = cos(theta) * (cos(phi)); 00224 n0[1] = -sin(theta) * (cos(phi)); 00225 n0[2] = sin(phi); 00226 00227 n1[0] = cos(theta1) * (cos(phi)); 00228 n1[1] = -sin(theta1) * (cos(phi)); 00229 n1[2] = sin(phi); 00230 00231 n2[0] = cos(theta1) * (cos(phi1)); 00232 n2[1] = -sin(theta1) * (cos(phi1)); 00233 n2[2] = sin(phi1); 00234 00235 n3[0] = cos(theta) * (cos(phi1)); 00236 n3[1] = -sin(theta) * (cos(phi1)); 00237 n3[2] = sin(phi1); 00238 00239 glBegin(type); 00240 glNormal3fv(n3); 00241 glVertex3fv(p3); 00242 glNormal3fv(n2); 00243 glVertex3fv(p2); 00244 glNormal3fv(n1); 00245 glVertex3fv(p1); 00246 glNormal3fv(n0); 00247 glVertex3fv(p0); 00248 glEnd(); 00249 } 00250 } 00251 } |
|
Definition at line 116 of file glut_shapes.c. References faces, i, v, x0, y0, y1, z0, and z1. Referenced by glutSolidCube(), and glutWireCube().
00118 { 00119 static GLfloat n[6][3] = 00120 { 00121 {-1.0, 0.0, 0.0}, 00122 {0.0, 1.0, 0.0}, 00123 {1.0, 0.0, 0.0}, 00124 {0.0, -1.0, 0.0}, 00125 {0.0, 0.0, 1.0}, 00126 {0.0, 0.0, -1.0} 00127 }; 00128 static GLint faces[6][4] = 00129 { 00130 {0, 1, 2, 3}, 00131 {3, 2, 6, 7}, 00132 {7, 6, 5, 4}, 00133 {4, 5, 1, 0}, 00134 {5, 6, 2, 1}, 00135 {7, 4, 0, 3} 00136 }; 00137 GLfloat v[8][3], tmp; 00138 GLint i; 00139 00140 if (x0 > x1) { 00141 tmp = x0; 00142 x0 = x1; 00143 x1 = tmp; 00144 } 00145 if (y0 > y1) { 00146 tmp = y0; 00147 y0 = y1; 00148 y1 = tmp; 00149 } 00150 if (z0 > z1) { 00151 tmp = z0; 00152 z0 = z1; 00153 z1 = tmp; 00154 } 00155 v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0; 00156 v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1; 00157 v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0; 00158 v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1; 00159 v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0; 00160 v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1; 00161 00162 for (i = 0; i < 6; i++) { 00163 glBegin(type); 00164 glNormal3fv(&n[i][0]); 00165 glVertex3fv(&v[faces[i][0]][0]); 00166 glVertex3fv(&v[faces[i][1]][0]); 00167 glVertex3fv(&v[faces[i][2]][0]); 00168 glVertex3fv(&v[faces[i][3]][0]); 00169 glEnd(); 00170 } 00171 } |
|
Definition at line 447 of file glut_shapes.c. References i, subdivide(), x0, and x2. Referenced by icosahedron(), octahedron(), and tetrahedron().
|
|
Definition at line 103 of file glut_shapes.c. References base, QUAD_OBJ_INIT, and quadObj.
00105 { 00106 QUAD_OBJ_INIT(); 00107 gluQuadricDrawStyle(quadObj, GLU_FILL); 00108 gluQuadricNormals(quadObj, GLU_SMOOTH); 00109 /* If we ever changed/used the texture or orientation state 00110 of quadObj, we'd need to change it to the defaults here 00111 with gluQuadricTexture and/or gluQuadricOrientation. */ 00112 gluCylinder(quadObj, base, 0.0, height, slices, stacks); 00113 } |
|
Definition at line 183 of file glut_shapes.c. References drawBox().
00184 { 00185 drawBox(-size / 2., size / 2., 00186 -size / 2., size / 2., 00187 -size / 2., size / 2., 00188 GL_QUADS); 00189 } |
|
Definition at line 385 of file glut_shapes.c. References dodecahedron().
00386 { 00387 dodecahedron(GL_TRIANGLE_FAN); 00388 } |
|
Definition at line 567 of file glut_shapes.c. References icosahedron().
00568 { 00569 icosahedron(GL_TRIANGLES); 00570 } |
|
Definition at line 499 of file glut_shapes.c. References octahedron().
00500 { 00501 octahedron(GL_TRIANGLES); 00502 } |
|
Definition at line 78 of file glut_shapes.c. References QUAD_OBJ_INIT, and quadObj.
00079 { 00080 QUAD_OBJ_INIT(); 00081 gluQuadricDrawStyle(quadObj, GLU_FILL); 00082 gluQuadricNormals(quadObj, GLU_SMOOTH); 00083 /* If we ever changed/used the texture or orientation state 00084 of quadObj, we'd need to change it to the defaults here 00085 with gluQuadricTexture and/or gluQuadricOrientation. */ 00086 gluSphere(quadObj, radius, slices, stacks); 00087 } |
|
Definition at line 608 of file glut_shapes.c. References tetrahedron().
00609 { 00610 tetrahedron(GL_TRIANGLES); 00611 } |
|
Definition at line 262 of file glut_shapes.c. References doughnut().
00264 { 00265 doughnut(innerRadius, outerRadius, nsides, rings, GL_QUADS); 00266 } |
|
Definition at line 90 of file glut_shapes.c. References base, QUAD_OBJ_INIT, and quadObj.
00092 { 00093 QUAD_OBJ_INIT(); 00094 gluQuadricDrawStyle(quadObj, GLU_LINE); 00095 gluQuadricNormals(quadObj, GLU_SMOOTH); 00096 /* If we ever changed/used the texture or orientation state 00097 of quadObj, we'd need to change it to the defaults here 00098 with gluQuadricTexture and/or gluQuadricOrientation. */ 00099 gluCylinder(quadObj, base, 0.0, height, slices, stacks); 00100 } |
|
Definition at line 174 of file glut_shapes.c. References drawBox().
00175 { 00176 drawBox(-size / 2., size / 2., 00177 -size / 2., size / 2., 00178 -size / 2., size / 2., 00179 GL_LINE_LOOP); 00180 } |
|
Definition at line 379 of file glut_shapes.c. References dodecahedron().
00380 { 00381 dodecahedron(GL_LINE_LOOP); 00382 } |
|
Definition at line 561 of file glut_shapes.c. References icosahedron().
00562 { 00563 icosahedron(GL_LINE_LOOP); 00564 } |
|
Definition at line 493 of file glut_shapes.c. References octahedron().
00494 { 00495 octahedron(GL_LINE_LOOP); 00496 } |
|
Definition at line 66 of file glut_shapes.c. References QUAD_OBJ_INIT, and quadObj.
00067 { 00068 QUAD_OBJ_INIT(); 00069 gluQuadricDrawStyle(quadObj, GLU_LINE); 00070 gluQuadricNormals(quadObj, GLU_SMOOTH); 00071 /* If we ever changed/used the texture or orientation state 00072 of quadObj, we'd need to change it to the defaults here 00073 with gluQuadricTexture and/or gluQuadricOrientation. */ 00074 gluSphere(quadObj, radius, slices, stacks); 00075 } |
|
Definition at line 602 of file glut_shapes.c. References tetrahedron().
00603 { 00604 tetrahedron(GL_LINE_LOOP); 00605 } |
|
Definition at line 254 of file glut_shapes.c. References doughnut().
00256 { 00257 doughnut(innerRadius, outerRadius, 00258 nsides, rings, GL_LINE_LOOP); 00259 } |
|
Definition at line 551 of file glut_shapes.c. References drawtriangle(), i, idata, and index. Referenced by glutSolidIcosahedron(), and glutWireIcosahedron().
|
|
Definition at line 271 of file glut_shapes.c. References dodec. Referenced by dodecahedron().
00272 { 00273 GLfloat alpha, beta; 00274 00275 alpha = sqrt(2.0 / (3.0 + sqrt(5.0))); 00276 beta = 1.0 + sqrt(6.0 / (3.0 + sqrt(5.0)) - 00277 2.0 + 2.0 * sqrt(2.0 / (3.0 + sqrt(5.0)))); 00278 dodec[0][0] = -alpha; dodec[0][1] = 0; dodec[0][2] = beta; 00279 dodec[1][0] = alpha; dodec[1][1] = 0; dodec[1][2] = beta; 00280 dodec[2][0] = -1; dodec[2][1] = -1; dodec[2][2] = -1; 00281 dodec[3][0] = -1; dodec[3][1] = -1; dodec[3][2] = 1; 00282 dodec[4][0] = -1; dodec[4][1] = 1; dodec[4][2] = -1; 00283 dodec[5][0] = -1; dodec[5][1] = 1; dodec[5][2] = 1; 00284 dodec[6][0] = 1; dodec[6][1] = -1; dodec[6][2] = -1; 00285 dodec[7][0] = 1; dodec[7][1] = -1; dodec[7][2] = 1; 00286 dodec[8][0] = 1; dodec[8][1] = 1; dodec[8][2] = -1; 00287 dodec[9][0] = 1; dodec[9][1] = 1; dodec[9][2] = 1; 00288 dodec[10][0] = beta; dodec[10][1] = alpha; dodec[10][2] = 0; 00289 dodec[11][0] = beta; dodec[11][1] = -alpha; dodec[11][2] = 0; 00290 dodec[12][0] = -beta; dodec[12][1] = alpha; dodec[12][2] = 0; 00291 dodec[13][0] = -beta; dodec[13][1] = -alpha; dodec[13][2] = 0; 00292 dodec[14][0] = -alpha; dodec[14][1] = 0; dodec[14][2] = -beta; 00293 dodec[15][0] = alpha; dodec[15][1] = 0; dodec[15][2] = -beta; 00294 dodec[16][0] = 0; dodec[16][1] = beta; dodec[16][2] = alpha; 00295 dodec[17][0] = 0; dodec[17][1] = beta; dodec[17][2] = -alpha; 00296 dodec[18][0] = 0; dodec[18][1] = -beta; dodec[18][2] = alpha; 00297 dodec[19][0] = 0; dodec[19][1] = -beta; dodec[19][2] = -alpha; 00298 } |
|
Definition at line 58 of file glut_shapes.c. References __glutFatalError(), and quadObj.
00059 { 00060 quadObj = gluNewQuadric(); 00061 if (!quadObj) 00062 __glutFatalError("out of memory."); 00063 } |
|
Definition at line 320 of file glut_shapes.c. References __glutWarning(), and v. Referenced by main(), pentagon(), recorditem(), and UC_read_opts().
|
|
Definition at line 483 of file glut_shapes.c. References drawtriangle(), i, odata, and ondex. Referenced by glutSolidOctahedron(), and glutWireOctahedron().
|
|
Definition at line 336 of file glut_shapes.c. References a, c, crossprod(), DIFF3, dodec, n0, and normalize(). Referenced by dodecahedron().
00337 { 00338 GLfloat n0[3], d1[3], d2[3]; 00339 00340 DIFF3(dodec[a], dodec[b], d1); 00341 DIFF3(dodec[b], dodec[c], d2); 00342 crossprod(d1, d2, n0); 00343 normalize(n0); 00344 00345 glBegin(shadeType); 00346 glNormal3fv(n0); 00347 glVertex3fv(&dodec[a][0]); 00348 glVertex3fv(&dodec[b][0]); 00349 glVertex3fv(&dodec[c][0]); 00350 glVertex3fv(&dodec[d][0]); 00351 glVertex3fv(&dodec[e][0]); 00352 glEnd(); 00353 } |
|
Definition at line 391 of file glut_shapes.c. References crossprod(), DIFF3, n1, n2, and normalize(). Referenced by subdivide().
|
|
Definition at line 410 of file glut_shapes.c. References i, l, recorditem(), and v1. Referenced by drawtriangle().
00412 { 00413 int depth; 00414 GLfloat w0[3], w1[3], w2[3]; 00415 GLfloat l; 00416 int i, j, k, n; 00417 00418 depth = 1; 00419 for (i = 0; i < depth; i++) { 00420 for (j = 0; i + j < depth; j++) { 00421 k = depth - i - j; 00422 for (n = 0; n < 3; n++) { 00423 w0[n] = (i * v0[n] + j * v1[n] + k * v2[n]) / depth; 00424 w1[n] = ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n]) 00425 / depth; 00426 w2[n] = (i * v0[n] + (j + 1) * v1[n] + (k - 1) * v2[n]) 00427 / depth; 00428 } 00429 l = sqrt(w0[0] * w0[0] + w0[1] * w0[1] + w0[2] * w0[2]); 00430 w0[0] /= l; 00431 w0[1] /= l; 00432 w0[2] /= l; 00433 l = sqrt(w1[0] * w1[0] + w1[1] * w1[1] + w1[2] * w1[2]); 00434 w1[0] /= l; 00435 w1[1] /= l; 00436 w1[2] /= l; 00437 l = sqrt(w2[0] * w2[0] + w2[1] * w2[1] + w2[2] * w2[2]); 00438 w2[0] /= l; 00439 w2[1] /= l; 00440 w2[2] /= l; 00441 recorditem(w1, w0, w2, shadeType); 00442 } 00443 } 00444 } |
|
Definition at line 593 of file glut_shapes.c. References drawtriangle(), i, tdata, and tndex. Referenced by glutSolidTetrahedron(), and glutWireTetrahedron().
|
Variable Documentation
|
Definition at line 268 of file glut_shapes.c. Referenced by initDodecahedron(), and pentagon(). |
|
Initial value: { {-X, 0, Z}, {X, 0, Z}, {-X, 0, -Z}, {X, 0, -Z}, {0, Z, X}, {0, Z, -X}, {0, -Z, X}, {0, -Z, -X}, {Z, X, 0}, {-Z, X, 0}, {Z, -X, 0}, {-Z, -X, 0} } Definition at line 510 of file glut_shapes.c. Referenced by icosahedron(). |
|
Initial value: { {0, 4, 1}, {0, 9, 4}, {9, 5, 4}, {4, 5, 8}, {4, 8, 1}, {8, 10, 1}, {8, 3, 10}, {5, 3, 8}, {5, 2, 3}, {2, 7, 3}, {7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6}, {6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5}, {7, 2, 11}, } Definition at line 526 of file glut_shapes.c. Referenced by icosahedron(). |
|
Initial value: { {1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} } Definition at line 460 of file glut_shapes.c. Referenced by octahedron(). |
|
Initial value: { {0, 4, 2}, {1, 2, 4}, {0, 3, 4}, {1, 4, 3}, {0, 2, 5}, {1, 5, 2}, {0, 5, 3}, {1, 3, 5} } Definition at line 470 of file glut_shapes.c. Referenced by octahedron(). |
|
(c) Copyright 1993, Silicon Graphics, Inc. ALL RIGHTS RESERVED Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Silicon Graphics, Inc. not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. US Government Users Restricted Rights Use, duplication, or disclosure by the Government is subject to restrictions set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR or the DOD or NASA FAR Supplement. Unpublished-- rights reserved under the copyright laws of the United States. Contractor/manufacturer is Silicon Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. OpenGL(TM) is a trademark of Silicon Graphics, Inc. Definition at line 53 of file glut_shapes.c. Referenced by glutSolidCone(), glutSolidSphere(), glutWireCone(), glutWireSphere(), and initQuadObj(). |
|
Initial value: { {T, T, T}, {T, -T, -T}, {-T, T, -T}, {-T, -T, T} } Definition at line 576 of file glut_shapes.c. Referenced by tetrahedron(). |
|
Initial value: { {0, 1, 3}, {2, 1, 0}, {3, 2, 0}, {1, 2, 3} } Definition at line 584 of file glut_shapes.c. Referenced by tetrahedron(). |