namespace app {
+/// Objects of class keep track of the current delta and the time elapsed since
+/// their respective incarnation (which may also be tampered with).
+/// It's also possible to scale the time e.g. for slow-motion or fast-forwarding.
class Timer {
public:
}
void AABB::Rotate(Scalar delta) {
-
+ // by definition AABBs cannot rotate
}
bool AABB::CheckCollision(const Shape &other, Ray &na) const {
+ // This call reveals the real type of this shape by overloading and the
+ // other one via polymorphism.
if (other.CheckCollision(*this, na)) {
+ // Since the other shape's collision check returns its own surface
+ // normal, it has to be inverted here.
na.Direction() *= -1;
return true;
} else {
class AABB;
class Circle;
+/// Base class for all "shapes" (i.e. collision primitives).
+/// This serves as an interface for game::Entity to double dispatch the
+/// collision detection algorithms.
class Shape {
public:
virtual ~Shape(void) { };
public:
+ /// Move the shape by given delta.
virtual void Translate(const Vector &delta) = 0;
+ /// Rotate the shape by given delta (in radians).
virtual void Rotate(Scalar delta) = 0;
public:
+ /// Check if this shape overlaps the given and, if it does, write the
+ /// surface normal into given vector.
+ /// All shapes must override this method to dispatch to the specialized
+ /// version of CheckCollision().
+ /// See AABB::CheckCollision(const Shape &, Ray &) const for details.
virtual bool CheckCollision(const Shape &, Ray &) const = 0;
virtual bool CheckCollision(const AABB &, Ray &) const = 0;
virtual bool CheckCollision(const Circle &, Ray &) const = 0;