YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BoundingBox.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/Physics/BoundingBox.hpp
"
2
3
namespace
yap
4
{
5
BoundingBox::BoundingBox
()
6
: spatial3Info_ ()
7
{
8
}
9
10
BoundingBox::BoundingBox
(
11
const
Vector2
& position,
12
const
Vector2
& size,
13
int
z,
14
int
h)
15
: spatial3Info_ (position, size, z, h)
16
{
17
}
18
19
BoundingBox::~BoundingBox
()
20
{
21
}
22
23
BoundingBox::BoundingBox
(
const
BoundingBox
& copy)
24
: spatial3Info_ (copy.spatial3Info_)
25
{
26
}
27
28
const
Vector2
&
BoundingBox::GetPosition
()
const
29
{
30
return
spatial3Info_
.
GetPosition
();
31
}
32
33
const
Vector2
&
BoundingBox::GetSize
()
const
34
{
35
return
spatial3Info_
.
GetSize
();
36
}
37
38
const
Vector2
&
BoundingBox::GetTopLeft
()
const
39
{
40
return
spatial3Info_
.
GetTopLeft
();
41
}
42
43
const
Vector2
&
BoundingBox::GetBottomRight
()
const
44
{
45
return
spatial3Info_
.
GetBottomRight
();
46
}
47
48
const
Vector2
&
BoundingBox::GetCenter
()
const
49
{
50
return
spatial3Info_
.
GetCenter
();
51
}
52
53
const
FloatRect
&
BoundingBox::GetRectangle
()
const
54
{
55
return
spatial3Info_
.
GetRectangle
();
56
}
57
58
void
BoundingBox::Move
(
const
Vector2
& offset)
59
{
60
spatial3Info_
.
SetPosition
(
GetPosition
() + offset);
61
}
62
63
void
BoundingBox::Scale
(
const
Vector2
& factor)
64
{
65
spatial3Info_
.
SetSize
(
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
113
bool
BoundingBox::CollidesWith
(
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
YAPOG
src
YAPOG
Game
World
Map
Physics
BoundingBox.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1