summary refs log tree commit diff
path: root/src/GFX/Camera.cpp
blob: dbc3444434f8b47a7028fc21dc1d58fc3749a569 (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::GFX {

Vector<3> Camera::position() const {
    return m_position;
}

void Camera::set_position(Vector<3> position) {
    m_position = position;
}

void Camera::move(Vector<3> by) {
    m_position = m_position + by;
}

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(Vector<3>{result.elements});
}

Rotation Camera::angles() const {
    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;
    }
}

}