From e57cac01b0a4eb764185e8eca9396a25b83f34d3 Mon Sep 17 00:00:00 2001 From: aura Date: Tue, 3 Mar 2026 16:16:06 +0100 Subject: edge planes ))) --- src/util/aabb.h | 20 ++++++++++++++++++++ src/util/vector.h | 9 +++++++++ 2 files changed, 29 insertions(+) (limited to 'src/util') diff --git a/src/util/aabb.h b/src/util/aabb.h index 96e40bf..9dc4b20 100644 --- a/src/util/aabb.h +++ b/src/util/aabb.h @@ -13,3 +13,23 @@ inline F32 aabb_support_radius( const AABB& aabb, const VEC3& dir ) { VEC3 half = aabb_half( aabb ); return fabsf(dir.x) * half.x + fabsf(dir.y) * half.y + fabsf(dir.z) * half.z; } + +inline U8 aabb_intersects( const AABB& aabb, const AABB& other ) { + if (aabb.min.x > other.max.x || aabb.max.x < other.min.x) + return 0; + if (aabb.min.y > other.max.y || aabb.max.y < other.min.y) + return 0; + if (aabb.min.z > other.max.z || aabb.max.z < other.min.z) + return 0; + return 1; +} + +inline U8 aabb_contains_point( const AABB& aabb, const VEC3& point ) { + if (point.x < aabb.min.x || point.x > aabb.max.x) + return 0; + if (point.y < aabb.min.y || point.y > aabb.max.y) + return 0; + if (point.z < aabb.min.z || point.z > aabb.max.z) + return 0; + return 1; +} diff --git a/src/util/vector.h b/src/util/vector.h index 6065343..33409a7 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -119,6 +119,15 @@ struct VEC4 { VEC4 operator/( const F32& v ) { return VEC4( x / v, y / v, z / v, w / v ); } }; +static const VEC2 vec2_right = { 1.f, 0.f }; +static const VEC2 vec2_forward = { 0.f, 1.f }; +static const VEC2 vec2_axis[] = { vec2_right, vec2_forward }; + +static const VEC3 vec3_up = { 0.f, 0.f, 1.f }; +static const VEC3 vec3_right = { 1.f, 0.f, 0.f }; +static const VEC3 vec3_forward = { 0.f, 1.f, 0.f }; +static const VEC3 vec3_axis[] = { vec3_right, vec3_forward, vec3_up }; + inline U8 is_zero( VEC2 v ) { return v.x == 0.f && v.y == 0.f; } inline U8 is_zero( VEC3 v ) { return v.x == 0.f && v.y == 0.f && v.z == 0.f; } inline U8 is_zero( VEC4 v ) { return v.x == 0.f && v.y == 0.f && v.z == 0.f && v.w == 0.f; } -- cgit v1.2.3