]> git.localhorst.tv Git - tacos.git/blob - src/graphics/viewport.cpp
ray/floor intersection experiments
[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 , inverse_size(1.0f / float(width), 1.0f / float(height))
13 , fov(0.78539816339744830961f) // π/4
14 , aspect(float(w) / float(h))
15 , near(0.1f)
16 , far(256.0f)
17 , perspective(glm::perspective(fov, aspect, near, far))
18 , ortho(glm::ortho(0.0f, float(width), float(height), 0.0f, near, far)) {
19
20 }
21
22 void Viewport::Resize(int w, int h) noexcept {
23         width = w;
24         height = h;
25         float fw = float(w), fh = float(h);
26         inverse_size.x = 1.0f / fw;
27         inverse_size.y = 1.0f / fh;
28         aspect = fw / fh;
29         perspective = glm::perspective(fov, aspect, near, far);
30         ortho = glm::ortho(0.0f, fw, fh, 0.0f, near, far);
31         glViewport(0, 0, width, height);
32 }
33
34 }