1
|
#include "camera.hpp"
|
2
|
|
3
|
const int Camera::MIN_DIST = 1000;
|
4
|
const int Camera::MAX_DIST = 40000;
|
5
|
|
6
|
Camera::Camera(): QMatrix4x4()
|
7
|
{
|
8
|
}
|
9
|
|
10
|
void Camera::set(QVector3D position)
|
11
|
{
|
12
|
this->position = position;
|
13
|
this->center = QVector3D(0.0f, 0.0f, 0.0f);
|
14
|
lookAt();
|
15
|
}
|
16
|
|
17
|
void Camera::zoomIn()
|
18
|
{
|
19
|
if (getPosition().length() > MIN_DIST)
|
20
|
{
|
21
|
position -= getVectorToPosition() * 0.1f;
|
22
|
lookAt();
|
23
|
}
|
24
|
}
|
25
|
|
26
|
void Camera::zoomOut()
|
27
|
{
|
28
|
if (getPosition().length() < MAX_DIST)
|
29
|
{
|
30
|
position += getVectorToPosition() * 0.1f;
|
31
|
lookAt();
|
32
|
}
|
33
|
}
|
34
|
|
35
|
QVector3D Camera::getPosition()
|
36
|
{
|
37
|
return position;
|
38
|
}
|
39
|
|
40
|
QVector3D Camera::getVectorToPosition()
|
41
|
{
|
42
|
return position - center;
|
43
|
}
|
44
|
|
45
|
void Camera::lookAt()
|
46
|
{
|
47
|
setToIdentity();
|
48
|
QMatrix4x4::lookAt(position, center, QVector3D(0.0f, 1.0f, 0.0f));
|
49
|
}
|