]> git.localhorst.tv Git - orbi.git/blob - src/world/AABB.h
orientation for entities
[orbi.git] / src / world / AABB.h
1 #ifndef ORBI_AABB_H_
2 #define ORBI_AABB_H_
3
4 #include "../graphics/Vector.h"
5
6
7 namespace orbi {
8
9 class Collision;
10
11 class AABB {
12
13 public:
14         constexpr AABB() { }
15         constexpr AABB(Vector<float> pos, Vector<float> size)
16         : size(size), lt(pos), rb(pos + size) { }
17         constexpr AABB(float x, float y, float w, float h)
18         : size(w, h), lt(x, y), rb(x + w, y + h) { }
19
20 public:
21         float Left() const { return lt.x; }
22         float Top() const { return lt.y; }
23         float Right() const { return rb.x; }
24         float Bottom() const { return rb.y; }
25
26         Vector<float> LeftTop() const { return lt; }
27         Vector<float> LeftBottom() const { return Vector<float>(lt.x, rb.y); }
28         Vector<float> RightTop() const { return Vector<float>(rb.x, lt.y); }
29         Vector<float> RightBottom() const { return rb; }
30
31         Vector<float> Center() const { return lt + HalfSize(); }
32         Vector<float> HalfSize() const { return Size() / 2.0f; }
33         Vector<float> Size() const { return size; }
34
35 public:
36         void Move(Vector<float> delta) { lt += delta; rb = lt + size; }
37         void Resize(Vector<float> size) { *this = AABB(lt, size); }
38
39         bool Intersects(const AABB &other) const;
40         bool Intersects(const AABB &other, Collision &) const;
41
42 private:
43         Vector<float> size;
44         Vector<float> lt;
45         Vector<float> rb;
46
47 };
48
49 }
50
51 #endif