]> git.localhorst.tv Git - orbi.git/blobdiff - src/world/AABB.cpp
some cleanup
[orbi.git] / src / world / AABB.cpp
index c54537e16ee9f6e40b99b75e552a7f720fe2ab6e..0ed5a63934b8e1e11a9243a3e76b0a3255279253 100644 (file)
@@ -1,39 +1,46 @@
 #include "AABB.h"
 
+#include "Collision.h"
+
+
 namespace orbi {
 
-bool AABB::Intersects(const AABB &other, Vector<float> &p, Vector<float> &n, Vector<float> &d) const {
+bool AABB::Intersects(const AABB &other, Collision &coll) const {
        if (Bottom() < other.Top()) return false;
        if (other.Bottom() < Top()) return false;
        if (Right() < other.Left()) return false;
        if (other.Right() < Left()) return false;
 
        AABB diff;
-       diff.lt.x = std::max(Left(), other.Left());
-       diff.lt.y = std::max(Top(), other.Top());
-       diff.rb.x = std::min(Right(), other.Right());
-       diff.rb.y = std::min(Bottom(), other.Bottom());
+       diff.lt = max(lt, other.lt);
+       diff.rb = min(rb, other.rb);
        const Vector<float> sdiff = diff.Size();
 
        if (sdiff.x < sdiff.y) {
+               coll.pos.y = diff.Center().y;
+               coll.norm.y = 0;
+               coll.depth.y = 0;
                if (Center().x < other.Center().x) {
-                       p = Vector<float>(Right(), ((Top() + Bottom()) / 2 + (other.Top() + other.Bottom()) / 2) / 2);
-                       n = Vector<float>(-1, 0);
-                       d = Vector<float>(other.Left() - Right(), 0);
+                       coll.pos.x = Right();
+                       coll.norm.x = -1;
+                       coll.depth.x = other.Left() - Right();
                } else {
-                       p = Vector<float>(Left(), ((Top() + Bottom()) / 2 + (other.Top() + other.Bottom()) / 2) / 2);
-                       n = Vector<float>(1, 0);
-                       d = Vector<float>(other.Right() - Left(), 0);
+                       coll.pos.x = Left();
+                       coll.norm.x = 1;
+                       coll.depth.x = other.Right() - Left();
                }
        } else {
+               coll.pos.x = diff.Center().x;
+               coll.norm.x = 0;
+               coll.depth.x = 0;
                if (Center().y < other.Center().y) {
-                       p = Vector<float>(((Left() + Right()) / 2 + (other.Left() + other.Right()) / 2) / 2, Bottom());
-                       n = Vector<float>(0, -1);
-                       d = Vector<float>(0, other.Top() - Bottom());
+                       coll.pos.y = Bottom();
+                       coll.norm.y = -1;
+                       coll.depth.y = other.Top() - Bottom();
                } else {
-                       p = Vector<float>(((Left() + Right()) / 2 + (other.Left() + other.Right()) / 2) / 2, Top());
-                       n = Vector<float>(0, 1);
-                       d = Vector<float>(0, other.Bottom() - Top());
+                       coll.pos.y = Top();
+                       coll.norm.y = 1;
+                       coll.depth.y = other.Bottom() - Top();
                }
        }
        return true;