From bb76f72831af73adb1b2deebd4b9235fa51fa7df Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 11 Dec 2022 14:28:46 +0000 Subject: Cache view and viewProject matrices, update only on camera movement --- gfx/gl/camera.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'gfx/gl/camera.cpp') 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; +} -- cgit v1.2.3