X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FAABB.cpp;h=92c8ba2014f017632c54e7c50074010f8f973a86;hb=a73a6dd63407b5f5ef5b0c635551ad27b27c95d6;hp=0ed5a63934b8e1e11a9243a3e76b0a3255279253;hpb=962405ec344818a7f6850d243feca7989ae5d41b;p=orbi.git diff --git a/src/world/AABB.cpp b/src/world/AABB.cpp index 0ed5a63..92c8ba2 100644 --- a/src/world/AABB.cpp +++ b/src/world/AABB.cpp @@ -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;