4 * Created on: Apr 30, 2012
14 void AABB::Translate(const Vector &delta) {
19 void AABB::Rotate(Scalar delta) {
24 bool AABB::CheckCollision(const Shape &other, Ray &na) const {
25 if (other.CheckCollision(*this, na)) {
33 bool AABB::CheckCollision(const AABB &other, Ray &na) const {
34 if (Bottom() <= other.Top()) return false;
35 if (other.Bottom() <= Top()) return false;
36 if (Right() <= other.Left()) return false;
37 if (other.Right() <= Left()) return false;
39 if (Bottom() <= other.Top() || other.Bottom() <= Top()) {
40 if (Left() < other.Left()) {
41 na.Origin() = Vector(((Top() + Bottom()) / 2 + (other.Top() + other.Bottom()) / 2) / 2, Right());
42 na.Direction() = Vector(-1, 0);
44 na.Origin() = Vector(((Top() + Bottom()) / 2 + (other.Top() + other.Bottom()) / 2) / 2, Left());
45 na.Direction() = Vector(1, 0);
48 if (Top() < other.Top()) {
49 na.Origin() = Vector(Bottom(), ((Left() + Right()) / 2 + (other.Left() + other.Right()) / 2) / 2);
50 na.Direction() = Vector(0, -1);
52 na.Origin() = Vector(Top(), ((Left() + Right()) / 2 + (other.Left() + other.Right()) / 2) / 2);
53 na.Direction() = Vector(0, 1);
59 bool AABB::CheckCollision(const Circle &other, Ray &na) const {
60 if (other.CheckCollision(*this, na)) {
69 std::ostream &AABB::Write(std::ostream &out) const {
70 return out << "AABB(" << Width() << 'x' << Height() << ", " << Center() << ')';