From f40d09cb8f712e87691af4912f3630d92d692779 Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Dec 2025 15:14:26 +0500 Subject: Shuffle stuff around - Use the new and improved hierarchy I figured out when making Prospero chat - Re-add NSIS scripts, again from Prospero - Update most build and utility scripts with their most recent versions --- src/core/math/aabb.hh | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/core/math/aabb.hh (limited to 'src/core/math/aabb.hh') diff --git a/src/core/math/aabb.hh b/src/core/math/aabb.hh new file mode 100644 index 0000000..a235a9b --- /dev/null +++ b/src/core/math/aabb.hh @@ -0,0 +1,111 @@ +#pragma once + +#include "core/math/concepts.hh" + +namespace math +{ +template +class AABB { +public: + using value_type = T; + using vector_type = glm::vec<3, T>; + + constexpr AABB(void) = default; + constexpr explicit AABB(const vector_type& start, const vector_type& end); + virtual ~AABB(void) = default; + + constexpr void set_bounds(const vector_type& start, const vector_type& end); + constexpr void set_offset(const vector_type& base, const vector_type& size); + + constexpr bool contains(const vector_type& point) const; + constexpr bool intersect(const AABB& other_box) const; + + constexpr AABB combine(const AABB& other_box) const; + constexpr AABB multiply(const AABB& other_box) const; + constexpr AABB push(const vector_type& vector) const; + +public: + vector_type min {}; + vector_type max {}; +}; +} // namespace math + +namespace math +{ +using AABBf = AABB; +} // namespace math + +template +constexpr math::AABB::AABB(const vector_type& start, const vector_type& end) +{ + set_bounds(start, end); +} + +template +constexpr void math::AABB::set_bounds(const vector_type& start, const vector_type& end) +{ + min = start; + max = end; +} + +template +constexpr void math::AABB::set_offset(const vector_type& base, const vector_type& size) +{ + min = base; + max = base + size; +} + +template +constexpr bool math::AABB::contains(const vector_type& point) const +{ + auto result = true; + result = result && (point.x >= min.x) && (point.x <= max.x); + result = result && (point.y >= min.y) && (point.y <= max.y); + result = result && (point.z >= min.z) && (point.z <= max.z); + return result; +} + +template +constexpr bool math::AABB::intersect(const AABB& other_box) const +{ + auto result = true; + result = result && (min.x <= other_box.max.x) && (max.x >= other_box.min.x); + result = result && (min.y <= other_box.max.y) && (max.y >= other_box.min.y); + result = result && (min.z <= other_box.max.z) && (max.z >= other_box.min.z); + return result; +} + +template +constexpr math::AABB math::AABB::combine(const AABB& other_box) const +{ + AABB result; + result.min.x = glm::min(min.x, other_box.min.x); + result.min.y = glm::min(min.y, other_box.min.y); + result.min.z = glm::min(min.z, other_box.min.z); + result.max.x = glm::max(max.x, other_box.max.x); + result.max.y = glm::max(max.y, other_box.max.y); + result.max.z = glm::max(max.z, other_box.max.z); + return result; +} + +template +constexpr math::AABB math::AABB::multiply(const AABB& other_box) const +{ + AABB result; + result.min.x = glm::max(min.x, other_box.min.x); + result.min.y = glm::max(min.y, other_box.min.y); + result.min.z = glm::max(min.z, other_box.min.z); + result.max.x = glm::min(max.x, other_box.max.x); + result.max.y = glm::min(max.y, other_box.max.y); + result.max.z = glm::min(max.z, other_box.max.z); + return result; +} + +template +constexpr math::AABB math::AABB::push(const vector_type& vector) const +{ + AABB result; + result.min = min + vector; + result.max = max + vector; + return result; +} -- cgit