YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ProgressiveCameraController.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/ProgressiveCameraController.hpp
"
2
#include "
YAPOG/Graphics/ICamera.hpp
"
3
#include "
YAPOG/Graphics/ISpatial.hpp
"
4
#include "
YAPOG/System/MathHelper.hpp
"
5
6
namespace
yap
7
{
8
const
float
ProgressiveCameraController::CAMERA_MOVE_TRIGGER_LIMIT
= 50.0f;
9
const
float
ProgressiveCameraController::MOVE_AMORTIZATION_FACTOR
= 180.0f;
10
const
float
ProgressiveCameraController::DEFAULT_VELOCITY_FACTOR
= 100.0f;
11
12
ProgressiveCameraController::ProgressiveCameraController
(
ICamera
& camera)
13
:
CameraController
(camera)
14
, velocityFactor_ (
15
Vector2
(
16
DEFAULT_VELOCITY_FACTOR,
17
DEFAULT_VELOCITY_FACTOR))
18
{
19
}
20
21
ProgressiveCameraController::~ProgressiveCameraController
()
22
{
23
}
24
25
void
ProgressiveCameraController::SetVelocityFactor
(
26
const
Vector2
& velocityFactor)
27
{
28
velocityFactor_
= velocityFactor;
29
}
30
31
void
ProgressiveCameraController::HandleFocusTarget
()
32
{
33
CenterOnTarget
();
34
}
35
36
void
ProgressiveCameraController::HandleUpdate
(
const
Time
& dt)
37
{
38
if
(
target_
==
nullptr
)
39
return
;
40
41
Vector2
offset;
42
43
const
Vector2
& targetPoint =
target_
->
GetCenter
();
44
Vector2
cameraSizeFactor =
Vector2
(
45
camera_
.
GetSize
().x /
camera_
.
GetSize
().y,
46
camera_
.
GetSize
().y /
camera_
.
GetSize
().x);
47
48
if
(
MathHelper::Abs
(targetPoint.x -
camera_
.
GetCenter
().x) >
49
CAMERA_MOVE_TRIGGER_LIMIT
* cameraSizeFactor.x)
50
offset.x =
51
velocityFactor_
.x *
52
(targetPoint.x -
camera_
.
GetCenter
().x) /
53
MOVE_AMORTIZATION_FACTOR
*
54
cameraSizeFactor.y *
55
dt.
GetValue
();
56
57
if
(
MathHelper::Abs
(targetPoint.y -
camera_
.
GetCenter
().y) >
58
CAMERA_MOVE_TRIGGER_LIMIT
* cameraSizeFactor.y)
59
offset.y =
60
velocityFactor_
.y *
61
(targetPoint.y -
camera_
.
GetCenter
().y) /
62
MOVE_AMORTIZATION_FACTOR
*
63
cameraSizeFactor.x *
64
dt.
GetValue
();
65
66
CheckBounds
(offset);
67
68
camera_
.
Move
(offset);
69
}
70
}
// namespace yap
YAPOG
src
YAPOG
Graphics
ProgressiveCameraController.cpp
Generated on Mon Sep 17 2012 22:24:26 for YAPOG by
1.8.1.1