00001
00007 #ifndef _RECT_H_
00008 #define _RECT_H_
00009
00010 #include "IsoBomb.h"
00011
00016 class Rect {
00017 public:
00018 float x, y, w, h;
00019
00020 Rect() : x(0), y(0), w(0), h(0) {}
00021 Rect(float x2, float y2, float w2, float h2) : x(x2), y(y2), w(w2), h(h2) {}
00022
00023 void init(float x2, float y2, float w2, float h2) {
00024 x = x2; y = y2; w = w2; h = h2;
00025 }
00026
00027 float getRight() const {
00028 return x+w;
00029 }
00030
00031 float getBottom() const {
00032 return y+h;
00033 }
00034
00035 Point getUpperLeft() const {
00036 return Point(x, y);
00037 }
00038
00039 Point getLowerRight() const {
00040 return Point( x+w, y+h );
00041 }
00042
00043 Point getUpperRight() const {
00044 return Point( x+w, y );
00045 }
00046
00047 Point getLowerLeft() const {
00048 return Point( x, y+h );
00049 }
00050
00051 Point getCenter() const {
00052 return Point(x+w/2.0f, y+h/2.0f);
00053 }
00054
00055 void setCenter( const Point& cent ) {
00056 x = cent.x - (w / 2);
00057 y = cent.y - (h / 2);
00058 }
00059
00063 bool isCollision(const Point& other) const {
00064 return ((other.x <= x+w) && (other.y <= y+h) &&
00065 (other.x >= x) && (other.y >= y));
00066 }
00067
00071 bool isCollision(const Rect& other) const {
00072 return ((other.x <= x+w) && (other.y <= y+h) &&
00073 (other.x+other.w >= x) && (other.y+other.h >= y));
00074 }
00075
00079 float distTo(const Rect& other) const {
00080 return (float)(fabs(sqrt(sq((other.x+other.w/2.0f)-(x+w/2.0f)) +
00081 sq((other.y+other.h/2.0f)-(y+h/2.0f)))));
00082 }
00083
00084 protected:
00085 private:
00086 };
00087
00088 #endif