YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
CameraController.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/CameraController.hpp
"
2
#include "
YAPOG/Graphics/ICamera.hpp
"
3
4
namespace
yap
5
{
6
CameraController::CameraController
(
ICamera
& camera)
7
: camera_ (camera)
8
, target_ (nullptr)
9
, bounds_ ()
10
{
11
}
12
13
CameraController::~CameraController
()
14
{
15
}
16
17
void
CameraController::SetTarget
(
ISpatial
& target)
18
{
19
target_
= ⌖
20
}
21
22
void
CameraController::FocusTarget
()
23
{
24
HandleFocusTarget
();
25
}
26
27
void
CameraController::SetBounds
(
const
FloatRect
& bounds)
28
{
29
bounds_
= bounds;
30
}
31
32
void
CameraController::Update
(
const
Time
& dt)
33
{
34
HandleUpdate
(dt);
35
}
36
37
void
CameraController::CheckBounds
(
Vector2
& offset)
38
{
39
if
(
camera_
.
GetTopLeft
().x + offset.x <
bounds_
.left)
40
offset.x =
bounds_
.left -
camera_
.
GetTopLeft
().x;
41
42
if
(
camera_
.
GetBottomRight
().x + offset.x >
43
(
bounds_
.left +
bounds_
.width))
44
offset.x =
bounds_
.left +
bounds_
.width -
camera_
.
GetBottomRight
().x;
45
46
if
(
camera_
.
GetTopLeft
().y + offset.y <
bounds_
.top)
47
offset.y =
bounds_
.top -
camera_
.
GetTopLeft
().y;
48
49
if
(
camera_
.
GetBottomRight
().y + offset.y >
50
(
bounds_
.top +
bounds_
.height))
51
offset.y =
bounds_
.top +
bounds_
.height -
camera_
.
GetBottomRight
().y;
52
}
53
54
void
CameraController::CenterOnTarget
()
55
{
56
if
(
target_
==
nullptr
)
57
return
;
58
59
const
Vector2
& targetPoint =
target_
->
GetCenter
();
60
Vector2
offset = targetPoint -
camera_
.
GetCenter
();
61
62
CheckBounds
(offset);
63
64
camera_
.
Move
(offset);
65
}
66
}
// namespace yap
YAPOG
src
YAPOG
Graphics
CameraController.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1