]> git.localhorst.tv Git - sdl-test8.git/blob - src/shape/AABB.h
added collision engine, more or less stole gameplay from sdl-test7
[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 class AABB
16 : public Shape {
17
18         public:
19                 AABB(void) { };
20                 AABB(Scalar width, Scalar height) : leftTop(-width/2, -height/2), rightBottom(width/2, height/2) { };
21                 virtual ~AABB(void) { };
22
23         public:
24                 Scalar Left(void) const { return leftTop.X(); };
25                 Scalar Top(void) const { return leftTop.Y(); };
26                 Scalar Right(void) const { return rightBottom.X(); };
27                 Scalar Bottom(void) const { return rightBottom.Y(); };
28
29                 Vector Center(void) const { return leftTop + (rightBottom - leftTop) / 2; };
30                 Scalar Width(void) const { return Right() - Left(); };
31                 Scalar Height(void) const { return Bottom() - Top(); };
32
33         public:
34                 virtual void Translate(const Vector &delta);
35                 virtual void Rotate(Scalar delta);
36
37         public:
38                 virtual bool CheckCollision(const Shape &, Ray &) const;
39                 virtual bool CheckCollision(const AABB &, Ray &) const;
40                 virtual bool CheckCollision(const Circle &, Ray &) const;
41
42         public:
43                 virtual std::ostream &Write(std::ostream &) const;
44
45         private:
46                 Vector leftTop, rightBottom;
47
48 };
49
50 }
51
52 #endif /* SHAPE_AABB_H_ */