ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/sphere.c
(Generate patch)

Comparing ray/src/rt/sphere.c (file contents):
Revision 1.2 by greg, Wed Apr 19 22:24:30 1989 UTC vs.
Revision 2.7 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  sphere.c - compute ray intersection with spheres.
9 *
10 *     8/19/85
6   */
7  
8 < #include  "ray.h"
8 > #include "copyright.h"
9  
10 + #include  "ray.h"
11   #include  "otypes.h"
12 + #include  "rtotypes.h"
13  
14  
15 < o_sphere(so, r)                 /* compute intersection with sphere */
16 < OBJREC  *so;
17 < register RAY  *r;
15 > extern int
16 > o_sphere(                       /* compute intersection with sphere */
17 >        OBJREC  *so,
18 >        register RAY  *r
19 > )
20   {
21          double  a, b, c;        /* coefficients for quadratic equation */
22          double  root[2];        /* quadratic roots */
23          int  nroots;
24          double  t;
25 <        register double  *ap;
25 >        register RREAL  *ap;
26          register int  i;
27  
28 <        if (so->oargs.nfargs != 4 || so->oargs.farg[3] <= FTINY)
29 <                objerror(so, USER, "bad arguments");
31 <
28 >        if (so->oargs.nfargs != 4)
29 >                objerror(so, USER, "bad # arguments");
30          ap = so->oargs.farg;
31 +        if (ap[3] < -FTINY) {
32 +                objerror(so, WARNING, "negative radius");
33 +                so->otype = so->otype == OBJ_SPHERE ?
34 +                                OBJ_BUBBLE : OBJ_SPHERE;
35 +                ap[3] = -ap[3];
36 +        } else if (ap[3] <= FTINY)
37 +                objerror(so, USER, "zero radius");
38  
39          /*
40           *      We compute the intersection by substituting into
# Line 37 | Line 42 | register RAY  *r;
42           *  quadratic equation in t is then solved for the
43           *  smallest positive root, which is our point of
44           *  intersection.
45 <         *      Because the ray direction is normalized, a is always 1.
45 >         *      Since the ray is normalized, a should always be
46 >         *  one.  We compute it here to prevent instability in the
47 >         *  intersection calculation.
48           */
49 <
50 <        a = 1.0;                /* compute quadratic coefficients */
44 <        b = c = 0.0;
49 >                                /* compute quadratic coefficients */
50 >        a = b = c = 0.0;
51          for (i = 0; i < 3; i++) {
52 +                a += r->rdir[i]*r->rdir[i];
53                  t = r->rorg[i] - ap[i];
54                  b += 2.0*r->rdir[i]*t;
55                  c += t*t;
# Line 71 | Line 78 | register RAY  *r;
78                  r->ron[i] = (r->rop[i] - ap[i]) / a;
79          }
80          r->rod = -DOT(r->rdir, r->ron);
81 <        r->rofs = 1.0; setident4(r->rofx);
82 <        r->robs = 1.0; setident4(r->robx);
81 >        r->rox = NULL;
82 >        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
83 >        r->uv[0] = r->uv[1] = 0.0;
84  
85          return(1);                      /* hit */
86   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines