4 * Created on: Apr 20, 2012
12 #include "../game/Entity.h"
17 bool Circle::Overlaps(const Shape &other, Vector &normal) const {
18 if (other.Overlaps(*this, normal)) {
26 bool Circle::Overlaps(const AABB &other, Vector &normal) const {
27 // fast checks for far away shapes
28 if (Bottom() <= other.Top()) return false;
29 if (other.Bottom() <= Top()) return false;
30 if (Right() <= other.Left()) return false;
31 if (other.Right() <= Left()) return false;
34 X() < other.Left() ? 0 : (
35 other.Right() < X() ? 2 : 1));
37 Y() < other.Top() ? 0 : (
38 other.Bottom() < Y() ? 2 : 1));
39 int zone(xZone + 3*yZone);
42 normal = (Center() - other.Center()).Unit();
47 if (xZone == 1) { // vertical
48 if (Bottom() < other.Top()) return false;
49 if (other.Bottom() < Top()) return false;
51 if (Bottom() < other.Bottom()) {
52 normal = Vector(0, -1);
54 normal = Vector(0, 1);
59 if (Right() < other.Left()) return false;
60 if (other.Right() < Left()) return false;
62 if (Left() < other.Left()) {
63 normal = Vector(-1, 0);
65 normal = Vector(1, 0);
72 yZone ? other.Right() : other.Left(),
73 xZone ? other.Bottom() : other.Top());
74 Vector distance(position - near);
75 Sint32 distanceSquared(distance.LengthSquared());
76 if (distanceSquared < (Radius() * Radius())) {
77 normal = distance.Unit();
85 bool Circle::Overlaps(const Circle &other, Vector &normal) const {
86 Vector delta(position - other.position);
87 Sint32 distanceSquared(delta.LengthSquared()), minDistance(Radius() + other.Radius());
88 if (distanceSquared < (minDistance * minDistance)) {
89 normal = delta.Unify();
96 bool Circle::Overlaps(const FakeLens &other, Vector &normal) const {
97 if (other.Overlaps(*this, normal)) {
105 std::ostream &Circle::Write(std::ostream &out) const {
106 return out << "Circle(" << Radius() << '+' << Top() << '+' << Left() << ')';