From 54bcabc374b438ee288964d6f6314f5da2121a0e Mon Sep 17 00:00:00 2001 From: aura Date: Thu, 5 Mar 2026 08:25:23 +0100 Subject: calc face center during map compile --- src/game/world/bsp.cpp | 1 + src/game/world/bsp.h | 9 +++++++++ src/game/world/trace.cpp | 7 +++---- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/game') diff --git a/src/game/world/bsp.cpp b/src/game/world/bsp.cpp index f5fb0e9..b55593f 100644 --- a/src/game/world/bsp.cpp +++ b/src/game/world/bsp.cpp @@ -840,6 +840,7 @@ BSP* bsp_build_map( WORLD_MAP* m ) { bsp->root = bsp_build_nodes( bsp, planes, faces, 0 ); for( U32 i = 0; i < bsp->faces.size; ++i ) { bsp_face_calc_extents( &bsp->faces.data[i] ); + bsp->faces.data[i].center = bsp_face_get_center( &bsp->faces.data[i] ); bsp->faces.data[i].id = i; } bsp_gen_leaf_edges( bsp ); diff --git a/src/game/world/bsp.h b/src/game/world/bsp.h index ac72e14..fbf2a4c 100644 --- a/src/game/world/bsp.h +++ b/src/game/world/bsp.h @@ -49,6 +49,7 @@ struct BSP_FACE { LIST render_verts{}; VEC3 mins; VEC3 maxs; + VEC3 center; U32 hitmask; }; @@ -154,6 +155,14 @@ inline U8 bsp_face_is_axis_aligned( BSP_FACE* f ) { return 1; } +inline VEC3 bsp_face_get_center( BSP_FACE* f ) { + if( !f->verts.size ) return {}; + VEC3 c{}; + for( U32 i = 0; i < f->verts.size; ++i ) + c += f->verts.data[i].pos; + return c / f->verts.size; +} + inline void bsp_face_calc_extents( BSP_FACE* f ) { VEC3 mins{ +INFINITY, +INFINITY, +INFINITY }, maxs{ -INFINITY, -INFINITY, -INFINITY }; for( U32 i = 0; i < f->verts.size; ++i ) { diff --git a/src/game/world/trace.cpp b/src/game/world/trace.cpp index 0cd720d..2cf2a81 100644 --- a/src/game/world/trace.cpp +++ b/src/game/world/trace.cpp @@ -198,11 +198,10 @@ inline U8 point_in_inflated_poly( const AABB& hull, const VEC3& norm ){ - VEC3 center{}; U32 c = face->verts.size; - for( U32 i = 0; i < c; ++i ) - center = center + face->verts.data[i].pos; - if( c ) center = center * (1.0f / c); + VEC3 center = face->center; + if( !c ) + return 0; VEC3 hullh = ( hull.max - hull.min ) * 0.5f; for( U32 i = 0; i < c; ++i ) { -- cgit v1.2.3