]> git.localhorst.tv Git - orbi.git/blob - src/world/AABB.h
20580caaded42e57f994432de8890820cbcc9b2c
[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 AABB {
10
11 public:
12         constexpr AABB() { }
13         constexpr AABB(Vector<float> pos, Vector<float> size)
14         : lt(pos), rb(pos + size) { }
15         constexpr AABB(float x, float y, float w, float h)
16         : lt(x, y), rb(x + w, y + h) { }
17
18 public:
19         float Left() const { return lt.x; }
20         float Top() const { return lt.y; }
21         float Right() const { return rb.x; }
22         float Bottom() const { return rb.y; }
23
24         Vector<float> Position() const { return lt; }
25         Vector<float> Center() const { return lt + HalfSize(); }
26         Vector<float> HalfSize() const { return Size() / 2.0f; }
27         Vector<float> Size() const { return rb - lt; }
28
29 public:
30         void Move(Vector<float> delta) { lt += delta; rb += delta; }
31         void Resize(Vector<float> size) { *this = AABB(lt, size); }
32
33         bool Intersects(const AABB &other, Vector<float> &p, Vector<float> &n, Vector<float> &d) const;
34
35 private:
36         Vector<float> lt;
37         Vector<float> rb;
38
39 };
40
41 }
42
43 #endif