]> git.localhorst.tv Git - orbi.git/blob - src/world/AABB.h
5b482c4cc701ae9fe6fa9eb8d568bb5b56508f87
[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> Position() const { return lt; }
27         Vector<float> Center() const { return lt + HalfSize(); }
28         Vector<float> HalfSize() const { return Size() / 2.0f; }
29         Vector<float> Size() const { return size; }
30
31 public:
32         void Move(Vector<float> delta) { lt += delta; rb = lt + size; }
33         void Resize(Vector<float> size) { *this = AABB(lt, size); }
34
35         bool Intersects(const AABB &other) const;
36         bool Intersects(const AABB &other, Collision &) const;
37
38 private:
39         Vector<float> size;
40         Vector<float> lt;
41         Vector<float> rb;
42
43 };
44
45 }
46
47 #endif