]> git.localhorst.tv Git - orbi.git/blobdiff - src/world/AABB.h
orientation for entities
[orbi.git] / src / world / AABB.h
index a0e3436194fd57dbee28b06682babc553ef6edd2..ca7b85729e6609efcbb4e156a1f729de70205b3b 100644 (file)
@@ -13,9 +13,9 @@ class AABB {
 public:
        constexpr AABB() { }
        constexpr AABB(Vector<float> pos, Vector<float> size)
-       : lt(pos), rb(pos + size) { }
+       : size(size), lt(pos), rb(pos + size) { }
        constexpr AABB(float x, float y, float w, float h)
-       : lt(x, y), rb(x + w, y + h) { }
+       : size(w, h), lt(x, y), rb(x + w, y + h) { }
 
 public:
        float Left() const { return lt.x; }
@@ -23,19 +23,24 @@ public:
        float Right() const { return rb.x; }
        float Bottom() const { return rb.y; }
 
-       Vector<float> Position() const { return lt; }
+       Vector<float> LeftTop() const { return lt; }
+       Vector<float> LeftBottom() const { return Vector<float>(lt.x, rb.y); }
+       Vector<float> RightTop() const { return Vector<float>(rb.x, lt.y); }
+       Vector<float> RightBottom() const { return rb; }
+
        Vector<float> Center() const { return lt + HalfSize(); }
        Vector<float> HalfSize() const { return Size() / 2.0f; }
-       Vector<float> Size() const { return rb - lt; }
+       Vector<float> Size() const { return size; }
 
 public:
-       void Move(Vector<float> delta) { lt += delta; rb += delta; }
+       void Move(Vector<float> delta) { lt += delta; rb = lt + size; }
        void Resize(Vector<float> size) { *this = AABB(lt, size); }
 
        bool Intersects(const AABB &other) const;
        bool Intersects(const AABB &other, Collision &) const;
 
 private:
+       Vector<float> size;
        Vector<float> lt;
        Vector<float> rb;