59 |
|
{ |
60 |
|
FVECT v1; |
61 |
|
double d1, d2; |
62 |
< |
register double *fa; |
62 |
> |
register FLOAT *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 |
|
|
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++) |
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 |
|
} |