]> git.localhorst.tv Git - orbi.git/blob - src/world/AABB.h
9a2d5ebbef4bbe4a3e7a9214d3c9ab9765805163
[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         : lt(pos), rb(pos + size) { }
17         constexpr AABB(float x, float y, float w, float h)
18         : 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 rb - lt; }
30
31 public:
32         void Move(Vector<float> delta) { lt += delta; rb += delta; }
33         void Resize(Vector<float> size) { *this = AABB(lt, size); }
34
35         bool Intersects(const AABB &other, Collision &) const;
36
37 private:
38         Vector<float> lt;
39         Vector<float> rb;
40
41 };
42
43 }
44
45 #endif