--- ray/src/common/rglsurf.c 2003/03/27 04:16:33 3.6 +++ ray/src/common/rglsurf.c 2003/11/14 17:22:06 3.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rglsurf.c,v 3.6 2003/03/27 04:16:33 greg Exp $"; +static const char RCSid[] = "$Id: rglsurf.c,v 3.11 2003/11/14 17:22:06 schorsch Exp $"; #endif /* * Convert Radiance -> OpenGL surfaces. @@ -37,8 +37,9 @@ int ispoly; if (mp != curmat && domats) { NOPOLY(); domatobj(curmat = mp, cent); - } else if (!ispoly) + } else if (!ispoly) { NOPOLY(); + } } @@ -106,7 +107,7 @@ GLdouble **dataOut; } -static +static void newtess() /* allocate GLU tessellation object */ { if ((gluto = gluNewTess()) == NULL) @@ -120,7 +121,7 @@ newtess() /* allocate GLU tessellation object */ } -static +static void newquadric() /* allocate GLU quadric structure */ { if ((gluqo = gluNewQuadric()) == NULL) @@ -138,11 +139,11 @@ register OBJREC *o; FVECT norm, cent; register int i; - if (o->oargs.nfargs < 9 | o->oargs.nfargs % 3) + if ((o->oargs.nfargs < 9) | (o->oargs.nfargs % 3)) 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((MATREC *)o->os, cent, norm, area); setmaterial((MATREC *)o->os, cent, 1); /* set material */ @@ -177,6 +178,7 @@ register OBJREC *o; (GLdouble)o->oargs.farg[3*i+1], (GLdouble)o->oargs.farg[3*i+2]); } + return(0); } @@ -207,7 +209,7 @@ 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((MATREC *)o->os, o->oargs.farg, PI*o->oargs.farg[3]*o->oargs.farg[3]); @@ -223,6 +225,7 @@ register OBJREC *o; (GLdouble)o->oargs.farg[2]); gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS); glPopMatrix(); + return(0); } @@ -234,7 +237,7 @@ register OBJREC *o; FVECT cent; register int iscyl; - iscyl = o->otype==OBJ_CYLINDER | o->otype==OBJ_TUBE; + iscyl = (o->otype==OBJ_CYLINDER) | (o->otype==OBJ_TUBE); if (o->oargs.nfargs != (iscyl ? 7 : 8)) objerror(o, USER, "bad # real arguments"); if (o->oargs.farg[6] < -FTINY) { @@ -250,20 +253,23 @@ register OBJREC *o; } else if (!iscyl && o->oargs.farg[7] < -FTINY) objerror(o, USER, "illegal radii"); if (o->oargs.farg[6] <= FTINY && (iscyl || o->oargs.farg[7] <= FTINY)) - return; + return; /* XXX we should return a value here */ 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; /* XXX we should return a value here */ 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((MATREC *)o->os, cent, 0); if (gluqo == NULL) newquadric(); glu_rout = "making cylinder"; - gluQuadricOrientation(gluqo, o->otype==OBJ_CUP | o->otype==OBJ_TUBE ? + gluQuadricOrientation(gluqo, (o->otype==OBJ_CUP) | (o->otype==OBJ_TUBE) ? GLU_INSIDE : GLU_OUTSIDE); gluQuadricNormals(gluqo, GLU_SMOOTH); glMatrixMode(GL_MODELVIEW); @@ -272,13 +278,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) @@ -286,6 +293,7 @@ register OBJREC *o; gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7], h, NSLICES, 1); glPopMatrix(); + return(0); } @@ -293,7 +301,7 @@ 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, USER, "bad # real arguments"); @@ -307,7 +315,10 @@ register OBJREC *o; if (o->oargs.farg[6] < 0.) /* complains for tiny neg's */ o->oargs.farg[6] = 0.; if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY) - return; + return; /* XXX we should return a value here */ + h = VLEN(o->oargs.farg+3); + if (h <= FTINY) + return; /* XXX we should return a value here */ if (dolights) doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3, PI*(o->oargs.farg[7]*o->oargs.farg[7] - @@ -322,17 +333,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); }