From 89f9b3df68374d6b29a4212835358ef0e6e6b6f9 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 2 Dec 2023 18:01:15 +0300 Subject: [PATCH] public: make simple bbox functions inline --- public/xash3d_mathlib.c | 42 +---------------------------------------- public/xash3d_mathlib.h | 28 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 44 deletions(-) diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index 7ec72ebe..36705c3c 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -384,18 +384,6 @@ void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, v // // bounds operations // -/* -================= -ClearBounds -================= -*/ -void ClearBounds( vec3_t mins, vec3_t maxs ) -{ - // make bogus range - mins[0] = mins[1] = mins[2] = 999999.0f; - maxs[0] = maxs[1] = maxs[2] = -999999.0f; -} - /* ================= AddPointToBounds @@ -416,7 +404,7 @@ void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) /* ================= -ExpandBounds +ExpandBounds (not used anywhere?) ================= */ void ExpandBounds( vec3_t mins, vec3_t maxs, float offset ) @@ -429,34 +417,6 @@ void ExpandBounds( vec3_t mins, vec3_t maxs, float offset ) maxs[2] += offset; } -/* -================= -BoundsIntersect -================= -*/ -qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 ) -{ - if( mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2] ) - return false; - if( maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2] ) - return false; - return true; -} - -/* -================= -BoundsAndSphereIntersect -================= -*/ -qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius ) -{ - if( mins[0] > origin[0] + radius || mins[1] > origin[1] + radius || mins[2] > origin[2] + radius ) - return false; - if( maxs[0] < origin[0] - radius || maxs[1] < origin[1] - radius || maxs[2] < origin[2] - radius ) - return false; - return true; -} - /* ================= SphereIntersect diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 598d2d1b..ce0a58c5 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -195,10 +195,32 @@ void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles ); void PlaneIntersect( const struct mplane_s *plane, const vec3_t p0, const vec3_t p1, vec3_t out ); -void ClearBounds( vec3_t mins, vec3_t maxs ); +static inline void ClearBounds( vec3_t mins, vec3_t maxs ) +{ + // make bogus range + mins[0] = mins[1] = mins[2] = 999999.0f; + maxs[0] = maxs[1] = maxs[2] = -999999.0f; +} + +static inline qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 ) +{ + if( mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2] ) + return false; + if( maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2] ) + return false; + return true; +} + +static inline qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius ) +{ + if( mins[0] > origin[0] + radius || mins[1] > origin[1] + radius || mins[2] > origin[2] + radius ) + return false; + if( maxs[0] < origin[0] - radius || maxs[1] < origin[1] - radius || maxs[2] < origin[2] - radius ) + return false; + return true; +} + void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); -qboolean BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 ); -qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t origin, float radius ); qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir ); float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ); void ExpandBounds( vec3_t mins, vec3_t maxs, float offset );