From 73045b6642348c8d2fd8b45cae305bbf0344d444 Mon Sep 17 00:00:00 2001 From: aura Date: Wed, 4 Mar 2026 18:58:21 +0100 Subject: more collision improv --- src/game/world/bsp.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/game/world/bsp.cpp') diff --git a/src/game/world/bsp.cpp b/src/game/world/bsp.cpp index 7f72e52..c33cac1 100644 --- a/src/game/world/bsp.cpp +++ b/src/game/world/bsp.cpp @@ -417,6 +417,10 @@ I32 bsp_build_nodes( } U8 bsp_edge_is_shared( BSP* bsp, VEC3 edge1a, VEC3 edge1b, VEC3 center, VEC3 ecross, U32 facei ) { + BSP_FACE* face = &bsp->faces[facei]; + VEC3 n = bsp_face_get_normal( face ); + U8 aligned = bsp_face_is_axis_aligned( face ); + for( U32 i = 0; i < bsp->faces.size; ++i ) { if( facei == i ) continue; @@ -425,6 +429,12 @@ U8 bsp_edge_is_shared( BSP* bsp, VEC3 edge1a, VEC3 edge1b, VEC3 center, VEC3 ecr if( other->verts.size < 3 ) continue; + VEC3 othern = bsp_face_get_normal( face ); + F32 d = vec_dot( n, othern ); + // dont create edge planes for planes that are axis-aligned and directly perpendicular + if( aligned && (d < BSP_NORM_EPSILON || d > 1.f - BSP_NORM_EPSILON) ) + continue; + VEC3 otherc{}; for( U32 vi = 0; vi < other->verts.size; ++vi ) otherc += other->verts[vi].pos; @@ -487,9 +497,6 @@ void bsp_gen_leaf_edges( BSP* bsp, I32 leaf_idx ) { if( fabsf( vec_dot( cross, facen ) ) > 0.995f ) continue; - if( !bsp_edge_is_shared( bsp, a, b, center, cross, faceidx ) ) - continue; - F32 d = vec_dot( cross, a ); BSP_PLANE plane = { cross, d }; U8 dupe = 0; @@ -500,6 +507,9 @@ void bsp_gen_leaf_edges( BSP* bsp, I32 leaf_idx ) { if( dupe ) continue; + if( !bsp_edge_is_shared( bsp, a, b, center, cross, faceidx ) ) + continue; + BSP_EDGE e; e.plane = plane; e.face = faceidx; -- cgit v1.2.3