--- ray/src/rt/o_cone.c 1989/04/19 22:24:25 1.2 +++ ray/src/rt/o_cone.c 2004/06/28 10:07:17 2.6 @@ -1,25 +1,23 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: o_cone.c,v 2.6 2004/06/28 10:07:17 greg Exp $"; #endif - /* * o_cone.c - routine to determine ray intersection with cones. - * - * 2/13/86 */ -#include "ray.h" +#include "copyright.h" +#include "ray.h" #include "otypes.h" - +#include "rtotypes.h" #include "cone.h" -o_cone(o, r) /* intersect ray with cone */ -OBJREC *o; -register RAY *r; +extern int +o_cone( /* intersect ray with cone */ + OBJREC *o, + register RAY *r +) { FVECT rox, rdx; double a, b, c; @@ -86,8 +84,7 @@ register RAY *r; r->rop[i] = r->rorg[i] + r->rdir[i]*r->rot; VCOPY(r->ron, co->ad); r->rod = -rdx[2]; - r->rofs = 1.0; setident4(r->rofx); - r->robs = 1.0; setident4(r->robx); + r->rox = NULL; return(1); /* good */ } /* roots for cone, cup, cyl., tube */ @@ -130,9 +127,15 @@ register RAY *r; for (i = 0; i < 3; i++) r->ron[i] = (co->al*r->ron[i] - c*co->ad[i]) /co->sl; + a = DOT(r->ron, r->ron); + if (a > 1.+FTINY || a < 1.-FTINY) { + c = 1./(.5 + .5*a); /* avoid numerical error */ + r->ron[0] *= c; r->ron[1] *= c; r->ron[2] *= c; + } r->rod = -DOT(r->rdir, r->ron); - r->rofs = 1.0; setident4(r->rofx); - r->robs = 1.0; setident4(r->robx); + r->pert[0] = r->pert[1] = r->pert[2] = 0.0; + r->uv[0] = r->uv[1] = 0.0; + r->rox = NULL; return(1); /* good */ } return(0);