]> git.localhorst.tv Git - tacos.git/blob - src/graphics/viewport.cpp
controllable camera
[tacos.git] / src / graphics / viewport.cpp
1 #include "viewport.hpp"
2
3 #include <GL/glew.h>
4 #include <glm/gtc/matrix_transform.hpp>
5
6
7 namespace tacos {
8
9 Viewport::Viewport(int w, int h)
10 : width(w)
11 , height(h)
12 , fov(0.78539816339744830961f) // π/4
13 , aspect(float(w) / float(h))
14 , near(0.1f)
15 , far(256.0f)
16 , perspective(glm::perspective(fov, aspect, near, far))
17 , ortho(glm::ortho(0.0f, float(width), float(height), 0.0f, near, far)) {
18
19 }
20
21 void Viewport::Resize(int w, int h) noexcept {
22         width = w;
23         height = h;
24         aspect = float(width) / float(height);
25         perspective = glm::perspective(fov, aspect, near, far);
26         ortho = glm::ortho(0.0f, float(width), float(height), 0.0f, near, far);
27         glViewport(0, 0, width, height);
28 }
29
30 }