]> git.localhorst.tv Git - tacos.git/blobdiff - src/graphics/viewport.cpp
ray/floor intersection experiments
[tacos.git] / src / graphics / viewport.cpp
index 17c99c7a8ff9a05b6a9a6974fb664534c917286b..4ff27920ba6d2b88b16b6391535e53aa923c5f0b 100644 (file)
@@ -9,6 +9,7 @@ namespace tacos {
 Viewport::Viewport(int w, int h)
 : width(w)
 , height(h)
+, inverse_size(1.0f / float(width), 1.0f / float(height))
 , fov(0.78539816339744830961f) // π/4
 , aspect(float(w) / float(h))
 , near(0.1f)
@@ -21,9 +22,12 @@ Viewport::Viewport(int w, int h)
 void Viewport::Resize(int w, int h) noexcept {
        width = w;
        height = h;
-       aspect = float(width) / float(height);
+       float fw = float(w), fh = float(h);
+       inverse_size.x = 1.0f / fw;
+       inverse_size.y = 1.0f / fh;
+       aspect = fw / fh;
        perspective = glm::perspective(fov, aspect, near, far);
-       ortho = glm::ortho(0.0f, float(width), float(height), 0.0f, near, far);
+       ortho = glm::ortho(0.0f, fw, fh, 0.0f, near, far);
        glViewport(0, 0, width, height);
 }