InvertedAABBox2D.h
上传用户:edingdan
上传日期:2020-03-19
资源大小:8486k
文件大小:2k
开发平台:

Visual C++

  1. #ifndef INVAABBOX2D_H
  2. #define INVAABBOX2D_H
  3. //-----------------------------------------------------------------------------
  4. //
  5. //  Name:   InvertedAABBox2D.h
  6. //
  7. //  Author: Mat Buckland (www.ai-junkie.com)
  8. //
  9. //  Desc:   v simple inverted (y increases down screen) axis aligned bounding
  10. //          box class
  11. //-----------------------------------------------------------------------------
  12. #include "2d/Vector2D.h"
  13. #include "misc/cgdi.h"
  14. class InvertedAABBox2D
  15. {
  16. private:
  17.   
  18.   Vector2D  m_vTopLeft;
  19.   Vector2D  m_vBottomRight;
  20.   Vector2D  m_vCenter;
  21.   
  22. public:
  23.   InvertedAABBox2D(Vector2D tl,
  24.                    Vector2D br):m_vTopLeft(tl),
  25.                                 m_vBottomRight(br),
  26.                                 m_vCenter((tl+br)/2.0)
  27.   {}
  28.   //returns true if the bbox described by other intersects with this one
  29.   bool isOverlappedWith(const InvertedAABBox2D& other)const
  30.   {
  31.     return !((other.Top() > this->Bottom()) ||
  32.            (other.Bottom() < this->Top()) ||
  33.            (other.Left() > this->Right()) ||
  34.            (other.Right() < this->Left()));
  35.   }
  36.   
  37.   Vector2D TopLeft()const{return m_vTopLeft;}
  38.   Vector2D BottomRight()const{return m_vBottomRight;}
  39.   double    Top()const{return m_vTopLeft.y;}
  40.   double    Left()const{return m_vTopLeft.x;}
  41.   double    Bottom()const{return m_vBottomRight.y;}
  42.   double    Right()const{return m_vBottomRight.x;}
  43.   Vector2D Center()const{return m_vCenter;}
  44.   void     Render(bool RenderCenter = false)const
  45.   {
  46.     gdi->Line((int)Left(), (int)Top(), (int)Right(), (int)Top() );
  47.     gdi->Line((int)Left(), (int)Bottom(), (int)Right(), (int)Bottom() );
  48.     gdi->Line((int)Left(), (int)Top(), (int)Left(), (int)Bottom() );
  49.     gdi->Line((int)Right(), (int)Top(), (int)Right(), (int)Bottom() );
  50.     if (RenderCenter)
  51.     {
  52.       gdi->Circle(m_vCenter, 5);
  53.     }
  54.   }
  55. };
  56.   
  57. #endif