--- ray/src/rt/sphere.c 1989/02/02 10:41:42 1.1 +++ ray/src/rt/sphere.c 1991/05/22 16:59:44 1.4 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -26,10 +26,16 @@ register RAY *r; register double *ap; register int i; - if (so->oargs.nfargs != 4 || so->oargs.farg[3] <= FTINY) - objerror(so, USER, "bad arguments"); - + if (so->oargs.nfargs != 4) + objerror(so, USER, "bad # arguments"); ap = so->oargs.farg; + if (ap[3] < -FTINY) { + objerror(so, WARNING, "negative radius"); + so->otype = so->otype == OBJ_SPHERE ? + OBJ_BUBBLE : OBJ_SPHERE; + ap[3] = -ap[3]; + } else if (ap[3] <= FTINY) + objerror(so, USER, "zero radius"); /* * We compute the intersection by substituting into @@ -57,18 +63,21 @@ register RAY *r; if (i >= nroots) return(0); /* no positive root */ - if (t < r->rot) { /* found closer intersection */ - r->ro = so; - r->rot = t; - /* compute normal */ - a = ap[3]; - if (so->otype == OBJ_BUBBLE) - a = -a; /* reverse */ - for (i = 0; i < 3; i++) { - r->rop[i] = r->rorg[i] + r->rdir[i]*t; - r->ron[i] = (r->rop[i] - ap[i]) / a; - } - r->rod = -DOT(r->rdir, r->ron); + if (t >= r->rot) + return(0); /* other is closer */ + + r->ro = so; + r->rot = t; + /* compute normal */ + a = ap[3]; + if (so->otype == OBJ_BUBBLE) + a = -a; /* reverse */ + for (i = 0; i < 3; i++) { + r->rop[i] = r->rorg[i] + r->rdir[i]*t; + r->ron[i] = (r->rop[i] - ap[i]) / a; } - return(1); + r->rod = -DOT(r->rdir, r->ron); + r->rox = NULL; + + return(1); /* hit */ }