YAPOG  0.0.1
Yet Another Pokemon Online Game
BoundingBox.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
6  : spatial3Info_ ()
7  {
8  }
9 
11  const Vector2& position,
12  const Vector2& size,
13  int z,
14  int h)
15  : spatial3Info_ (position, size, z, h)
16  {
17  }
18 
20  {
21  }
22 
24  : spatial3Info_ (copy.spatial3Info_)
25  {
26  }
27 
29  {
30  return spatial3Info_.GetPosition ();
31  }
32 
33  const Vector2& BoundingBox::GetSize () const
34  {
35  return spatial3Info_.GetSize ();
36  }
37 
39  {
40  return spatial3Info_.GetTopLeft ();
41  }
42 
44  {
45  return spatial3Info_.GetBottomRight ();
46  }
47 
49  {
50  return spatial3Info_.GetCenter ();
51  }
52 
54  {
55  return spatial3Info_.GetRectangle ();
56  }
57 
58  void BoundingBox::Move (const Vector2& offset)
59  {
61  }
62 
63  void BoundingBox::Scale (const Vector2& factor)
64  {
66  Vector2 (
67  GetSize ().x * factor.x,
68  GetSize ().y * factor.y));
69  }
70 
71  void BoundingBox::SetPosition (const Vector2& position)
72  {
73  Move (position - GetPosition ());
74  }
75 
76  void BoundingBox::SetSize (const Vector2& size)
77  {
78  Scale (
79  Vector2 (
80  size.x / GetSize ().x,
81  size.y / GetSize ().y));
82  }
83 
84  const int& BoundingBox::GetZ () const
85  {
86  return spatial3Info_.GetZ ();
87  }
88 
89  void BoundingBox::SetZ (int z)
90  {
91  spatial3Info_.SetZ (z);
92  }
93 
94  const int& BoundingBox::GetH () const
95  {
96  return spatial3Info_.GetH ();
97  }
98 
99  void BoundingBox::SetH (int h)
100  {
101  spatial3Info_.SetH (h);
102  }
103 
104  bool BoundingBox::CollidesWith (const ICollidable& other) const
105  {
106  if (GetZ () >= other.GetZ () + other.GetH () ||
107  GetZ () + GetH () <= other.GetZ ())
108  return false;
109 
110  return spatial3Info_.GetRectangle ().intersects (other.GetRectangle ());
111  }
112 
114  const ICollidable& other,
115  const Vector2& offset) const
116  {
117  if (GetZ () >= other.GetZ () + other.GetH () ||
118  GetZ () + GetH () <= other.GetZ ())
119  return false;
120 
121  FloatRect rect (
122  spatial3Info_.GetRectangle ().left + offset.x,
123  spatial3Info_.GetRectangle ().top + offset.y,
124  spatial3Info_.GetRectangle ().width,
125  spatial3Info_.GetRectangle ().height);
126 
127  return rect.intersects (other.GetRectangle ());
128  }
129 } // namespace yap