--- ray/src/common/rglsurf.c 1998/06/17 16:45:08 3.2 +++ ray/src/common/rglsurf.c 2003/05/25 15:41:31 3.9 @@ -1,13 +1,12 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rglsurf.c,v 3.9 2003/05/25 15:41:31 greg Exp $"; #endif - /* * Convert Radiance -> OpenGL surfaces. */ +#include "copyright.h" + #include "radogl.h" #ifndef NSLICES @@ -29,6 +28,7 @@ static char *glu_rout = "unk"; /* active GLU routine * #define NOPOLY() if (curpolysize) {glEnd(); curpolysize = 0;} else +void setmaterial(mp, cent, ispoly) /* prepare for new material */ register MATREC *mp; FVECT cent; @@ -80,7 +80,7 @@ register FVECT v[]; /* vertex list */ } -static +static void glu_error(en) /* report an error as a warning */ GLenum en; { @@ -89,6 +89,23 @@ GLenum en; } +static void +myCombine(coords, vertex_data, weight, dataOut) +register GLdouble coords[3]; +GLdouble *vertex_data[4]; +GLfloat weight[4]; +GLdouble **dataOut; +{ + register GLdouble *newvert; + + newvert = (GLdouble *)malloc(3*sizeof(GLdouble)); + if (newvert == NULL) + error(SYSTEM, "out of memory in myCombine"); + VCOPY(newvert, coords); /* no data, just coordinates */ + *dataOut = newvert; +} + + static newtess() /* allocate GLU tessellation object */ { @@ -97,6 +114,7 @@ newtess() /* allocate GLU tessellation object */ gluTessCallback(gluto, GLU_TESS_BEGIN, glBegin); gluTessCallback(gluto, GLU_TESS_VERTEX, glVertex3dv); gluTessCallback(gluto, GLU_TESS_END, glEnd); + gluTessCallback(gluto, GLU_TESS_COMBINE, myCombine); gluTessCallback(gluto, GLU_TESS_ERROR, glu_error); gluTessProperty(gluto, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); } @@ -112,6 +130,7 @@ newquadric() /* allocate GLU quadric structure */ } +int o_face(o) /* convert a face */ register OBJREC *o; { @@ -123,10 +142,10 @@ register OBJREC *o; objerror(o, USER, "bad # real arguments"); area = polyarea(cent, norm, o->oargs.nfargs/3, (FVECT *)o->oargs.farg); if (area <= FTINY) - return; + return(0); if (dolights) /* check for source */ - doflatsrc(o->os, cent, norm, area); - setmaterial(o->os, cent, 1); /* set material */ + doflatsrc((MATREC *)o->os, cent, norm, area); + setmaterial((MATREC *)o->os, cent, 1); /* set material */ if (o->oargs.nfargs/3 != curpolysize) { if (curpolysize) glEnd(); curpolysize = o->oargs.nfargs/3; @@ -158,9 +177,11 @@ register OBJREC *o; (GLdouble)o->oargs.farg[3*i+1], (GLdouble)o->oargs.farg[3*i+2]); } + return(0); } +void surfclean() /* clean up surface routines */ { setmaterial(NULL, NULL, 0); @@ -176,6 +197,7 @@ surfclean() /* clean up surface routines */ } +int o_sphere(o) /* convert a sphere */ register OBJREC *o; { @@ -186,11 +208,11 @@ register OBJREC *o; o->otype = o->otype==OBJ_SPHERE ? OBJ_BUBBLE : OBJ_SPHERE; o->oargs.farg[3] = -o->oargs.farg[3]; } else if (o->oargs.farg[3] <= FTINY) - return; + return(0); if (dolights) - dosphsrc(o->os, o->oargs.farg, + dosphsrc((MATREC *)o->os, o->oargs.farg, PI*o->oargs.farg[3]*o->oargs.farg[3]); - setmaterial(o->os, o->oargs.farg, 0); + setmaterial((MATREC *)o->os, o->oargs.farg, 0); if (gluqo == NULL) newquadric(); glu_rout = "making sphere"; gluQuadricOrientation(gluqo, @@ -202,9 +224,11 @@ register OBJREC *o; (GLdouble)o->oargs.farg[2]); gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS); glPopMatrix(); + return(0); } +int o_cone(o) /* convert a cone or cylinder */ register OBJREC *o; { @@ -214,7 +238,7 @@ register OBJREC *o; iscyl = o->otype==OBJ_CYLINDER | o->otype==OBJ_TUBE; if (o->oargs.nfargs != (iscyl ? 7 : 8)) - objerror(o, "bad # real arguments"); + objerror(o, USER, "bad # real arguments"); if (o->oargs.farg[6] < -FTINY) { o->oargs.farg[6] = -o->oargs.farg[6]; if (iscyl) @@ -229,14 +253,19 @@ register OBJREC *o; objerror(o, USER, "illegal radii"); if (o->oargs.farg[6] <= FTINY && (iscyl || o->oargs.farg[7] <= FTINY)) return; - if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ - o->oargs.farg[6] = 0.; - if (!iscyl && o->oargs.farg[7] < 0.) - o->oargs.farg[7] = 0.; + if (!iscyl) { + if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ + o->oargs.farg[6] = 0.; + if (o->oargs.farg[7] < 0.) + o->oargs.farg[7] = 0.; + } + h = sqrt(dist2(o->oargs.farg,o->oargs.farg+3)); + if (h <= FTINY) + return; cent[0] = .5*(o->oargs.farg[0] + o->oargs.farg[3]); cent[1] = .5*(o->oargs.farg[1] + o->oargs.farg[4]); cent[2] = .5*(o->oargs.farg[2] + o->oargs.farg[5]); - setmaterial(o->os, cent, 0); + setmaterial((MATREC *)o->os, cent, 0); if (gluqo == NULL) newquadric(); glu_rout = "making cylinder"; gluQuadricOrientation(gluqo, o->otype==OBJ_CUP | o->otype==OBJ_TUBE ? @@ -248,13 +277,14 @@ register OBJREC *o; glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1], (GLdouble)o->oargs.farg[2]); /* compute height & rotation angle */ - h = sqrt(dist2(o->oargs.farg,o->oargs.farg+3)); - if (h <= FTINY) - return; x1 = o->oargs.farg[1] - o->oargs.farg[4]; y1 = o->oargs.farg[3] - o->oargs.farg[0]; /* z1 = 0; */ - d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / h); + d = x1*x1 + y1*y1; + if (d <= FTINY*FTINY) + x1 = 1.; + else + d = 180./PI * asin(sqrt(d) / h); if (o->oargs.farg[5] < o->oargs.farg[2]) d = 180. - d; if (d > FTINY) @@ -262,16 +292,18 @@ register OBJREC *o; gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7], h, NSLICES, 1); glPopMatrix(); + return(0); } +int o_ring(o) /* convert a ring */ register OBJREC *o; { - double x1, y1, d; + double x1, y1, d, h; if (o->oargs.nfargs != 8) - objerror(o, "bad # real arguments"); + objerror(o, USER, "bad # real arguments"); if (o->oargs.farg[7] < o->oargs.farg[6]) { register double d = o->oargs.farg[7]; o->oargs.farg[7] = o->oargs.farg[6]; @@ -283,11 +315,14 @@ register OBJREC *o; o->oargs.farg[6] = 0.; if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY) return; + h = VLEN(o->oargs.farg+3); + if (h <= FTINY) + return; if (dolights) - doflatsrc(o->os, o->oargs.farg, o->oargs.farg+3, + doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3, PI*(o->oargs.farg[7]*o->oargs.farg[7] - o->oargs.farg[6]*o->oargs.farg[6])); - setmaterial(o->os, o->oargs.farg, 0); + setmaterial((MATREC *)o->os, o->oargs.farg, 0); if (gluqo == NULL) newquadric(); glu_rout = "making disk"; gluQuadricOrientation(gluqo, GLU_OUTSIDE); @@ -297,17 +332,19 @@ register OBJREC *o; glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1], (GLdouble)o->oargs.farg[2]); /* compute rotation angle */ - d = VLEN(o->oargs.farg+3); - if (d <= FTINY) - return; x1 = -o->oargs.farg[4]; y1 = o->oargs.farg[3]; /* z1 = 0; */ - d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / d); + d = x1*x1 + y1*y1; + if (d <= FTINY*FTINY) + x1 = 1.; + else + d = 180./PI * asin(sqrt(d) / h); if (o->oargs.farg[5] < 0.) d = 180. - d; if (d > FTINY) glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.); gluDisk(gluqo, o->oargs.farg[6], o->oargs.farg[7], NSLICES, 1); glPopMatrix(); + return(0); }