28 |
|
#include "tmesh.h" |
29 |
|
|
30 |
|
|
31 |
< |
#define EDGE_CACHE_SIZ 109 /* length of mesh edge cache */ |
31 |
> |
#define EDGE_CACHE_SIZ 251 /* length of mesh edge cache */ |
32 |
|
|
33 |
|
#define curmi (edge_cache.mi) |
34 |
|
#define curmsh (curmi->msh) |
68 |
|
int4 t = v2; v2 = v1; v1 = t; |
69 |
|
reversed = 1; |
70 |
|
} |
71 |
< |
ecp = &edge_cache.cache[(v2<<11 ^ v1) % EDGE_CACHE_SIZ]; |
71 |
> |
ecp = &edge_cache.cache[((v2<<11 ^ v1) & 0x7fffffff) % EDGE_CACHE_SIZ]; |
72 |
|
if (ecp->v1i != v1 || ecp->v2i != v2) { |
73 |
|
MESHVERT tv1, tv2; /* compute signed volume */ |
74 |
+ |
FVECT v2d; |
75 |
|
double vol; |
76 |
|
if (!getmeshvert(&tv1, edge_cache.mi->msh, v1, MT_V) || |
77 |
< |
!getmeshvert(&tv2, edge_cache.mi->msh, v2, MT_V)) |
77 |
> |
!getmeshvert(&tv2, edge_cache.mi->msh, v2, MT_V)) |
78 |
|
objerror(edge_cache.o, INTERNAL, |
79 |
< |
"missing mesh vertex in signed_volume"); |
79 |
> |
"missing mesh vertex in signed_volume"); |
80 |
> |
VSUB(v2d, tv2.v, r->rorg); |
81 |
|
vol = (tv1.v[0] - r->rorg[0]) * |
82 |
< |
( (tv2.v[1] - r->rorg[1])*r->rdir[2] - |
81 |
< |
(tv2.v[2] - r->rorg[2])*r->rdir[1] ); |
82 |
> |
(v2d[1]*r->rdir[2] - v2d[2]*r->rdir[1]); |
83 |
|
vol += (tv1.v[1] - r->rorg[1]) * |
84 |
< |
( (tv2.v[2] - r->rorg[2])*r->rdir[0] - |
84 |
< |
(tv2.v[0] - r->rorg[0])*r->rdir[2] ); |
84 |
> |
(v2d[2]*r->rdir[0] - v2d[0]*r->rdir[2]); |
85 |
|
vol += (tv1.v[2] - r->rorg[2]) * |
86 |
< |
( (tv2.v[0] - r->rorg[0])*r->rdir[1] - |
87 |
< |
(tv2.v[1] - r->rorg[1])*r->rdir[0] ); |
86 |
> |
(v2d[0]*r->rdir[1] - v2d[1]*r->rdir[0]); |
87 |
|
if (vol > .0) |
88 |
|
ecp->signum = 1; |
89 |
|
else if (vol < .0) |
112 |
|
for (i = oset[0]; i > 0; i--) { |
113 |
|
if (!getmeshtrivid(tvi, curmsh, oset[i])) |
114 |
|
objerror(edge_cache.o, INTERNAL, |
115 |
< |
"missing triangle vertices in mesh_hit"); |
115 |
> |
"missing triangle vertices in mesh_hit"); |
116 |
|
sv1 = signed_volume(r, tvi[0], tvi[1]); |
117 |
|
sv2 = signed_volume(r, tvi[1], tvi[2]); |
118 |
|
sv3 = signed_volume(r, tvi[2], tvi[0]); |
138 |
|
r->rot = d; |
139 |
|
VSUM(r->rop, r->rorg, r->rdir, d); |
140 |
|
VCOPY(r->ron, nrm); |
141 |
< |
/* normalize(r->ron) called in o_mesh() & rod set */ |
141 |
> |
/* normalize(r->ron) called & r->rod set in o_mesh() */ |
142 |
|
} |
143 |
|
} |
144 |
|
|
196 |
|
if (normalize(r->pert) != 0.0) |
197 |
|
for (i = 0; i < 3; i++) |
198 |
|
r->pert[i] -= r->ron[i]; |
199 |
< |
} |
199 |
> |
} else |
200 |
> |
r->pert[0] = r->pert[1] = r->pert[2] = .0; |
201 |
> |
|
202 |
|
if (flags & MT_UV) /* interpolate uv coordinates */ |
203 |
|
for (i = 0; i < 2; i++) |
204 |
|
r->uv[i] = wt[0]*tv[0].uv[i] + |
205 |
|
wt[1]*tv[1].uv[i] + |
206 |
|
wt[2]*tv[2].uv[i]; |
207 |
+ |
else |
208 |
+ |
r->uv[0] = r->uv[1] = .0; |
209 |
|
|
210 |
|
/* return hit */ |
211 |
|
return(1); |