1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 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 |
43 |
|
* quadratic equation in t is then solved for the |
44 |
|
* smallest positive root, which is our point of |
45 |
|
* intersection. |
46 |
< |
* Because the ray direction is normalized, a is always 1. |
46 |
> |
* Since the ray is normalized, a should always be |
47 |
> |
* one. We compute it here to prevent instability in the |
48 |
> |
* intersection calculation. |
49 |
|
*/ |
50 |
< |
|
51 |
< |
a = 1.0; /* compute quadratic coefficients */ |
44 |
< |
b = c = 0.0; |
50 |
> |
/* compute quadratic coefficients */ |
51 |
> |
a = b = c = 0.0; |
52 |
|
for (i = 0; i < 3; i++) { |
53 |
+ |
a += r->rdir[i]*r->rdir[i]; |
54 |
|
t = r->rorg[i] - ap[i]; |
55 |
|
b += 2.0*r->rdir[i]*t; |
56 |
|
c += t*t; |
79 |
|
r->ron[i] = (r->rop[i] - ap[i]) / a; |
80 |
|
} |
81 |
|
r->rod = -DOT(r->rdir, r->ron); |
82 |
< |
r->rofs = 1.0; setident4(r->rofx); |
75 |
< |
r->robs = 1.0; setident4(r->robx); |
82 |
> |
r->rox = NULL; |
83 |
|
|
84 |
|
return(1); /* hit */ |
85 |
|
} |