Break out trace_hits_portal() from trace_enters_leaf().

This commit is contained in:
Bill Currie 2011-12-06 08:46:04 +09:00
parent 9a9079a2b3
commit 4c17ca9583

View file

@ -135,31 +135,20 @@ edges_intersect (const vec3_t p1, const vec3_t p2,
return true;
}
static int
trace_enters_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf,
plane_t *plane, const vec3_t vel, const vec3_t org)
static qboolean
trace_hits_portal (hull_t *hull, trace_t *trace, clipport_t *portal,
const vec3_t start, const vec3_t vel)
{
clipport_t *portal;
int side;
int i;
int planenum;
vec_t *point;
vec_t *edge;
vec_t dist, offset, vn;
plane_t *plane;
plane_t cutplane;
vec_t offset, dist, v_n;
vec_t *point, *edge;
planenum = plane - hull->planes;
plane = hull->planes + portal->planenum;
vn = DotProduct (vel, plane->normal);
cutplane.type = 3; // generic plane
v_n = DotProduct (vel, plane->normal);
if (!v_n) {
//FIXME is this correct? The assumption is that if we got to a leaf
//travelliing parallel to its plane, then we have to be in the leaf
return 1;
}
for (portal = leaf->portals; portal; portal = portal->next[side]) {
side = portal->leafs[1] == leaf;
if (portal->planenum != planenum)
continue;
for (i = 0; i < portal->winding->numpoints; i++) {
point = portal->winding->points[i];
edge = portal->edges->points[i];
@ -168,20 +157,39 @@ trace_enters_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf,
// matter.
CrossProduct (vel, edge, cutplane.normal);
cutplane.dist = DotProduct (cutplane.normal, point);
dist = PlaneDiff (org, &cutplane);
dist = PlaneDiff (start, &cutplane);
offset = calc_offset (trace, &cutplane);
if (v_n > 0) {
if (dist >= offset)
break;
} else {
if (dist <= -offset)
break;
if ((vn > 0 && dist >= offset) || (vn < 0 && dist <= -offset))
return false;
}
return true;
}
static qboolean
trace_enters_leaf (hull_t *hull, trace_t *trace, clipleaf_t *leaf,
plane_t *plane, const vec3_t vel, const vec3_t org)
{
clipport_t *portal;
int side;
int planenum;
vec_t v_n;
planenum = plane - hull->planes;
v_n = DotProduct (vel, plane->normal);
if (!v_n) {
//FIXME is this correct? The assumption is that if we got to a leaf
//travelliing parallel to its plane, then we have to be in the leaf
return true;
}
if (i == portal->winding->numpoints)
return 1;
for (portal = leaf->portals; portal; portal = portal->next[side]) {
side = portal->leafs[1] == leaf;
if (portal->planenum != planenum)
continue;
if (trace_hits_portal (hull, trace, portal, org, vel))
return true;
}
return 0;
return false;
}
typedef struct {