summaryrefslogtreecommitdiff
path: root/gfx/gl/camera.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-11 14:28:46 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2022-12-12 09:21:50 +0000
commitbb76f72831af73adb1b2deebd4b9235fa51fa7df (patch)
tree97e8ba1bedb42642366262c66b6170adf8d2d1b8 /gfx/gl/camera.cpp
parentHave Camera remember all its properties (diff)
downloadilt-bb76f72831af73adb1b2deebd4b9235fa51fa7df.tar.bz2
ilt-bb76f72831af73adb1b2deebd4b9235fa51fa7df.tar.xz
ilt-bb76f72831af73adb1b2deebd4b9235fa51fa7df.zip
Cache view and viewProject matrices, update only on camera movement
Diffstat (limited to 'gfx/gl/camera.cpp')
-rw-r--r--gfx/gl/camera.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 1c46200..994d8ab 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -7,12 +7,7 @@ Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar)
position {pos}, forward {::north}, up {::up}, fov {fov}, aspect {aspect}, near {zNear}, far {zFar},
projection {glm::perspective(fov, aspect, zNear, zFar)}
{
-}
-
-glm::mat4
-Camera::getViewProjection() const
-{
- return projection * glm::lookAt(position, position + forward, up);
+ updateView();
}
Ray
@@ -22,3 +17,10 @@ Camera::unProject(const glm::vec2 & mouse) const
return {position,
glm::normalize(glm::unProject(mouse ^ 1, glm::lookAt(::origin, forward, up), projection, screen))};
}
+
+void
+Camera::updateView()
+{
+ view = glm::lookAt(position, position + forward, up);
+ viewProjection = projection * view;
+}