4 * Created on: Apr 10, 2012
8 #ifndef GEOMETRY_AABB_H_
9 #define GEOMETRY_AABB_H_
23 AABB(void) : leftTop(), rightBottom() { };
24 explicit AABB(const Vector &size) : leftTop(), rightBottom(size) { };
25 AABB(const Vector &position, const Vector &size)
26 : leftTop(position), rightBottom(position + size) { };
27 virtual ~AABB(void) { };
30 Scalar Left(void) const { return leftTop.X(); };
31 Scalar Top(void) const { return leftTop.Y(); };
32 Scalar Right(void) const { return rightBottom.X(); };
33 Scalar Bottom(void) const { return rightBottom.Y(); };
35 Scalar X(void) const { return Left(); };
36 Scalar Y(void) const { return Top(); };
37 Scalar Width(void) const { return Right() - Left(); };
38 Scalar Height(void) const { return Bottom() - Top(); };
41 virtual bool Overlaps(const Shape &other, Vector &normal) const;
42 virtual bool Overlaps(const AABB &other, Vector &normal) const;
43 virtual bool Overlaps(const Circle &other, Vector &normal) const;
44 virtual bool Overlaps(const FakeLens &, Vector &normal) const;
46 bool VerticalOverlap(const AABB &other) const {
47 if (Bottom() < other.Top()) return false;
48 if (other.Bottom() < Top()) return false;
51 bool HorizontalOverlap(const AABB &other) const {
52 if (Right() < other.Left()) return false;
53 if (other.Right() < Left()) return false;
58 void Move(const Vector &delta) {
63 void SetBounds(const Vector &position, const Vector &size) {
65 rightBottom = position + size;
67 void SetPosition(const Vector &position) {
68 rightBottom = position + (rightBottom - leftTop);
71 void SetSize(const Vector &size) {
72 rightBottom = leftTop + size;
75 virtual Vector Center(void) const {
76 return leftTop + (rightBottom - leftTop) / 2;
79 virtual std::ostream &Write(std::ostream &out) const;
82 void WriteRect(SDL_Rect &rect) const {
90 Vector leftTop, rightBottom;
96 #endif /* GEOMETRY_AABB_H_ */