diff options
| author | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
| commit | f8b92ce3aa08b1445c9f956d8166830946562d12 (patch) | |
| tree | 94e63a5aec9f8f52b577f56799e0c9201fd976a5 /src/util/aabb.h | |
a
Diffstat (limited to 'src/util/aabb.h')
| -rw-r--r-- | src/util/aabb.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util/aabb.h b/src/util/aabb.h new file mode 100644 index 0000000..f2fd251 --- /dev/null +++ b/src/util/aabb.h @@ -0,0 +1,30 @@ +#pragma once + +#include "vector.h" + +struct AABB { + VEC3 min; + VEC3 max; +}; + +inline VEC3 aabb_center( const AABB& aabb ) { return (aabb.min + aabb.max) * 0.5f; } +inline VEC3 aabb_half( const AABB& aabb ) { return (aabb.max - aabb.min) * 0.5f; } +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 VEC2 aabb_extend_at_feet( const AABB& aabb, const VEC3& dir ) { + VEC3 half = aabb_half( aabb ); + + F32 hx = half.x; + F32 hy = half.y; + F32 hz = half.z * 2; + + F32 lateral = fabsf( dir.x ) * hx + fabsf( dir.y ) * hy; + + F32 pos_z = dir.z > 0 ? dir.z * hz : 0.f; + F32 neg_z = dir.z < 0 ? (-dir.z) * hz : 0.f; + + return { lateral + pos_z, lateral + neg_z }; +} |
