]> git.localhorst.tv Git - sdl-test7.git/blob - src/geometry/Shape.h
added some comments
[sdl-test7.git] / src / geometry / Shape.h
1 /*
2  * Shape.h
3  *
4  *  Created on: Apr 20, 2012
5  *      Author: holy
6  */
7
8 #ifndef GEOMETRY_SHAPE_H_
9 #define GEOMETRY_SHAPE_H_
10
11 #include "Vector2D.h"
12
13 #include <limits>
14 #include <ostream>
15
16 namespace geometry {
17
18 class AABB;
19 class Circle;
20 class FakeLens;
21
22 /// Base class for all "shapes" (i.e. collision primitives).
23 /// This serves as an interface for game::Entity to double dispatch the
24 /// collision detection algorithms.
25 class Shape {
26
27         public:
28                 typedef float Scalar;
29                 typedef Vector2D<Scalar> Vector;
30                 typedef std::numeric_limits<Scalar> Limits;
31
32         protected:
33                 Shape(void) { };
34                 virtual ~Shape(void) { };
35
36         public:
37                 /// Check if this shape overlaps the given and, if it does, write the
38                 /// surface normal into given vector.
39                 /// All shapes must override this method to dispatch to the specialized
40                 /// version of Overlaps().
41                 /// See AABB::Overlaps(const Shape &, Vector &normal) const for details.
42                 virtual bool Overlaps(const Shape &, Vector &normal) const = 0;
43
44                 virtual bool Overlaps(const AABB &, Vector &normal) const = 0;
45                 virtual bool Overlaps(const Circle &, Vector &normal) const = 0;
46                 virtual bool Overlaps(const FakeLens &, Vector &normal) const = 0;
47
48         public:
49                 virtual std::ostream &Write(std::ostream &out) const = 0;
50
51         public:
52                 virtual void SetPosition(const Vector &) = 0;
53                 virtual Vector Center(void) const = 0;
54
55 };
56
57 }
58
59
60 namespace std {
61
62 inline ostream &operator <<(ostream &out, const geometry::Shape &s) {
63         return s.Write(out);
64 };
65
66 }
67
68 #endif /* GEOMETRY_SHAPE_H_ */