1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
23 |
|
double root[2]; /* quadratic roots */ |
24 |
|
int nroots; |
25 |
|
double t; |
26 |
< |
register double *ap; |
26 |
> |
register FLOAT *ap; |
27 |
|
register int i; |
28 |
|
|
29 |
< |
if (so->oargs.nfargs != 4 || so->oargs.farg[3] <= FTINY) |
30 |
< |
objerror(so, USER, "bad arguments"); |
31 |
< |
|
29 |
> |
if (so->oargs.nfargs != 4) |
30 |
> |
objerror(so, USER, "bad # arguments"); |
31 |
|
ap = so->oargs.farg; |
32 |
+ |
if (ap[3] < -FTINY) { |
33 |
+ |
objerror(so, WARNING, "negative radius"); |
34 |
+ |
so->otype = so->otype == OBJ_SPHERE ? |
35 |
+ |
OBJ_BUBBLE : OBJ_SPHERE; |
36 |
+ |
ap[3] = -ap[3]; |
37 |
+ |
} else if (ap[3] <= FTINY) |
38 |
+ |
objerror(so, USER, "zero radius"); |
39 |
|
|
40 |
|
/* |
41 |
|
* We compute the intersection by substituting into |
63 |
|
if (i >= nroots) |
64 |
|
return(0); /* no positive root */ |
65 |
|
|
66 |
< |
if (t < r->rot) { /* found closer intersection */ |
67 |
< |
r->ro = so; |
68 |
< |
r->rot = t; |
69 |
< |
/* compute normal */ |
70 |
< |
a = ap[3]; |
71 |
< |
if (so->otype == OBJ_BUBBLE) |
72 |
< |
a = -a; /* reverse */ |
73 |
< |
for (i = 0; i < 3; i++) { |
74 |
< |
r->rop[i] = r->rorg[i] + r->rdir[i]*t; |
75 |
< |
r->ron[i] = (r->rop[i] - ap[i]) / a; |
76 |
< |
} |
77 |
< |
r->rod = -DOT(r->rdir, r->ron); |
66 |
> |
if (t >= r->rot) |
67 |
> |
return(0); /* other is closer */ |
68 |
> |
|
69 |
> |
r->ro = so; |
70 |
> |
r->rot = t; |
71 |
> |
/* compute normal */ |
72 |
> |
a = ap[3]; |
73 |
> |
if (so->otype == OBJ_BUBBLE) |
74 |
> |
a = -a; /* reverse */ |
75 |
> |
for (i = 0; i < 3; i++) { |
76 |
> |
r->rop[i] = r->rorg[i] + r->rdir[i]*t; |
77 |
> |
r->ron[i] = (r->rop[i] - ap[i]) / a; |
78 |
|
} |
79 |
< |
return(1); |
79 |
> |
r->rod = -DOT(r->rdir, r->ron); |
80 |
> |
r->rox = NULL; |
81 |
> |
|
82 |
> |
return(1); /* hit */ |
83 |
|
} |