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

Comparing ray/src/ot/sphere.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:33:06 1989 UTC vs.
Revision 2.4 by schorsch, Sat Mar 27 12:41:45 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 - routines for creating octrees for spheres.
6   *
# Line 53 | Line 50 | static char SCCSid[] = "$SunId$ LBL";
50   */
51  
52  
53 < o_sphere(o, cu)                 /* determine if sphere intersects cube */
54 < OBJREC  *o;
55 < register CUBE  *cu;
53 > /* XXX o_sphere() is extern, but not declared in any header file */
54 > int
55 > o_sphere(                       /* determine if sphere intersects cube */
56 >        OBJREC  *o,
57 >        register CUBE  *cu
58 > )
59   {
60          FVECT  v1;
61          double  d1, d2;
62 <        register double  *fa;
62 >        register RREAL  *fa;
63          register int  i;
64   #define  cent           fa
65   #define  rad            fa[3]
66                                          /* get arguments */
67 +        if (o->oargs.nfargs != 4)
68 +                objerror(o, USER, "bad # arguments");
69          fa = o->oargs.farg;
70 <        if (o->oargs.nfargs != 4 || rad <= FTINY)
71 <                objerror(o, USER, "bad arguments");
70 >        if (rad < -FTINY) {
71 >                objerror(o, WARNING, "negative radius");
72 >                o->otype = o->otype == OBJ_SPHERE ?
73 >                                OBJ_BUBBLE : OBJ_SPHERE;
74 >                rad = -rad;
75 >        } else if (rad <= FTINY)
76 >                objerror(o, USER, "zero radius");
77  
78          d1 = ROOT3/2.0 * cu->cusize;    /* bounding radius for cube */
79  
# Line 76 | Line 83 | register CUBE  *cu;
83          d2 = DOT(v1,v1);
84  
85          if (d2 > (rad+d1+FTINY)*(rad+d1+FTINY)) /* quick test */
86 <                return(0);                      /* cube outside */
86 >                return(O_MISS);                 /* cube outside */
87          
88                                          /* check sphere interior */
89          if (d1 < rad) {
90                  if (d2 < (rad-d1-FTINY)*(rad-d1-FTINY))
91 <                        return(0);              /* cube inside sphere */
91 >                        return(O_MISS);         /* cube inside sphere */
92                  if (d2 < (rad+FTINY)*(rad+FTINY))
93 <                        return(1);              /* cube center inside */
93 >                        return(O_HIT);          /* cube center inside */
94          }
95                                          /* find closest distance */
96          for (i = 0; i < 3; i++)
# Line 95 | Line 102 | register CUBE  *cu;
102                          v1[i] = 0;
103                                          /* final intersection check */
104          if (DOT(v1,v1) <= (rad+FTINY)*(rad+FTINY))
105 <                return(1);
105 >                return(O_HIT);
106          else
107 <                return(0);
107 >                return(O_MISS);
108   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines