| 1 |
/* $Id: quadric.c,v 1.2 2000/11/02 00:28:54 mholst Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Mesa 3-D graphics library |
| 5 |
* Version: 2.2 |
| 6 |
* Copyright (C) 1995-1997 Brian Paul |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Library General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Library General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Library General Public |
| 19 |
* License along with this library; if not, write to the Free |
| 20 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
/* TODO: |
| 24 |
* texture coordinate support |
| 25 |
* flip normals according to orientation |
| 26 |
* there's still some inside/outside orientation bugs in possibly all |
| 27 |
* but the sphere function |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
#include <math.h> |
| 32 |
#include <stdio.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include "gluP.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#ifndef M_PI |
| 39 |
# define M_PI (3.1415926) |
| 40 |
#endif |
| 41 |
|
| 42 |
|
| 43 |
/* |
| 44 |
* Convert degrees to radians: |
| 45 |
*/ |
| 46 |
#define DEG_TO_RAD(A) ((A)*(M_PI/180.0)) |
| 47 |
|
| 48 |
|
| 49 |
/* |
| 50 |
* Sin and Cos for degree angles: |
| 51 |
*/ |
| 52 |
#define SIND( A ) sin( (A)*(M_PI/180.0) ) |
| 53 |
#define COSD( A) cos( (A)*(M_PI/180.0) ) |
| 54 |
|
| 55 |
|
| 56 |
/* |
| 57 |
* Texture coordinates if texture flag is set |
| 58 |
*/ |
| 59 |
#define TXTR_COORD(x,y) if (qobj->TextureFlag) glTexCoord2f(x,y); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
struct GLUquadricObj { |
| 64 |
GLenum DrawStyle; /* GLU_FILL, LINE, SILHOUETTE, or POINT */ |
| 65 |
GLenum Orientation; /* GLU_INSIDE or GLU_OUTSIDE */ |
| 66 |
GLboolean TextureFlag; /* Generate texture coords? */ |
| 67 |
GLenum Normals; /* GLU_NONE, GLU_FLAT, or GLU_SMOOTH */ |
| 68 |
void (*ErrorFunc)(GLenum err); /* Error handler callback function */ |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
/* |
| 74 |
* Process a GLU error. |
| 75 |
*/ |
| 76 |
static void quadric_error( GLUquadricObj *qobj, GLenum error, const char *msg ) |
| 77 |
{ |
| 78 |
/* Call the error call back function if any */ |
| 79 |
if (qobj->ErrorFunc) { |
| 80 |
(*qobj->ErrorFunc)( error ); |
| 81 |
} |
| 82 |
/* Print a message to stdout if MESA_DEBUG variable is defined */ |
| 83 |
if (getenv("MESA_DEBUG")) { |
| 84 |
fprintf(stderr,"GLUError: %s: %s\n", gluErrorString(error), msg ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
GLUquadricObj *gluNewQuadric( void ) |
| 92 |
{ |
| 93 |
GLUquadricObj *q; |
| 94 |
|
| 95 |
q = (GLUquadricObj *) malloc( sizeof(struct GLUquadricObj) ); |
| 96 |
if (q) { |
| 97 |
q->DrawStyle = GLU_FILL; |
| 98 |
q->Orientation = GLU_OUTSIDE; |
| 99 |
q->TextureFlag = GL_FALSE; |
| 100 |
q->Normals = GLU_SMOOTH; |
| 101 |
q->ErrorFunc = NULL; |
| 102 |
} |
| 103 |
return q; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
void gluDeleteQuadric( GLUquadricObj *state ) |
| 109 |
{ |
| 110 |
if (state) { |
| 111 |
free( (void *) state ); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
/* |
| 118 |
* Set the drawing style to be GLU_FILL, GLU_LINE, GLU_SILHOUETTE, or GLU_POINT. |
| 119 |
*/ |
| 120 |
void gluQuadricDrawStyle( GLUquadricObj *quadObject, GLenum drawStyle ) |
| 121 |
{ |
| 122 |
if (quadObject && (drawStyle==GLU_FILL || drawStyle==GLU_LINE |
| 123 |
|| drawStyle==GLU_SILHOUETTE || drawStyle==GLU_POINT)) { |
| 124 |
quadObject->DrawStyle = drawStyle; |
| 125 |
} |
| 126 |
else { |
| 127 |
quadric_error( quadObject, GLU_INVALID_ENUM, "qluQuadricDrawStyle" ); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
/* |
| 134 |
* Set the orientation to GLU_INSIDE or GLU_OUTSIDE. |
| 135 |
*/ |
| 136 |
void gluQuadricOrientation( GLUquadricObj *quadObject, GLenum orientation ) |
| 137 |
{ |
| 138 |
if (quadObject && (orientation==GLU_INSIDE || orientation==GLU_OUTSIDE)) { |
| 139 |
quadObject->Orientation = orientation; |
| 140 |
} |
| 141 |
else { |
| 142 |
quadric_error( quadObject, GLU_INVALID_ENUM, "qluQuadricOrientation" ); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
/* |
| 149 |
* Set the error handler callback function. |
| 150 |
*/ |
| 151 |
void gluQuadricCallback( GLUquadricObj *qobj, |
| 152 |
GLenum which, void (*fn)(GLenum) ) |
| 153 |
{ |
| 154 |
if (qobj && which==GLU_ERROR) { |
| 155 |
qobj->ErrorFunc = fn; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
void gluQuadricNormals( GLUquadricObj *quadObject, GLenum normals ) |
| 161 |
{ |
| 162 |
if (quadObject |
| 163 |
&& (normals==GLU_NONE || normals==GLU_FLAT || normals==GLU_SMOOTH)) { |
| 164 |
quadObject->Normals = normals; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
void gluQuadricTexture( GLUquadricObj *quadObject, |
| 170 |
GLboolean textureCoords ) |
| 171 |
{ |
| 172 |
if (quadObject) { |
| 173 |
quadObject->TextureFlag = textureCoords; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
/* |
| 181 |
* Call glNormal3f after scaling normal to unit length. |
| 182 |
*/ |
| 183 |
static void normal3f( GLfloat x, GLfloat y, GLfloat z ) |
| 184 |
{ |
| 185 |
GLdouble mag; |
| 186 |
|
| 187 |
mag = sqrt( x*x + y*y + z*z ); |
| 188 |
if (mag>0.00001F) { |
| 189 |
x /= mag; |
| 190 |
y /= mag; |
| 191 |
z /= mag; |
| 192 |
} |
| 193 |
glNormal3f( x, y, z ); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
void gluCylinder( GLUquadricObj *qobj, |
| 199 |
GLdouble baseRadius, GLdouble topRadius, GLdouble height, |
| 200 |
GLint slices, GLint stacks ) |
| 201 |
{ |
| 202 |
GLdouble da, r, dr, dz; |
| 203 |
GLfloat x, y, z, nz, nsign; |
| 204 |
GLint i, j; |
| 205 |
|
| 206 |
if (qobj->Orientation==GLU_INSIDE) { |
| 207 |
nsign = -1.0; |
| 208 |
} |
| 209 |
else { |
| 210 |
nsign = 1.0; |
| 211 |
} |
| 212 |
|
| 213 |
da = 2.0*M_PI / slices; |
| 214 |
dr = (topRadius-baseRadius) / stacks; |
| 215 |
dz = height / stacks; |
| 216 |
nz = (baseRadius-topRadius) / height; /* Z component of normal vectors */ |
| 217 |
|
| 218 |
if (qobj->DrawStyle==GLU_POINT) { |
| 219 |
glBegin( GL_POINTS ); |
| 220 |
for (i=0;i<slices;i++) { |
| 221 |
x = cos(i*da); |
| 222 |
y = sin(i*da); |
| 223 |
normal3f( x*nsign, y*nsign, nz*nsign ); |
| 224 |
|
| 225 |
z = 0.0; |
| 226 |
r = baseRadius; |
| 227 |
for (j=0;j<=stacks;j++) { |
| 228 |
glVertex3f( x*r, y*r, z ); |
| 229 |
z += dz; |
| 230 |
r += dr; |
| 231 |
} |
| 232 |
} |
| 233 |
glEnd(); |
| 234 |
} |
| 235 |
else if (qobj->DrawStyle==GLU_LINE || qobj->DrawStyle==GLU_SILHOUETTE) { |
| 236 |
/* Draw rings */ |
| 237 |
if (qobj->DrawStyle==GLU_LINE) { |
| 238 |
z = 0.0; |
| 239 |
r = baseRadius; |
| 240 |
for (j=0;j<=stacks;j++) { |
| 241 |
glBegin( GL_LINE_LOOP ); |
| 242 |
for (i=0;i<slices;i++) { |
| 243 |
x = cos(i*da); |
| 244 |
y = sin(i*da); |
| 245 |
normal3f( x*nsign, y*nsign, nz*nsign ); |
| 246 |
glVertex3f( x*r, y*r, z ); |
| 247 |
} |
| 248 |
glEnd(); |
| 249 |
z += dz; |
| 250 |
r += dr; |
| 251 |
} |
| 252 |
} |
| 253 |
else { |
| 254 |
/* draw one ring at each end */ |
| 255 |
if (baseRadius!=0.0) { |
| 256 |
glBegin( GL_LINE_LOOP ); |
| 257 |
for (i=0;i<slices;i++) { |
| 258 |
x = cos(i*da); |
| 259 |
y = sin(i*da); |
| 260 |
normal3f( x*nsign, y*nsign, nz*nsign ); |
| 261 |
glVertex3f( x*baseRadius, y*baseRadius, 0.0 ); |
| 262 |
} |
| 263 |
glEnd(); |
| 264 |
glBegin( GL_LINE_LOOP ); |
| 265 |
for (i=0;i<slices;i++) { |
| 266 |
x = cos(i*da); |
| 267 |
y = sin(i*da); |
| 268 |
normal3f( x*nsign, y*nsign, nz*nsign ); |
| 269 |
glVertex3f( x*topRadius, y*topRadius, height ); |
| 270 |
} |
| 271 |
glEnd(); |
| 272 |
} |
| 273 |
} |
| 274 |
/* draw length lines */ |
| 275 |
glBegin( GL_LINES ); |
| 276 |
for (i=0;i<slices;i++) { |
| 277 |
x = cos(i*da); |
| 278 |
y = sin(i*da); |
| 279 |
normal3f( x*nsign, y*nsign, nz*nsign ); |
| 280 |
glVertex3f( x*baseRadius, y*baseRadius, 0.0 ); |
| 281 |
glVertex3f( x*topRadius, y*topRadius, height ); |
| 282 |
} |
| 283 |
glEnd(); |
| 284 |
} |
| 285 |
else if (qobj->DrawStyle==GLU_FILL) { |
| 286 |
GLfloat du = 1.0 / slices; |
| 287 |
GLfloat dv = 1.0 / stacks; |
| 288 |
GLfloat tcx = 0.0, tcy = 0.0; |
| 289 |
|
| 290 |
for (i=0;i<slices;i++) { |
| 291 |
GLfloat x1 = -sin(i*da); |
| 292 |
GLfloat y1 = cos(i*da); |
| 293 |
GLfloat x2 = -sin((i+1)*da); |
| 294 |
GLfloat y2 = cos((i+1)*da); |
| 295 |
z = 0.0; |
| 296 |
r = baseRadius; |
| 297 |
tcy = 0.0; |
| 298 |
glBegin( GL_QUAD_STRIP ); |
| 299 |
for (j=0;j<=stacks;j++) { |
| 300 |
if (nsign==1.0) { |
| 301 |
normal3f( x1*nsign, y1*nsign, nz*nsign ); |
| 302 |
TXTR_COORD(tcx, tcy); |
| 303 |
glVertex3f( x1*r, y1*r, z ); |
| 304 |
normal3f( x2*nsign, y2*nsign, nz*nsign ); |
| 305 |
TXTR_COORD(tcx+du, tcy); |
| 306 |
glVertex3f( x2*r, y2*r, z ); |
| 307 |
} |
| 308 |
else { |
| 309 |
normal3f( x2*nsign, y2*nsign, nz*nsign ); |
| 310 |
TXTR_COORD(tcx, tcy); |
| 311 |
glVertex3f( x2*r, y2*r, z ); |
| 312 |
normal3f( x1*nsign, y1*nsign, nz*nsign ); |
| 313 |
TXTR_COORD(tcx+du, tcy); |
| 314 |
glVertex3f( x1*r, y1*r, z ); |
| 315 |
} |
| 316 |
z += dz; |
| 317 |
r += dr; |
| 318 |
tcy += dv; |
| 319 |
} |
| 320 |
glEnd(); |
| 321 |
tcx += du; |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
void gluSphere( GLUquadricObj *qobj, |
| 331 |
GLdouble radius, GLint slices, GLint stacks ) |
| 332 |
{ |
| 333 |
GLfloat rho, drho, theta, dtheta; |
| 334 |
GLfloat x, y, z; |
| 335 |
GLfloat s, t, ds, dt; |
| 336 |
GLint i, j, imin, imax; |
| 337 |
GLboolean normals; |
| 338 |
GLfloat nsign; |
| 339 |
|
| 340 |
if (qobj->Normals==GLU_NONE) { |
| 341 |
normals = GL_FALSE; |
| 342 |
} |
| 343 |
else { |
| 344 |
normals = GL_TRUE; |
| 345 |
} |
| 346 |
if (qobj->Orientation==GLU_INSIDE) { |
| 347 |
nsign = -1.0; |
| 348 |
} |
| 349 |
else { |
| 350 |
nsign = 1.0; |
| 351 |
} |
| 352 |
|
| 353 |
drho = M_PI / (GLfloat) stacks; |
| 354 |
dtheta = 2.0 * M_PI / (GLfloat) slices; |
| 355 |
|
| 356 |
/* texturing: s goes from 0.0/0.25/0.5/0.75/1.0 at +y/+x/-y/-x/+y axis */ |
| 357 |
/* t goes from -1.0/+1.0 at z = -radius/+radius (linear along longitudes) */ |
| 358 |
/* cannot use triangle fan on texturing (s coord. at top/bottom tip varies) */ |
| 359 |
|
| 360 |
if (qobj->DrawStyle==GLU_FILL) { |
| 361 |
if (!qobj->TextureFlag) { |
| 362 |
/* draw +Z end as a triangle fan */ |
| 363 |
glBegin( GL_TRIANGLE_FAN ); |
| 364 |
glNormal3f( 0.0, 0.0, 1.0 ); |
| 365 |
TXTR_COORD(0.5,1.0); |
| 366 |
glVertex3f( 0.0, 0.0, nsign * radius ); |
| 367 |
for (j=0;j<=slices;j++) { |
| 368 |
theta = (j==slices) ? 0.0 : j * dtheta; |
| 369 |
x = -sin(theta) * sin(drho); |
| 370 |
y = cos(theta) * sin(drho); |
| 371 |
z = nsign * cos(drho); |
| 372 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 373 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 374 |
} |
| 375 |
glEnd(); |
| 376 |
} |
| 377 |
|
| 378 |
ds = 1.0 / slices; |
| 379 |
dt = 1.0 / stacks; |
| 380 |
t = 1.0; /* because loop now runs from 0 */ |
| 381 |
if (qobj->TextureFlag) { |
| 382 |
imin = 0; |
| 383 |
imax = stacks; |
| 384 |
} |
| 385 |
else { |
| 386 |
imin = 1; |
| 387 |
imax = stacks-1; |
| 388 |
} |
| 389 |
|
| 390 |
/* draw intermediate stacks as quad strips */ |
| 391 |
for (i=imin;i<imax;i++) { |
| 392 |
rho = i * drho; |
| 393 |
glBegin( GL_QUAD_STRIP ); |
| 394 |
s = 0.0; |
| 395 |
for (j=0;j<=slices;j++) { |
| 396 |
theta = (j==slices) ? 0.0 : j * dtheta; |
| 397 |
x = -sin(theta) * sin(rho); |
| 398 |
y = cos(theta) * sin(rho); |
| 399 |
z = nsign * cos(rho); |
| 400 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 401 |
TXTR_COORD(s,t); |
| 402 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 403 |
x = -sin(theta) * sin(rho+drho); |
| 404 |
y = cos(theta) * sin(rho+drho); |
| 405 |
z = nsign * cos(rho+drho); |
| 406 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 407 |
TXTR_COORD(s,t-dt); |
| 408 |
s += ds; |
| 409 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 410 |
} |
| 411 |
glEnd(); |
| 412 |
t -= dt; |
| 413 |
} |
| 414 |
|
| 415 |
if (!qobj->TextureFlag) { |
| 416 |
/* draw -Z end as a triangle fan */ |
| 417 |
glBegin( GL_TRIANGLE_FAN ); |
| 418 |
glNormal3f( 0.0, 0.0, -1.0 ); |
| 419 |
TXTR_COORD(0.5,0.0); |
| 420 |
glVertex3f( 0.0, 0.0, -radius*nsign ); |
| 421 |
rho = M_PI - drho; |
| 422 |
s = 1.0; |
| 423 |
t = dt; |
| 424 |
for (j=slices;j>=0;j--) { |
| 425 |
theta = (j==slices) ? 0.0 : j * dtheta; |
| 426 |
x = -sin(theta) * sin(rho); |
| 427 |
y = cos(theta) * sin(rho); |
| 428 |
z = nsign * cos(rho); |
| 429 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 430 |
TXTR_COORD(s,t); |
| 431 |
s -= ds; |
| 432 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 433 |
} |
| 434 |
glEnd(); |
| 435 |
} |
| 436 |
} |
| 437 |
else if (qobj->DrawStyle==GLU_LINE || qobj->DrawStyle==GLU_SILHOUETTE) { |
| 438 |
/* draw stack lines */ |
| 439 |
for (i=1;i<stacks;i++) { /* stack line at i==stacks-1 was missing here */ |
| 440 |
rho = i * drho; |
| 441 |
glBegin( GL_LINE_LOOP ); |
| 442 |
for (j=0;j<slices;j++) { |
| 443 |
theta = j * dtheta; |
| 444 |
x = cos(theta) * sin(rho); |
| 445 |
y = sin(theta) * sin(rho); |
| 446 |
z = cos(rho); |
| 447 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 448 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 449 |
} |
| 450 |
glEnd(); |
| 451 |
} |
| 452 |
/* draw slice lines */ |
| 453 |
for (j=0;j<slices;j++) { |
| 454 |
theta = j * dtheta; |
| 455 |
glBegin( GL_LINE_STRIP ); |
| 456 |
for (i=0;i<=stacks;i++) { |
| 457 |
rho = i * drho; |
| 458 |
x = cos(theta) * sin(rho); |
| 459 |
y = sin(theta) * sin(rho); |
| 460 |
z = cos(rho); |
| 461 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 462 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 463 |
} |
| 464 |
glEnd(); |
| 465 |
} |
| 466 |
} |
| 467 |
else if (qobj->DrawStyle==GLU_POINT) { |
| 468 |
/* top and bottom-most points */ |
| 469 |
glBegin( GL_POINTS ); |
| 470 |
if (normals) glNormal3f( 0.0, 0.0, nsign ); |
| 471 |
glVertex3d( 0.0, 0.0, radius ); |
| 472 |
if (normals) glNormal3f( 0.0, 0.0, -nsign ); |
| 473 |
glVertex3d( 0.0, 0.0, -radius ); |
| 474 |
|
| 475 |
/* loop over stacks */ |
| 476 |
for (i=1;i<stacks-1;i++) { |
| 477 |
rho = i * drho; |
| 478 |
for (j=0;j<slices;j++) { |
| 479 |
theta = j * dtheta; |
| 480 |
x = cos(theta) * sin(rho); |
| 481 |
y = sin(theta) * sin(rho); |
| 482 |
z = cos(rho); |
| 483 |
if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); |
| 484 |
glVertex3f( x*radius, y*radius, z*radius ); |
| 485 |
} |
| 486 |
} |
| 487 |
glEnd(); |
| 488 |
} |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
void gluDisk( GLUquadricObj *qobj, |
| 495 |
GLdouble innerRadius, GLdouble outerRadius, |
| 496 |
GLint slices, GLint loops ) |
| 497 |
{ |
| 498 |
GLdouble a, da; |
| 499 |
GLfloat r, dr; |
| 500 |
GLfloat x, y; |
| 501 |
GLfloat r1, r2, dtc; |
| 502 |
GLint s, l; |
| 503 |
|
| 504 |
/* Normal vectors */ |
| 505 |
if (qobj->Normals!=GLU_NONE) { |
| 506 |
if (qobj->Orientation==GLU_OUTSIDE) { |
| 507 |
glNormal3f( 0.0, 0.0, +1.0 ); |
| 508 |
} |
| 509 |
else { |
| 510 |
glNormal3f( 0.0, 0.0, -1.0 ); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
da = 2.0*M_PI / slices; |
| 515 |
dr = (outerRadius-innerRadius) / (GLfloat) loops; |
| 516 |
|
| 517 |
/* texture of a gluDisk is a cut out of the texture unit square */ |
| 518 |
/* x, y in [-outerRadius, +outerRadius]; s, t in [0, 1] (linear mapping) */ |
| 519 |
dtc = 2.0f * outerRadius; |
| 520 |
|
| 521 |
switch (qobj->DrawStyle) { |
| 522 |
case GLU_FILL: |
| 523 |
{ |
| 524 |
GLfloat sa,ca; |
| 525 |
r1 = innerRadius; |
| 526 |
for (l=0;l<loops;l++) { |
| 527 |
r2 = r1 + dr; |
| 528 |
if (qobj->Orientation==GLU_OUTSIDE) { |
| 529 |
glBegin( GL_QUAD_STRIP ); |
| 530 |
for (s=0;s<=slices;s++) { |
| 531 |
if (s==slices) a = 0.0; |
| 532 |
else a = s * da; |
| 533 |
sa = sin(a); ca = cos(a); |
| 534 |
TXTR_COORD(0.5+sa*r2/dtc,0.5+ca*r2/dtc); |
| 535 |
glVertex2f( r2*sa, r2*ca ); |
| 536 |
TXTR_COORD(0.5+sa*r1/dtc,0.5+ca*r1/dtc); |
| 537 |
glVertex2f( r1*sa, r1*ca ); |
| 538 |
} |
| 539 |
glEnd(); |
| 540 |
} |
| 541 |
else { |
| 542 |
glBegin( GL_QUAD_STRIP ); |
| 543 |
for (s=slices;s>=0;s--) { |
| 544 |
if (s==slices) a = 0.0; |
| 545 |
else a = s * da; |
| 546 |
sa = sin(a); ca = cos(a); |
| 547 |
TXTR_COORD(0.5-sa*r2/dtc,0.5+ca*r2/dtc); |
| 548 |
glVertex2f( r2*sa, r2*ca ); |
| 549 |
TXTR_COORD(0.5-sa*r1/dtc,0.5+ca*r1/dtc); |
| 550 |
glVertex2f( r1*sa, r1*ca ); |
| 551 |
} |
| 552 |
glEnd(); |
| 553 |
} |
| 554 |
r1 = r2; |
| 555 |
} |
| 556 |
} |
| 557 |
break; |
| 558 |
case GLU_LINE: |
| 559 |
/* draw rings */ |
| 560 |
for (r=innerRadius; r<=outerRadius; r+=dr) { |
| 561 |
glBegin( GL_LINE_LOOP ); |
| 562 |
for (a=0.0; a<2.0*M_PI; a+=da) { |
| 563 |
glVertex2f( r*sin(a), r*cos(a) ); |
| 564 |
} |
| 565 |
glEnd(); |
| 566 |
} |
| 567 |
/* draw spokes */ |
| 568 |
for (a=0.0; a<2.0*M_PI; a+=da) { |
| 569 |
x = sin(a); |
| 570 |
y = cos(a); |
| 571 |
glBegin( GL_LINE_STRIP ); |
| 572 |
for (r=innerRadius; r<=outerRadius; r+=dr) { |
| 573 |
glVertex2f( r*x, r*y ); |
| 574 |
} |
| 575 |
glEnd(); |
| 576 |
} |
| 577 |
break; |
| 578 |
case GLU_POINT: |
| 579 |
glBegin( GL_POINTS ); |
| 580 |
for (a=0.0; a<2.0*M_PI; a+=da) { |
| 581 |
x = sin(a); |
| 582 |
y = cos(a); |
| 583 |
for (r=innerRadius; r<=outerRadius; r+=dr) { |
| 584 |
glVertex2f( r*x, r*y ); |
| 585 |
} |
| 586 |
} |
| 587 |
glEnd(); |
| 588 |
break; |
| 589 |
case GLU_SILHOUETTE: |
| 590 |
if (innerRadius!=0.0) { |
| 591 |
glBegin( GL_LINE_LOOP ); |
| 592 |
for (a=0.0; a<2.0*M_PI; a+=da) { |
| 593 |
x = innerRadius * sin(a); |
| 594 |
y = innerRadius * cos(a); |
| 595 |
glVertex2f( x, y ); |
| 596 |
} |
| 597 |
glEnd(); |
| 598 |
} |
| 599 |
glBegin( GL_LINE_LOOP ); |
| 600 |
for (a=0; a<2.0*M_PI; a+=da) { |
| 601 |
x = outerRadius * sin(a); |
| 602 |
y = outerRadius * cos(a); |
| 603 |
glVertex2f( x, y ); |
| 604 |
} |
| 605 |
glEnd(); |
| 606 |
break; |
| 607 |
default: |
| 608 |
abort(); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
void gluPartialDisk( GLUquadricObj *qobj, GLdouble innerRadius, |
| 615 |
GLdouble outerRadius, GLint slices, GLint loops, |
| 616 |
GLdouble startAngle, GLdouble sweepAngle ) |
| 617 |
{ |
| 618 |
if (qobj->Normals!=GLU_NONE) { |
| 619 |
if (qobj->Orientation==GLU_OUTSIDE) { |
| 620 |
glNormal3f( 0.0, 0.0, +1.0 ); |
| 621 |
} |
| 622 |
else { |
| 623 |
glNormal3f( 0.0, 0.0, -1.0 ); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
if (qobj->DrawStyle==GLU_POINT) { |
| 628 |
GLint loop, slice; |
| 629 |
GLdouble radius, delta_radius; |
| 630 |
GLdouble angle, delta_angle; |
| 631 |
delta_radius = (outerRadius - innerRadius) / (loops-1); |
| 632 |
delta_angle = DEG_TO_RAD((sweepAngle) / (slices-1)); |
| 633 |
glBegin( GL_POINTS ); |
| 634 |
radius = innerRadius; |
| 635 |
for (loop=0; loop<loops; loop++) { |
| 636 |
angle = DEG_TO_RAD(startAngle); |
| 637 |
for (slice=0; slice<slices; slice++) { |
| 638 |
glVertex2d( radius * sin(angle), radius * cos(angle) ); |
| 639 |
angle += delta_angle; |
| 640 |
} |
| 641 |
radius += delta_radius; |
| 642 |
} |
| 643 |
glEnd(); |
| 644 |
} |
| 645 |
else if (qobj->DrawStyle==GLU_LINE) { |
| 646 |
GLint loop, slice; |
| 647 |
GLdouble radius, delta_radius; |
| 648 |
GLdouble angle, delta_angle; |
| 649 |
delta_radius = (outerRadius - innerRadius) / loops; |
| 650 |
delta_angle = DEG_TO_RAD(sweepAngle / slices); |
| 651 |
/* draw rings */ |
| 652 |
radius = innerRadius; |
| 653 |
for (loop=0; loop<loops; loop++) { |
| 654 |
angle = DEG_TO_RAD(startAngle); |
| 655 |
glBegin( GL_LINE_STRIP ); |
| 656 |
for (slice=0; slice<slices; slice++) { |
| 657 |
glVertex2d( radius * sin(angle), radius * cos(angle) ); |
| 658 |
angle += delta_angle; |
| 659 |
} |
| 660 |
glEnd(); |
| 661 |
radius += delta_radius; |
| 662 |
} |
| 663 |
/* draw spokes */ |
| 664 |
angle = DEG_TO_RAD(startAngle); |
| 665 |
for (slice=0; slice<slices; slice++) { |
| 666 |
radius = innerRadius; |
| 667 |
glBegin( GL_LINE_STRIP ); |
| 668 |
for (loop=0; loop<loops; loop++) { |
| 669 |
glVertex2d( radius * sin(angle), radius * cos(angle) ); |
| 670 |
radius += delta_radius; |
| 671 |
} |
| 672 |
glEnd(); |
| 673 |
angle += delta_angle; |
| 674 |
} |
| 675 |
} |
| 676 |
else if (qobj->DrawStyle==GLU_SILHOUETTE) { |
| 677 |
GLint slice; |
| 678 |
GLdouble angle, delta_angle; |
| 679 |
delta_angle = DEG_TO_RAD(sweepAngle / slices); |
| 680 |
/* draw outer ring */ |
| 681 |
glBegin( GL_LINE_STRIP ); |
| 682 |
angle = DEG_TO_RAD(startAngle); |
| 683 |
for (slice=0; slice<=slices; slice++) { |
| 684 |
glVertex2d( outerRadius * sin(angle), outerRadius * cos(angle) ); |
| 685 |
angle += delta_angle; |
| 686 |
} |
| 687 |
glEnd(); |
| 688 |
/* draw inner ring */ |
| 689 |
if (innerRadius>0.0) { |
| 690 |
glBegin( GL_LINE_STRIP ); |
| 691 |
angle = DEG_TO_RAD(startAngle); |
| 692 |
for (slice=0; slice<slices; slice++) { |
| 693 |
glVertex2d( innerRadius * sin(angle), innerRadius * cos(angle) ); |
| 694 |
angle += delta_angle; |
| 695 |
} |
| 696 |
glEnd(); |
| 697 |
} |
| 698 |
/* draw spokes */ |
| 699 |
if (sweepAngle<360.0) { |
| 700 |
GLdouble stopAngle = startAngle + sweepAngle; |
| 701 |
glBegin( GL_LINES ); |
| 702 |
glVertex2d( innerRadius*SIND(startAngle), innerRadius*COSD(startAngle) ); |
| 703 |
glVertex2d( outerRadius*SIND(startAngle), outerRadius*COSD(startAngle) ); |
| 704 |
glVertex2d( innerRadius*SIND(stopAngle), innerRadius*COSD(stopAngle) ); |
| 705 |
glVertex2d( outerRadius*SIND(stopAngle), outerRadius*COSD(stopAngle) ); |
| 706 |
glEnd(); |
| 707 |
} |
| 708 |
} |
| 709 |
else if (qobj->DrawStyle==GLU_FILL) { |
| 710 |
GLint loop, slice; |
| 711 |
GLdouble radius, delta_radius; |
| 712 |
GLdouble angle, delta_angle; |
| 713 |
delta_radius = (outerRadius - innerRadius) / loops; |
| 714 |
delta_angle = DEG_TO_RAD(sweepAngle / slices); |
| 715 |
radius = innerRadius; |
| 716 |
for (loop=0; loop<loops; loop++) { |
| 717 |
glBegin( GL_QUAD_STRIP ); |
| 718 |
angle = DEG_TO_RAD(startAngle); |
| 719 |
for (slice=0; slice<slices; slice++) { |
| 720 |
if (qobj->Orientation==GLU_OUTSIDE) { |
| 721 |
glVertex2d( (radius+delta_radius)*sin(angle), |
| 722 |
(radius+delta_radius)*cos(angle) ); |
| 723 |
glVertex2d( radius * sin(angle), radius * cos(angle) ); |
| 724 |
} |
| 725 |
else { |
| 726 |
glVertex2d( radius * sin(angle), radius * cos(angle) ); |
| 727 |
glVertex2d( (radius+delta_radius)*sin(angle), |
| 728 |
(radius+delta_radius)*cos(angle) ); |
| 729 |
} |
| 730 |
angle += delta_angle; |
| 731 |
} |
| 732 |
glEnd(); |
| 733 |
radius += delta_radius; |
| 734 |
} |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|