-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathViewController.cpp
More file actions
156 lines (140 loc) · 3.64 KB
/
ViewController.cpp
File metadata and controls
156 lines (140 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//*****************************************************************************
// FILE NAME: ViewController.cpp
//
//*****************************************************************************
#include "view/camera.h"
#include "Game.h"
#include "ViewController.h"
//!***************************************************************
//! @details:
//! constructor
//!
//! @param[in]: parent
//! the Game object that owns this view controller
//!
//! @param[in]: camera
//! an optional camera that this view controller will manipulate
//!
//!***************************************************************
ViewController::ViewController(FIFE::Camera* camera)
: m_camera(camera), m_zoomIncrement(0.75),
m_maxZoom(4), m_minZoom(0.25), m_rotateIncrement(90)
{
}
//!***************************************************************
//! @details:
//! destructor
//!
//!***************************************************************
ViewController::~ViewController()
{
}
//!***************************************************************
//! @details:
//! associates this view controller with a camera
//!
//! @param[in]: camera
//! the camera that will be controlled
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::AttachCamera(FIFE::Camera* camera)
{
m_camera = camera;
}
//!***************************************************************
//! @details:
//! allows user the enable or disable the camera
//!
//! @param[in]: enable
//! true - enable camera
//! false - disables camera
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::EnableCamera(bool enable)
{
if (m_camera)
{
m_camera->setEnabled(enable);
}
}
//!***************************************************************
//! @details:
//! calculates the appropriate zoom level and increase the cameras
//! zoom
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::ZoomIn()
{
if (m_camera)
{
// calculate the zoom in level
double zoom = m_camera->getZoom() / m_zoomIncrement;
if (zoom <= m_maxZoom)
{
m_camera->setZoom(zoom);
}
}
}
//!***************************************************************
//! @details:
//! calculates the appropriate zoom and zooms the camera out
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::ZoomOut()
{
if (m_camera)
{
// calculate the zoom out level
double zoom = m_camera->getZoom() * m_zoomIncrement;
if (zoom >= m_minZoom)
{
m_camera->setZoom(zoom);
}
}
}
//!***************************************************************
//! @details:
//! rotates the camera left by a fixed rotation increment
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::RotateLeft()
{
if (m_camera)
{
// calculate rotation
double rotation = static_cast<int>((m_camera->getRotation() - m_rotateIncrement)) % 360;
m_camera->setRotation(rotation);
}
}
//!***************************************************************
//! @details:
//! rotates the camera right by a fixed rotation amount
//!
//! @return:
//! void
//!
//!***************************************************************
void ViewController::RotateRight()
{
if (m_camera)
{
// calculate rotation
double rotation = static_cast<int>((m_camera->getRotation() + m_rotateIncrement)) % 360;
m_camera->setRotation(rotation);
}
}