4 * Created on: Apr 29, 2012
14 void Circle::Translate(const Vector &delta) {
18 void Circle::Rotate(Scalar delta) {
23 bool Circle::CheckCollision(const Shape &other, Ray &na) const {
24 if (other.CheckCollision(*this, na)) {
32 bool Circle::CheckCollision(const AABB &other, Ray &na) const {
34 center.X() < other.Left() ? 0 : (
35 other.Right() < center.X() ? 2 : 1));
37 center.Y() < other.Top() ? 0 : (
38 other.Bottom() < center.Y() ? 2 : 1));
39 int zone(xZone + 3 * yZone);
43 na.Direction() = (center - other.Center()).Unit();
48 if (xZone == 1) { // vertical
49 if (Bottom() < other.Top()) return false;
50 if (other.Bottom() < Top()) return false;
52 if (Bottom() < other.Bottom()) {
53 na.Origin() = Vector(center.X(), Bottom());
54 na.Direction() = Vector(0, -1);
56 na.Origin() = Vector(center.X(), Top());
57 na.Direction() = Vector(0, 1);
62 if (Right() < other.Left()) return false;
63 if (other.Right() < Left()) return false;
65 if (Left() < other.Left()) {
66 na.Origin() = Vector(Left(), center.Y());
67 na.Direction() = Vector(-1, 0);
69 na.Origin() = Vector(Right(), center.Y());
70 na.Direction() = Vector(1, 0);
77 yZone ? other.Right() : other.Left(),
78 xZone ? other.Bottom() : other.Top());
79 Vector distance(Center() - near);
80 Scalar distanceSquared(distance.LengthSquared());
81 if (distanceSquared < (Radius() * Radius())) {
83 na.Direction() = distance.Unit();
91 bool Circle::CheckCollision(const Circle &other, Ray &na) const {
92 const Vector distance(center - other.center);
93 const Scalar distanceSquared(distance.LengthSquared());
94 const Scalar radii(radius + other.radius);
96 if (distanceSquared < (radii * radii)) {
97 na.Direction() = distance.Unit();
98 na.Origin() = center + (na.Direction() * radius);
106 std::ostream &Circle::Write(std::ostream &out) const {
107 return out << "Circle(" << Radius() << ", " << Center() << ')';