blob: 3a9d7cd8dd975836aec9ec745497a5f1475f6d44 (
plain)
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
|
#include "Camera.hpp"
namespace MC {
Vector<3> Camera::position() {
return m_position;
}
void Camera::set_position(Vector<3> position) {
m_position = position;
}
void Camera::move(Vector<3> vector) {
m_position = m_position + vector;
}
void Camera::move_relative(Vector<3> by) {
auto rotation = Matrix<4, 4>::rotation(m_angles);
auto result = rotation.transpose() * Vector<4>{by.x(), by.y(), by.z(), 1.0f};
move(result.elements);
}
Rotation Camera::angles() {
return m_angles;
}
void Camera::set_angles(Rotation angles) {
m_angles = angles;
}
void Camera::rotate(Rotation by) {
m_angles = m_angles + by;
if (m_angles.pitch() > 89.0f) {
m_angles.pitch() = 89.0f;
} else if (m_angles.pitch() < -89.0f) {
m_angles.pitch() = -89.0f;
}
}
}
|