From ca8b16620ec207f2b32edd1f5d46f7b0bfb0a14c Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 21 Nov 2023 02:28:00 +0100 Subject: Clumsy non-swept AABB collision system for Player --- src/Math/AABB.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Math/AABB.cpp (limited to 'src/Math/AABB.cpp') diff --git a/src/Math/AABB.cpp b/src/Math/AABB.cpp new file mode 100644 index 0000000..aa814a1 --- /dev/null +++ b/src/Math/AABB.cpp @@ -0,0 +1,17 @@ +// This file breaks the Ray.hpp <-> AABB.hpp dependency cycle. + +#include "AABB.hpp" +#include "Ray.hpp" + +AABB AABB::cast_box(Vector<3> v, AABB against) const { + auto ray = Ray{center(), v}; + + auto expanded_target = against.sum(*this); + auto raycast = ray.cast(expanded_target); + if (!raycast.hit) return *this; + + auto result_from = raycast.point - size() / 2.0; + auto result_to = result_from + size(); + + return {result_from, result_to}; +} -- cgit 1.4.1