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 |
|
* |
56 |
|
{ |
57 |
|
FVECT v1; |
58 |
|
double d1, d2; |
59 |
< |
register double *fa; |
59 |
> |
register FLOAT *fa; |
60 |
|
register int i; |
61 |
|
#define cent fa |
62 |
|
#define rad fa[3] |
63 |
|
/* get arguments */ |
64 |
+ |
if (o->oargs.nfargs != 4) |
65 |
+ |
objerror(o, USER, "bad # arguments"); |
66 |
|
fa = o->oargs.farg; |
67 |
< |
if (o->oargs.nfargs != 4 || rad <= FTINY) |
68 |
< |
objerror(o, USER, "bad arguments"); |
67 |
> |
if (rad < -FTINY) { |
68 |
> |
objerror(o, WARNING, "negative radius"); |
69 |
> |
o->otype = o->otype == OBJ_SPHERE ? |
70 |
> |
OBJ_BUBBLE : OBJ_SPHERE; |
71 |
> |
rad = -rad; |
72 |
> |
} else if (rad <= FTINY) |
73 |
> |
objerror(o, USER, "zero radius"); |
74 |
|
|
75 |
|
d1 = ROOT3/2.0 * cu->cusize; /* bounding radius for cube */ |
76 |
|
|
80 |
|
d2 = DOT(v1,v1); |
81 |
|
|
82 |
|
if (d2 > (rad+d1+FTINY)*(rad+d1+FTINY)) /* quick test */ |
83 |
< |
return(0); /* cube outside */ |
83 |
> |
return(O_MISS); /* cube outside */ |
84 |
|
|
85 |
|
/* check sphere interior */ |
86 |
|
if (d1 < rad) { |
87 |
|
if (d2 < (rad-d1-FTINY)*(rad-d1-FTINY)) |
88 |
< |
return(0); /* cube inside sphere */ |
88 |
> |
return(O_MISS); /* cube inside sphere */ |
89 |
|
if (d2 < (rad+FTINY)*(rad+FTINY)) |
90 |
< |
return(1); /* cube center inside */ |
90 |
> |
return(O_HIT); /* cube center inside */ |
91 |
|
} |
92 |
|
/* find closest distance */ |
93 |
|
for (i = 0; i < 3; i++) |
99 |
|
v1[i] = 0; |
100 |
|
/* final intersection check */ |
101 |
|
if (DOT(v1,v1) <= (rad+FTINY)*(rad+FTINY)) |
102 |
< |
return(1); |
102 |
> |
return(O_HIT); |
103 |
|
else |
104 |
< |
return(0); |
104 |
> |
return(O_MISS); |
105 |
|
} |