1
0
Fork 0
Univerxel/src/client/control/Camera.cpp

25 lines
765 B
C++

#include "Camera.hpp"
#include <glm/gtc/matrix_transform.hpp>
#include "../Window.hpp"
Camera::Camera(const Controllable* origin, const Camera::options& opt): origin(origin), o(opt) {
updateProjection();
}
Camera::~Camera() { }
void Camera::updateProjection() {
ProjectionMatrix = glm::perspective(o.fov, Window::RATIO, o.near_dist, o.far_dist);
}
void Camera::update() {
const auto &offset = origin->position.offset;
// FIXME: up inverted after backflip
const auto axis = origin->getAxis();
// Camera matrix
ViewMatrix = glm::lookAt(
offset, // Camera is here
offset + axis.direction, // and looks here : at the same position, plus "direction"
axis.up // Head is up (set to 0,-1,0 to look upside-down)
);
}