]> git.localhorst.tv Git - sdl-test8.git/blobdiff - src/shape/AABB.h
added collision engine, more or less stole gameplay from sdl-test7
[sdl-test8.git] / src / shape / AABB.h
diff --git a/src/shape/AABB.h b/src/shape/AABB.h
new file mode 100644 (file)
index 0000000..956114a
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * AABB.h
+ *
+ *  Created on: Apr 30, 2012
+ *      Author: holy
+ */
+
+#ifndef SHAPE_AABB_H_
+#define SHAPE_AABB_H_
+
+#include "Shape.h"
+
+namespace shape {
+
+class AABB
+: public Shape {
+
+       public:
+               AABB(void) { };
+               AABB(Scalar width, Scalar height) : leftTop(-width/2, -height/2), rightBottom(width/2, height/2) { };
+               virtual ~AABB(void) { };
+
+       public:
+               Scalar Left(void) const { return leftTop.X(); };
+               Scalar Top(void) const { return leftTop.Y(); };
+               Scalar Right(void) const { return rightBottom.X(); };
+               Scalar Bottom(void) const { return rightBottom.Y(); };
+
+               Vector Center(void) const { return leftTop + (rightBottom - leftTop) / 2; };
+               Scalar Width(void) const { return Right() - Left(); };
+               Scalar Height(void) const { return Bottom() - Top(); };
+
+       public:
+               virtual void Translate(const Vector &delta);
+               virtual void Rotate(Scalar delta);
+
+       public:
+               virtual bool CheckCollision(const Shape &, Ray &) const;
+               virtual bool CheckCollision(const AABB &, Ray &) const;
+               virtual bool CheckCollision(const Circle &, Ray &) const;
+
+       public:
+               virtual std::ostream &Write(std::ostream &) const;
+
+       private:
+               Vector leftTop, rightBottom;
+
+};
+
+}
+
+#endif /* SHAPE_AABB_H_ */