summaryrefslogtreecommitdiff
path: root/src/game/world/trace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/world/trace.cpp')
-rw-r--r--src/game/world/trace.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/game/world/trace.cpp b/src/game/world/trace.cpp
index 61e3da4..d962ba3 100644
--- a/src/game/world/trace.cpp
+++ b/src/game/world/trace.cpp
@@ -190,9 +190,10 @@ inline U8 point_in_inflated_poly(
for( U32 i = 0; i < c; ++i ) {
VEC3 a = face->verts.data[i].pos;
VEC3 b = face->verts.data[(i+1)%c].pos;
- VEC3 in = vec_cross( norm, b - a );
+ VEC3 e = b - a;
+ VEC3 in = vec_cross( norm, e );
F32 len = vec_len( in );
- if( len <= 0.00001f ) continue;
+ if( len <= 0.0001f ) continue;
in *= (1.0f/ len);
if( vec_dot( center - a, in ) < 0.0f )
in = in * -1.0f;
@@ -201,6 +202,21 @@ inline U8 point_in_inflated_poly(
F32 expand = aabb_support_radius( hull, in );
if( dist < -( expand - BSP_EDGE_TOLERANCE ) )
return 0;
+
+ U8 isaxis = 0;
+ for( U32 i = 0; i < 3; ++i ) {
+ if( norm == vec3_axis[i] || norm == (vec3_axis[i] * -1.f) ) {
+ isaxis = 1; break;
+ }
+ }
+
+ // for non-axis-aligned faces the point of contact is infinitely thin
+ // todo : this isnt foolproof, check for hit direction if it comes from up/down
+ // just ignore this, only apply to walls
+ if( !isaxis ) {
+ if( dist < BSP_EDGE_TOLERANCE )
+ return 0;
+ }
}
return 1;
}
@@ -218,15 +234,20 @@ U8 bsp_trace_sweep_aabb_to_face(
if( face->verts.size < 3 )
return 0;
- VEC3 hullh = (hull.max - hull.min) * 0.5f;
- AABB fhull = { face->mins - hullh, face->maxs + hullh };
+ VEC3 hullv = hull.max - hull.min;
+ AABB fhull = { face->mins - hullv, face->maxs + hullv };
VEC3 norm = bsp_face_get_normal( face );
F32 d = vec_dot( norm, face->verts[0].pos );
F32 radius = aabb_support_radius( hull, norm );
VEC3 dir = trace->in_end - trace->in_start;
F32 s0 = vec_dot( norm, trace->in_start ) - d;
- F32 ndir = vec_dot( norm, trace->in_end - trace->in_start );
+ F32 ndir = vec_dot( norm, dir );
+
+ VEC3 dirn = vec_normalize( dir );
+ F32 tdot = vec_dot( dirn, norm );
+ if( tdot >= 0 ) // dont collide with rear side
+ return 0;
if( fabsf( s0 ) <= radius + BSP_TRACE_EPSILON ) {
if( aabb_contains_point( fhull, start ) && point_in_inflated_poly( start, face, hull, norm ) ) {
@@ -247,7 +268,6 @@ U8 bsp_trace_sweep_aabb_to_face(
F32 t_enter = (-radius - s0) / ndir;
F32 t_exit = ( radius - s0) / ndir;
if( t_enter > t_exit ) { F32 tmp=t_enter; t_enter=t_exit; t_exit=tmp; }
-
if( t_exit < 0.f - BSP_TRACE_EPSILON || t_enter > 1.f + BSP_TRACE_EPSILON )
return 0;
@@ -319,9 +339,11 @@ U8 bsp_trace_sweep_aabb_to_leaf_edges(
F32 along = vec_dot( step - e->v1, edir );
VEC3 proj = e->v1 + edir * m_clamp( along, 0.f, elen );
F32 dist = vec_dist( proj, step );
+
+
+ F32 expand = aabb_support_radius( hull, n );
if( dist > BSP_TRACE_EPSILON ) {
- F32 expand = aabb_support_radius( hull, vec_normalize( step - proj ) );
- if( dist < -(expand) || dist > expand )
+ if( dist > expand - BSP_EDGE_TOLERANCE )
continue;
}