]> git.localhorst.tv Git - sdl-test8.git/blob - src/shape/AABB.h
some comments
[sdl-test8.git] / src / shape / AABB.h
1 /*
2  * AABB.h
3  *
4  *  Created on: Apr 30, 2012
5  *      Author: holy
6  */
7
8 #ifndef SHAPE_AABB_H_
9 #define SHAPE_AABB_H_
10
11 #include "Shape.h"
12
13 namespace shape {
14
15 /// An axes aligned bounding box.
16 /// This shape cannot be rotated.
17 class AABB
18 : public Shape {
19
20         public:
21                 AABB(void) { };
22                 AABB(Scalar width, Scalar height) : leftTop(-width/2, -height/2), rightBottom(width/2, height/2) { };
23                 virtual ~AABB(void) { };
24
25         public:
26                 Scalar Left(void) const { return leftTop.X(); };
27                 Scalar Top(void) const { return leftTop.Y(); };
28                 Scalar Right(void) const { return rightBottom.X(); };
29                 Scalar Bottom(void) const { return rightBottom.Y(); };
30
31                 Vector Center(void) const { return leftTop + (rightBottom - leftTop) / 2; };
32                 Scalar Width(void) const { return Right() - Left(); };
33                 Scalar Height(void) const { return Bottom() - Top(); };
34
35         public:
36                 virtual void Translate(const Vector &delta);
37                 virtual void Rotate(Scalar delta);
38
39         public:
40                 virtual bool CheckCollision(const Shape &, Ray &) const;
41                 virtual bool CheckCollision(const AABB &, Ray &) const;
42                 virtual bool CheckCollision(const Circle &, Ray &) const;
43
44         public:
45                 virtual std::ostream &Write(std::ostream &) const;
46
47         private:
48                 Vector leftTop, rightBottom;
49
50 };
51
52 }
53
54 #endif /* SHAPE_AABB_H_ */