X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fshape%2FAABB.h;fp=src%2Fshape%2FAABB.h;h=956114aa1f8d397756340fa637b6bee6d54a818c;hb=8b4877fe48d21d7e789cf52f81c1d6a87b06bcbc;hp=0000000000000000000000000000000000000000;hpb=42db59e3850c958821e8396fadc20fbeb71050c4;p=sdl-test8.git diff --git a/src/shape/AABB.h b/src/shape/AABB.h new file mode 100644 index 0000000..956114a --- /dev/null +++ b/src/shape/AABB.h @@ -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_ */