| 8 |
|
#include "copyright.h" |
| 9 |
|
|
| 10 |
|
#include "ray.h" |
| 11 |
– |
|
| 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 |
| 56 |
|
multv3(rdx, r->rdir, co->tm); |
| 57 |
|
/* compute intersection */ |
| 58 |
|
|
| 59 |
< |
if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) { |
| 59 |
> |
if ((o->otype == OBJ_CONE) | (o->otype == OBJ_CUP)) { |
| 60 |
|
|
| 61 |
|
a = rdx[0]*rdx[0] + rdx[1]*rdx[1] - rdx[2]*rdx[2]; |
| 62 |
|
b = 2.0*(rdx[0]*rox[0] + rdx[1]*rox[1] - rdx[2]*rox[2]); |
| 63 |
|
c = rox[0]*rox[0] + rox[1]*rox[1] - rox[2]*rox[2]; |
| 64 |
|
|
| 65 |
< |
} else if (o->otype == OBJ_CYLINDER || o->otype == OBJ_TUBE) { |
| 65 |
> |
} else if ((o->otype == OBJ_CYLINDER) | (o->otype == OBJ_TUBE)) { |
| 66 |
|
|
| 67 |
|
a = rdx[0]*rdx[0] + rdx[1]*rdx[1]; |
| 68 |
|
b = 2.0*(rdx[0]*rox[0] + rdx[1]*rox[1]); |
| 70 |
|
|
| 71 |
|
} else { /* OBJ_RING */ |
| 72 |
|
|
| 73 |
< |
if (rdx[2] <= FTINY && rdx[2] >= -FTINY) |
| 73 |
> |
if ((rdx[2] <= FTINY) & (rdx[2] >= -FTINY)) |
| 74 |
|
return(0); /* parallel */ |
| 75 |
|
root[0] = -rox[2]/rdx[2]; |
| 76 |
< |
if (root[0] <= FTINY || root[0] >= r->rot) |
| 77 |
< |
return(0); /* distance check */ |
| 76 |
> |
if (rayreject(o, r, root[0], -rdx[2])) |
| 77 |
> |
return(0); /* have better */ |
| 78 |
|
b = root[0]*rdx[0] + rox[0]; |
| 79 |
|
c = root[0]*rdx[1] + rox[1]; |
| 80 |
|
a = b*b + c*c; |
| 81 |
< |
if (a < CO_R0(co)*CO_R0(co) || a > CO_R1(co)*CO_R1(co)) |
| 81 |
> |
if (a > CO_R1(co)*CO_R1(co) || a < CO_R0(co)*CO_R0(co)) |
| 82 |
|
return(0); /* outside radii */ |
| 83 |
|
r->ro = o; |
| 84 |
|
r->rot = root[0]; |
| 85 |
< |
for (i = 0; i < 3; i++) |
| 83 |
< |
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->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 89 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
| 90 |
|
r->rox = NULL; |
| 91 |
|
return(1); /* good */ |
| 92 |
|
} |
| 96 |
|
for (rn = 0; rn < nroots; rn++) { /* check real roots */ |
| 97 |
|
if (root[rn] <= FTINY) |
| 98 |
|
continue; /* too small */ |
| 99 |
< |
if (root[rn] >= r->rot) |
| 99 |
> |
if (root[rn] > r->rot + FTINY) |
| 100 |
|
break; /* too big */ |
| 101 |
|
/* check endpoints */ |
| 102 |
< |
for (i = 0; i < 3; i++) { |
| 103 |
< |
rox[i] = r->rorg[i] + root[rn]*r->rdir[i]; |
| 100 |
< |
rdx[i] = rox[i] - CO_P0(co)[i]; |
| 101 |
< |
} |
| 102 |
> |
VSUM(rox, r->rorg, r->rdir, root[rn]); |
| 103 |
> |
VSUB(rdx, rox, CO_P0(co)); |
| 104 |
|
b = DOT(rdx, co->ad); |
| 105 |
|
if (b < 0.0) |
| 106 |
|
continue; /* before p0 */ |
| 107 |
|
if (b > co->al) |
| 108 |
|
continue; /* after p1 */ |
| 109 |
+ |
if (rayreject(o, r, root[rn], 0)) |
| 110 |
+ |
break; /* previous hit better */ |
| 111 |
|
r->ro = o; |
| 112 |
|
r->rot = root[rn]; |
| 113 |
|
VCOPY(r->rop, rox); |
| 126 |
|
} |
| 127 |
|
for (i = 0; i < 3; i++) |
| 128 |
|
r->ron[i] = (rdx[i] - b*co->ad[i])/a; |
| 129 |
< |
if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) |
| 129 |
> |
if ((o->otype == OBJ_CONE) | (o->otype == OBJ_CUP)) |
| 130 |
|
for (i = 0; i < 3; i++) |
| 131 |
|
r->ron[i] = (co->al*r->ron[i] - c*co->ad[i]) |
| 132 |
< |
/co->sl; |
| 132 |
> |
/ co->sl; |
| 133 |
> |
a = DOT(r->ron, r->ron); |
| 134 |
> |
if ((a > 1.+FTINY) | (a < 1.-FTINY)) { |
| 135 |
> |
c = 1./(.5 + .5*a); /* avoid numerical error */ |
| 136 |
> |
r->ron[0] *= c; r->ron[1] *= c; r->ron[2] *= c; |
| 137 |
> |
} |
| 138 |
|
r->rod = -DOT(r->rdir, r->ron); |
| 139 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
| 140 |
|
r->uv[0] = r->uv[1] = 0.0; |