YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BoundingBoxCollection.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/Physics/BoundingBoxCollection.hpp
"
2
#include "
YAPOG/Game/World/Map/Physics/BoundingBox.hpp
"
3
#include "
YAPOG/Game/World/Map/Physics/CollidableArea.hpp
"
4
#include "
YAPOG/Game/World/Map/WorldObject.hpp
"
5
6
namespace
yap
7
{
8
BoundingBoxCollection::BoundingBoxCollection
()
9
: spatial3Info_ ()
10
, boundingBoxes_ ()
11
, collidableArea_ (nullptr)
12
{
13
}
14
15
BoundingBoxCollection::~BoundingBoxCollection
()
16
{
17
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
18
delete
boundingBox;
19
}
20
21
BoundingBoxCollection::BoundingBoxCollection
(
22
const
BoundingBoxCollection
& copy)
23
: spatial3Info_ (copy.spatial3Info_)
24
, boundingBoxes_ ()
25
, collidableArea_ (nullptr)
26
{
27
}
28
29
void
BoundingBoxCollection::AddBoundingBox
(
BoundingBox
* boundingBox)
30
{
31
boundingBoxes_
.
Add
(boundingBox);
32
33
AddBoundingBoxToCollidableArea
(boundingBox);
34
}
35
36
void
BoundingBoxCollection::RemoveBoundingBox
(
BoundingBox
* boundingBox)
37
{
38
boundingBoxes_
.
Remove
(boundingBox);
39
40
RemoveBoundingBoxFromCollidableArea
(boundingBox);
41
}
42
43
BoundingBoxCollection::ItType
BoundingBoxCollection::begin
()
44
{
45
return
boundingBoxes_
.
begin
();
46
}
47
48
BoundingBoxCollection::ConstItType
BoundingBoxCollection::begin
()
const
49
{
50
return
boundingBoxes_
.
begin
();
51
}
52
53
BoundingBoxCollection::ItType
BoundingBoxCollection::end
()
54
{
55
return
boundingBoxes_
.
end
();
56
}
57
58
BoundingBoxCollection::ConstItType
BoundingBoxCollection::end
()
const
59
{
60
return
boundingBoxes_
.
end
();
61
}
62
63
const
Vector2
&
BoundingBoxCollection::GetPosition
()
const
64
{
65
return
spatial3Info_
.
GetPosition
();
66
}
67
68
const
Vector2
&
BoundingBoxCollection::GetSize
()
const
69
{
70
return
spatial3Info_
.
GetSize
();
71
}
72
73
const
Vector2
&
BoundingBoxCollection::GetTopLeft
()
const
74
{
75
return
spatial3Info_
.
GetTopLeft
();
76
}
77
78
const
Vector2
&
BoundingBoxCollection::GetBottomRight
()
const
79
{
80
return
spatial3Info_
.
GetBottomRight
();
81
}
82
83
const
Vector2
&
BoundingBoxCollection::GetCenter
()
const
84
{
85
return
spatial3Info_
.
GetCenter
();
86
}
87
88
const
sf::FloatRect
&
BoundingBoxCollection::GetRectangle
()
const
89
{
90
return
spatial3Info_
.
GetRectangle
();
91
}
92
93
void
BoundingBoxCollection::Move
(
const
Vector2
& offset)
94
{
95
spatial3Info_
.
SetPosition
(
GetPosition
() + offset);
96
97
RemoveBoundingBoxesFromCollidableArea
();
98
99
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
100
boundingBox->Move (offset);
101
102
AddBoundingBoxesToCollidableArea
();
103
}
104
105
void
BoundingBoxCollection::Scale
(
const
Vector2
& factor)
106
{
107
spatial3Info_
.
SetSize
(
108
Vector2
(
109
GetSize
().x * factor.x,
110
GetSize
().y * factor.y));
111
112
RemoveBoundingBoxesFromCollidableArea
();
113
114
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
115
boundingBox->Scale (factor);
116
117
AddBoundingBoxesToCollidableArea
();
118
}
119
120
void
BoundingBoxCollection::SetPosition
(
const
Vector2
& position)
121
{
122
Move
(position -
GetPosition
());
123
}
124
125
void
BoundingBoxCollection::SetSize
(
const
Vector2
& size)
126
{
127
Scale
(
128
Vector2
(
129
size.x /
GetSize
().x,
130
size.y /
GetSize
().y));
131
}
132
133
const
int
&
BoundingBoxCollection::GetZ
()
const
134
{
135
return
spatial3Info_
.
GetZ
();
136
}
137
138
void
BoundingBoxCollection::SetZ
(
int
z)
139
{
140
int
offset = z -
GetZ
();
141
142
spatial3Info_
.
SetZ
(z);
143
144
RemoveBoundingBoxesFromCollidableArea
();
145
146
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
147
boundingBox->SetZ (boundingBox->GetZ () + offset);
148
149
AddBoundingBoxesToCollidableArea
();
150
}
151
152
const
int
&
BoundingBoxCollection::GetH
()
const
153
{
154
return
spatial3Info_
.
GetH
();
155
}
156
157
void
BoundingBoxCollection::SetH
(
int
h)
158
{
159
int
factor = h /
GetH
();
160
161
spatial3Info_
.
SetH
(h);
162
163
RemoveBoundingBoxesFromCollidableArea
();
164
165
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
166
boundingBox->SetH (boundingBox->GetH () * factor);
167
168
AddBoundingBoxesToCollidableArea
();
169
}
170
171
bool
BoundingBoxCollection::CollidesWith
(
const
ICollidable
& other)
const
172
{
173
return
CollidesWith
(other,
Vector2
(0.0f, 0.0f));
174
}
175
176
bool
BoundingBoxCollection::CollidesWith
(
177
const
ICollidable
& other,
178
const
Vector2
& offset)
const
179
{
180
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
181
if
(boundingBox->CollidesWith (other, offset))
182
return
true
;
183
184
return
false
;
185
}
186
187
void
BoundingBoxCollection::AddBoundingBoxToCollidableArea
(
188
BoundingBox
* boundingBox)
189
{
190
if
(
collidableArea_
==
nullptr
)
191
return
;
192
193
HandleAddBoundingBoxToCollidableArea
(boundingBox);
194
}
195
196
void
BoundingBoxCollection::RemoveBoundingBoxFromCollidableArea
(
197
BoundingBox
* boundingBox)
198
{
199
if
(
collidableArea_
==
nullptr
)
200
return
;
201
202
HandleRemoveBoundingBoxFromCollidableArea
(boundingBox);
203
}
204
205
CollidableArea
&
BoundingBoxCollection::GetCollidableArea
()
206
{
207
return
*
collidableArea_
;
208
}
209
210
void
BoundingBoxCollection::SetCollidableArea
(
211
CollidableArea
* collidableArea)
212
{
213
if
(
collidableArea_
== collidableArea)
214
return
;
215
216
RemoveBoundingBoxesFromCollidableArea
();
217
218
collidableArea_
= collidableArea;
219
220
AddBoundingBoxesToCollidableArea
();
221
}
222
223
const
collection::List<BoundingBox*>
&
224
BoundingBoxCollection::GetBoundingBoxes
()
const
225
{
226
return
boundingBoxes_
;
227
}
228
229
void
BoundingBoxCollection::AddBoundingBoxesToCollidableArea
()
230
{
231
if
(
collidableArea_
==
nullptr
)
232
return
;
233
234
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
235
AddBoundingBoxToCollidableArea
(boundingBox);
236
}
237
238
void
BoundingBoxCollection::RemoveBoundingBoxesFromCollidableArea
()
239
{
240
if
(
collidableArea_
==
nullptr
)
241
return
;
242
243
for
(
BoundingBox
* boundingBox :
boundingBoxes_
)
244
RemoveBoundingBoxFromCollidableArea
(boundingBox);
245
}
246
}
// namespace yap
YAPOG
src
YAPOG
Game
World
Map
Physics
BoundingBoxCollection.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1