| 26 |
|
#include "ray.h" |
| 27 |
|
#include "mesh.h" |
| 28 |
|
#include "tmesh.h" |
| 29 |
+ |
#include "rtotypes.h" |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
#define EDGE_CACHE_SIZ 251 /* length of mesh edge cache */ |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
static int |
| 61 |
< |
signed_volume(r, v1, v2) /* get signed volume for ray and edge */ |
| 62 |
< |
register RAY *r; |
| 61 |
> |
volume_sign(r, v1, v2) /* get signed volume for ray and edge */ |
| 62 |
> |
RAY *r; |
| 63 |
|
int32 v1, v2; |
| 64 |
|
{ |
| 65 |
< |
int reversed = 0; |
| 66 |
< |
register struct EdgeSide *ecp; |
| 65 |
> |
int reversed = 0; |
| 66 |
> |
struct EdgeSide *ecp; |
| 67 |
|
|
| 68 |
|
if (v1 > v2) { |
| 69 |
|
int32 t = v2; v2 = v1; v1 = t; |
| 70 |
|
reversed = 1; |
| 71 |
|
} |
| 72 |
|
ecp = &edge_cache.cache[((v2<<11 ^ v1) & 0x7fffffff) % EDGE_CACHE_SIZ]; |
| 73 |
< |
if (ecp->v1i != v1 || ecp->v2i != v2) { |
| 73 |
> |
if ((ecp->v1i != v1) | (ecp->v2i != v2)) { |
| 74 |
|
MESHVERT tv1, tv2; /* compute signed volume */ |
| 75 |
|
FVECT v2d; |
| 76 |
|
double vol; |
| 77 |
< |
if (!getmeshvert(&tv1, edge_cache.mi->msh, v1, MT_V) || |
| 77 |
> |
if (!getmeshvert(&tv1, edge_cache.mi->msh, v1, MT_V) | |
| 78 |
|
!getmeshvert(&tv2, edge_cache.mi->msh, v2, MT_V)) |
| 79 |
|
objerror(edge_cache.o, INTERNAL, |
| 80 |
< |
"missing mesh vertex in signed_volume"); |
| 80 |
> |
"missing mesh vertex in volume_sign"); |
| 81 |
|
VSUB(v2d, tv2.v, r->rorg); |
| 82 |
|
vol = (tv1.v[0] - r->rorg[0]) * |
| 83 |
|
(v2d[1]*r->rdir[2] - v2d[2]*r->rdir[1]); |
| 85 |
|
(v2d[2]*r->rdir[0] - v2d[0]*r->rdir[2]); |
| 86 |
|
vol += (tv1.v[2] - r->rorg[2]) * |
| 87 |
|
(v2d[0]*r->rdir[1] - v2d[1]*r->rdir[0]); |
| 88 |
< |
if (vol > .0) |
| 89 |
< |
ecp->signum = 1; |
| 89 |
< |
else if (vol < .0) |
| 90 |
< |
ecp->signum = -1; |
| 91 |
< |
else |
| 92 |
< |
ecp->signum = 0; |
| 88 |
> |
/* don't generate 0 */ |
| 89 |
> |
ecp->signum = vol > .0 ? 1 : -1; |
| 90 |
|
ecp->v1i = v1; |
| 91 |
|
ecp->v2i = v2; |
| 92 |
|
} |
| 111 |
|
if (!getmeshtrivid(tvi, &tmod, curmsh, oset[i])) |
| 112 |
|
objerror(edge_cache.o, INTERNAL, |
| 113 |
|
"missing triangle vertices in mesh_hit"); |
| 114 |
< |
sv1 = signed_volume(r, tvi[0], tvi[1]); |
| 115 |
< |
sv2 = signed_volume(r, tvi[1], tvi[2]); |
| 116 |
< |
sv3 = signed_volume(r, tvi[2], tvi[0]); |
| 117 |
< |
if (sv1 != sv2 || sv2 != sv3) /* compare volume signs */ |
| 118 |
< |
if (sv1 && sv2 && sv3) |
| 119 |
< |
continue; |
| 114 |
> |
sv1 = volume_sign(r, tvi[0], tvi[1]); |
| 115 |
> |
sv2 = volume_sign(r, tvi[1], tvi[2]); |
| 116 |
> |
if (sv1 != sv2) /* compare volume signs */ |
| 117 |
> |
continue; |
| 118 |
> |
sv3 = volume_sign(r, tvi[2], tvi[0]); |
| 119 |
> |
if (sv2 != sv3) |
| 120 |
> |
continue; |
| 121 |
|
/* compute intersection */ |
| 122 |
|
getmeshvert(&tv[0], curmsh, tvi[0], MT_V); |
| 123 |
|
getmeshvert(&tv[1], curmsh, tvi[1], MT_V); |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
int |
| 146 |
< |
o_mesh(o, r) /* compute ray intersection with a mesh */ |
| 147 |
< |
OBJREC *o; |
| 148 |
< |
register RAY *r; |
| 146 |
> |
o_mesh( /* compute ray intersection with a mesh */ |
| 147 |
> |
OBJREC *o, |
| 148 |
> |
RAY *r |
| 149 |
> |
) |
| 150 |
|
{ |
| 151 |
|
RAY rcont; |
| 152 |
|
int flags; |
| 157 |
|
/* get the mesh instance */ |
| 158 |
|
prep_edge_cache(o); |
| 159 |
|
/* copy and transform ray */ |
| 160 |
< |
copystruct(&rcont, r); |
| 160 |
> |
rcont = *r; |
| 161 |
|
multp3(rcont.rorg, r->rorg, curmi->x.b.xfm); |
| 162 |
|
multv3(rcont.rdir, r->rdir, curmi->x.b.xfm); |
| 163 |
|
for (i = 0; i < 3; i++) |
| 199 |
|
wt[2]*tv[2].n[i]; |
| 200 |
|
multv3(r->pert, rcont.pert, curmi->x.f.xfm); |
| 201 |
|
if (normalize(r->pert) != 0.0) |
| 202 |
< |
for (i = 0; i < 3; i++) |
| 204 |
< |
r->pert[i] -= r->ron[i]; |
| 202 |
> |
VSUB(r->pert, r->pert, r->ron); |
| 203 |
|
} else |
| 204 |
|
r->pert[0] = r->pert[1] = r->pert[2] = .0; |
| 205 |
|
|