--- ray/src/ot/sphere.c 1989/02/02 10:33:06 1.1 +++ ray/src/ot/sphere.c 2003/06/26 00:58:10 2.3 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: sphere.c,v 2.3 2003/06/26 00:58:10 schorsch Exp $"; #endif - /* * sphere.c - routines for creating octrees for spheres. * @@ -59,14 +56,21 @@ register CUBE *cu; { FVECT v1; double d1, d2; - register double *fa; + register RREAL *fa; register int i; #define cent fa #define rad fa[3] /* get arguments */ + if (o->oargs.nfargs != 4) + objerror(o, USER, "bad # arguments"); fa = o->oargs.farg; - if (o->oargs.nfargs != 4 || rad <= FTINY) - objerror(o, USER, "bad arguments"); + if (rad < -FTINY) { + objerror(o, WARNING, "negative radius"); + o->otype = o->otype == OBJ_SPHERE ? + OBJ_BUBBLE : OBJ_SPHERE; + rad = -rad; + } else if (rad <= FTINY) + objerror(o, USER, "zero radius"); d1 = ROOT3/2.0 * cu->cusize; /* bounding radius for cube */ @@ -76,14 +80,14 @@ register CUBE *cu; d2 = DOT(v1,v1); if (d2 > (rad+d1+FTINY)*(rad+d1+FTINY)) /* quick test */ - return(0); /* cube outside */ + return(O_MISS); /* cube outside */ /* check sphere interior */ if (d1 < rad) { if (d2 < (rad-d1-FTINY)*(rad-d1-FTINY)) - return(0); /* cube inside sphere */ + return(O_MISS); /* cube inside sphere */ if (d2 < (rad+FTINY)*(rad+FTINY)) - return(1); /* cube center inside */ + return(O_HIT); /* cube center inside */ } /* find closest distance */ for (i = 0; i < 3; i++) @@ -95,7 +99,7 @@ register CUBE *cu; v1[i] = 0; /* final intersection check */ if (DOT(v1,v1) <= (rad+FTINY)*(rad+FTINY)) - return(1); + return(O_HIT); else - return(0); + return(O_MISS); }