TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Box2D.h
Go to the documentation of this file.
1 
13 #ifndef G3D_Box2D_h
14 #define G3D_Box2D_h
15 
16 #include "G3D/platform.h"
17 #include "G3D/Vector2.h"
18 
19 namespace G3D {
20 
21 class CoordinateFrame;
22 typedef class CoordinateFrame CFrame;
23 class Rect2D;
24 typedef class Rect2D AABox2D;
25 
30 class Box2D {
31 private:
34 
38 
41 
44 
46  float origin[2];
47 
49  float m_area;
50 
52 
54  bool overlaps1Way(const Box2D& other) const;
55 
56 
59  void computeAxes();
60 
61 public:
62 
69  Box2D(const Vector2& center = Vector2(0, 0), float w = 0, float h = 0, float angle = 0);
70 
71  Box2D(const AABox2D& b);
72 
73  Box2D(const Vector2& min, const Vector2& max);
74 
77  Box2D(const CFrame& frame, Box2D& b);
78 
79  inline bool contains(const Vector2& v) const {
80  // Take to object space:
81  const Vector2& p = v - m_center;
82  float x = p.dot(m_axisin[0]);
83  float y = p.dot(m_axisin[1]);
84 
85  // Must be within extent/2 on both axes in object space
86  return (abs(x) <= 0.5f) && (abs(y) <= 0.5f);
87  }
88 
90  inline const Vector2& extent() const {
91  return m_extent;
92  }
93 
95  inline const Vector2& axis(int a) const {
96  debugAssert(a == 0 || a == 1);
97  return m_axis[a];
98  }
99 
101  inline float area() const {
102  return m_area;
103  }
104 
105  inline const Vector2& corner(int i) const {
106  debugAssert(i >=0 && i <= 3);
107  return m_corner[i];
108  }
109 
110  inline const Vector2& center() const {
111  return m_center;
112  }
113 
115  inline bool overlaps(const Box2D& other) const {
116  return overlaps1Way(other) && other.overlaps1Way(*this);
117  }
118 };
119 
120 } // G3D
121 #endif
class Rect2D AABox2D
Definition: Box2D.h:24
Vector2 m_corner[4]
Definition: Box2D.h:33
Definition: Vector2.h:40
Vector2 m_axisin[2]
Definition: Box2D.h:37
Vector2 m_extent
Definition: Box2D.h:51
A rigid body RT (rotation-translation) transformation.
Definition: CoordinateFrame.h:59
double abs(double fValue)
Definition: g3dmath.h:617
bool overlaps1Way(const Box2D &other) const
Definition: Box2D.cpp:17
float area() const
Surface area.
Definition: Box2D.h:101
const Vector2 & axis(int a) const
Unit length vector along axis a.
Definition: Box2D.h:95
class CoordinateFrame CFrame
Definition: Box2D.h:22
Definition: AABox.h:25
const Vector2 & extent() const
Distance from corner(0) to the next corner along the box's local axis a.
Definition: Box2D.h:90
Definition: Rect2D.h:40
T max(const T &x, const T &y)
Definition: g3dmath.h:320
bool overlaps(const Box2D &other) const
Definition: Box2D.h:115
Vector2 m_center
Definition: Box2D.h:43
T min(const T &x, const T &y)
Definition: g3dmath.h:305
const Vector2 & corner(int i) const
Definition: Box2D.h:105
void computeAxes()
Definition: Box2D.cpp:52
#define debugAssert(exp)
Definition: debugAssert.h:160
Definition: Box2D.h:30
bool contains(const Vector2 &v) const
Definition: Box2D.h:79
float origin[2]
Definition: Box2D.h:46
G3D::int16 y
Definition: Vector2int16.h:38
Box2D(const Vector2 &center=Vector2(0, 0), float w=0, float h=0, float angle=0)
Definition: Box2D.cpp:75
Vector2 m_axis[2]
Definition: Box2D.h:40
G3D::int16 x
Definition: Vector2int16.h:37
const Vector2 & center() const
Definition: Box2D.h:110
float m_area
Definition: Box2D.h:49
float dot(const Vector2 &s) const
Definition: Vector2.h:446