summary refs log tree commit diff
path: root/src/Math/AABB.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-11-21 02:28:00 +0100
committerMel <einebeere@gmail.com>2023-11-21 02:28:00 +0100
commitca8b16620ec207f2b32edd1f5d46f7b0bfb0a14c (patch)
tree02746322c4229431e36b892f11f07a81ce21e439 /src/Math/AABB.cpp
parent272e6a63df7369e5afcb16c5a6c14f7dd6a75893 (diff)
downloadmeowcraft-ca8b16620ec207f2b32edd1f5d46f7b0bfb0a14c.tar.zst
meowcraft-ca8b16620ec207f2b32edd1f5d46f7b0bfb0a14c.zip
Clumsy non-swept AABB collision system for Player
Diffstat (limited to 'src/Math/AABB.cpp')
-rw-r--r--src/Math/AABB.cpp17
1 files changed, 17 insertions, 0 deletions
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};
+}