00001 #ifndef _AABB_H_
00002 #define _AABB_H_
00003
00004 #include "Vector2.h"
00005
00006 enum eAABBSideQueryResult
00007 {
00008 eTopSide = 0,
00009 eBottomSide,
00010 eLeftSide,
00011 eRightSide,
00012 eInsideAABB
00013 };
00014
00015 class AABBf
00016 {
00017 public:
00018 AABBf()
00019 : Left(0), Right(0), Top(0), Bottom(0)
00020 {
00021 }
00022
00023 AABBf(float L, float R, float T, float B)
00024 : Left(L), Right(R), Top(T), Bottom(B)
00025 {
00026 }
00027
00028 Vector2 GetCentre()
00029 {
00030 Vector2 temp;
00031 temp.x = Left + ((Right - Left)/2);
00032 temp.y = Bottom + ((Top - Bottom)/2);
00033
00034 return temp;
00035 }
00036
00037 AABBf& operator= (const AABBf &box)
00038 {
00039 Left = box.Left; Right = box.Right; Top = box.Top; Bottom = box.Bottom;
00040 return *this;
00041 }
00042
00043 float Left, Right, Top, Bottom;
00044 };
00045
00046 class AABBi
00047 {
00048 public:
00049 AABBi()
00050 : Left(0), Right(0), Top(0), Bottom(0)
00051 {
00052 }
00053
00054 AABBi(int L, int R, int T, int B)
00055 : Left(L), Right(R), Top(T), Bottom(B)
00056 {
00057 }
00058
00059 Vector2i GetCentre()
00060 {
00061 Vector2i temp;
00062 temp.x = Left + ((Right - Left)/2);
00063 temp.y = Bottom + ((Top - Bottom)/2);
00064
00065 return temp;
00066 }
00067
00068 AABBi& operator= (const AABBi &box)
00069 {
00070 Left = box.Left; Right = box.Right; Top = box.Top; Bottom = box.Bottom;
00071 return *this;
00072 }
00073
00074 static bool AABBvsCircleCollisionTest(const AABBi &box, const Vector2i &circlePos, const int &circleRadius, Vector2i &closestPoint);
00075 static bool AABBvsAABBCollisionTest(const AABBi &boxA, const AABBi &boxB);
00076 static eAABBSideQueryResult GetSideFromClosestPoint(const AABBi &box, const Vector2i &point, Vector2i* pSidePointA = 0, Vector2i* pSidePointB = 0);
00077
00078 int Left, Right, Top, Bottom;
00079 };
00080
00081
00082 #endif