1 |
– |
/* Copyright (c) 1990 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 |
|
* o_cone.c - routine to determine ray intersection with cones. |
9 |
– |
* |
10 |
– |
* 2/13/86 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "ray.h" |
8 |
> |
#include "copyright.h" |
9 |
|
|
10 |
+ |
#include "ray.h" |
11 |
|
#include "otypes.h" |
12 |
< |
|
12 |
> |
#include "rtotypes.h" |
13 |
|
#include "cone.h" |
14 |
|
|
15 |
|
|
16 |
< |
o_cone(o, r) /* intersect ray with cone */ |
17 |
< |
OBJREC *o; |
18 |
< |
register RAY *r; |
16 |
> |
int |
17 |
> |
o_cone( /* intersect ray with cone */ |
18 |
> |
OBJREC *o, |
19 |
> |
RAY *r |
20 |
> |
) |
21 |
|
{ |
22 |
|
FVECT rox, rdx; |
23 |
|
double a, b, c; |
24 |
|
double root[2]; |
25 |
|
int nroots, rn; |
26 |
< |
register CONE *co; |
27 |
< |
register int i; |
26 |
> |
CONE *co; |
27 |
> |
int i; |
28 |
|
|
29 |
|
/* get cone structure */ |
30 |
|
co = getcone(o, 1); |
31 |
+ |
if (co == NULL) |
32 |
+ |
objerror(o, INTERNAL, "unexpected illegal"); |
33 |
|
|
34 |
|
/* |
35 |
|
* To intersect a ray with a cone, we transform the |
82 |
|
return(0); /* outside radii */ |
83 |
|
r->ro = o; |
84 |
|
r->rot = root[0]; |
85 |
< |
for (i = 0; i < 3; i++) |
86 |
< |
r->rop[i] = r->rorg[i] + r->rdir[i]*r->rot; |
85 |
> |
VSUM(r->rop, r->rorg, r->rdir, r->rot); |
86 |
|
VCOPY(r->ron, co->ad); |
87 |
|
r->rod = -rdx[2]; |
88 |
|
r->rox = NULL; |
97 |
|
if (root[rn] >= r->rot) |
98 |
|
break; /* too big */ |
99 |
|
/* check endpoints */ |
100 |
< |
for (i = 0; i < 3; i++) { |
101 |
< |
rox[i] = r->rorg[i] + root[rn]*r->rdir[i]; |
103 |
< |
rdx[i] = rox[i] - CO_P0(co)[i]; |
104 |
< |
} |
100 |
> |
VSUM(rox, r->rorg, r->rdir, root[rn]); |
101 |
> |
VSUB(rdx, rox, CO_P0(co)); |
102 |
|
b = DOT(rdx, co->ad); |
103 |
|
if (b < 0.0) |
104 |
|
continue; /* before p0 */ |
125 |
|
if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) |
126 |
|
for (i = 0; i < 3; i++) |
127 |
|
r->ron[i] = (co->al*r->ron[i] - c*co->ad[i]) |
128 |
< |
/co->sl; |
128 |
> |
/ co->sl; |
129 |
> |
a = DOT(r->ron, r->ron); |
130 |
> |
if (a > 1.+FTINY || a < 1.-FTINY) { |
131 |
> |
c = 1./(.5 + .5*a); /* avoid numerical error */ |
132 |
> |
r->ron[0] *= c; r->ron[1] *= c; r->ron[2] *= c; |
133 |
> |
} |
134 |
|
r->rod = -DOT(r->rdir, r->ron); |
135 |
+ |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
136 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
137 |
|
r->rox = NULL; |
138 |
|
return(1); /* good */ |
139 |
|
} |