]> git.localhorst.tv Git - orbi.git/blobdiff - src/world/AABB.cpp
rotatable arm for character entities
[orbi.git] / src / world / AABB.cpp
index 0ed5a63934b8e1e11a9243a3e76b0a3255279253..92c8ba2014f017632c54e7c50074010f8f973a86 100644 (file)
@@ -1,15 +1,21 @@
 #include "AABB.h"
 
 #include "Collision.h"
+#include "../graphics/const.h"
 
 
 namespace orbi {
 
-bool AABB::Intersects(const AABB &other, Collision &coll) const {
+bool AABB::Intersects(const AABB &other) 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;
+       return true;
+}
+
+bool AABB::Intersects(const AABB &other, Collision &coll) const {
+       if (!Intersects(other)) return false;
 
        AABB diff;
        diff.lt = max(lt, other.lt);
@@ -19,7 +25,7 @@ bool AABB::Intersects(const AABB &other, Collision &coll) const {
        if (sdiff.x < sdiff.y) {
                coll.pos.y = diff.Center().y;
                coll.norm.y = 0;
-               coll.depth.y = 0;
+               coll.depth.y = sdiff.y * sigma(Center().y - other.Center().y);
                if (Center().x < other.Center().x) {
                        coll.pos.x = Right();
                        coll.norm.x = -1;
@@ -33,6 +39,7 @@ bool AABB::Intersects(const AABB &other, Collision &coll) const {
                coll.pos.x = diff.Center().x;
                coll.norm.x = 0;
                coll.depth.x = 0;
+               coll.depth.x = sdiff.x * sigma(Center().x - other.Center().x);
                if (Center().y < other.Center().y) {
                        coll.pos.y = Bottom();
                        coll.norm.y = -1;