- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/AABB.cpp

Go to the documentation of this file.

    00001 #include "AABB.h"
    00002
    00003 bool AABBi::AABBvsCircleCollisionTest(const AABBi &box, const Vector2i &circlePos, const int &circleRadius, Vector2i &closestPoint)
    00004 {
    00005         closestPoint = circlePos;
    00006         if(circlePos.x < box.Left)
    00007                 closestPoint.x = box.Left;
    00008         else if(circlePos.x > box.Right)
    00009                 closestPoint.x = box.Right;
    00010
    00011         if(circlePos.y < box.Bottom)
    00012                 closestPoint.y = box.Bottom;
    00013         else if(closestPoint.y > box.Top)
    00014                 closestPoint.y = box.Top;
    00015
    00016         Vector2i diffVec = closestPoint - circlePos;
    00017         if(diffVec.getLengthSqrd() > circleRadius * circleRadius)
    00018                 return false;
    00019         else
    00020                 return true;
    00021 }
    00022
    00023 bool AABBi::AABBvsAABBCollisionTest(const AABBi &boxA, const AABBi &boxB)
    00024 {
    00025         if(boxA.Top < boxB.Bottom)
    00026                 return false;
    00027         if(boxA.Bottom > boxB.Top)
    00028                 return false;
    00029         if(boxA.Left > boxB.Right)
    00030                 return false;
    00031         if(boxA.Right < boxB.Left)
    00032                 return false;
    00033
    00034         return true;
    00035 }
    00036
    00037 eAABBSideQueryResult AABBi::GetSideFromClosestPoint(const AABBi &box, const Vector2i &point, Vector2i* pSidePointA, Vector2i* pSidePointB)
    00038 {
    00039         eAABBSideQueryResult qResult = eInsideAABB;
    00040
    00041         if(box.Left == point.x)
    00042         {
    00043                 if(pSidePointA)
    00044                         *pSidePointA = Vector2i(box.Left, box.Top);
    00045                 if(pSidePointB)
    00046                         *pSidePointB = Vector2i(box.Left, box.Bottom);
    00047                 qResult = eLeftSide;
    00048         }
    00049         else if(box.Right == point.x)
    00050         {
    00051                 if(pSidePointA)
    00052                         *pSidePointA = Vector2i(box.Right, box.Top);
    00053                 if(pSidePointB)
    00054                         *pSidePointB = Vector2i(box.Right, box.Bottom);
    00055                 qResult = eRightSide;
    00056         }
    00057         else if(box.Top == point.y)
    00058         {
    00059                 if(pSidePointA)
    00060                         *pSidePointA = Vector2i(box.Left, box.Top);
    00061                 if(pSidePointB)
    00062                         *pSidePointB = Vector2i(box.Right, box.Top);
    00063                 qResult = eTopSide;
    00064         }
    00065         else if(box.Bottom == point.y)
    00066         {
    00067                 if(pSidePointA)
    00068                         *pSidePointA = Vector2i(box.Left, box.Bottom);
    00069                 if(pSidePointB)
    00070                         *pSidePointB = Vector2i(box.Right, box.Bottom);
    00071                 qResult = eBottomSide;
    00072         }
    00073
    00074         return qResult;
    00075 }