summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-02 11:34:50 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-02 11:34:50 +0000
commit4a168a95d16541b9a8338b074509bab406997a56 (patch)
treeee05615ea594f41a3dc53cf73d6e103b1f9a7024
parentWork around clang thinking this is unused in lambdas (diff)
downloadilt-4a168a95d16541b9a8338b074509bab406997a56.tar.bz2
ilt-4a168a95d16541b9a8338b074509bab406997a56.tar.xz
ilt-4a168a95d16541b9a8338b074509bab406997a56.zip
Cache the camera's view matrix
-rw-r--r--gfx/gl/camera.cpp13
-rw-r--r--gfx/gl/camera.h2
2 files changed, 9 insertions, 6 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 82b11a6..f03e85b 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -5,7 +5,7 @@
#include <ray.h>
Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNear, GlobalDistance zFar) :
- position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar},
+ position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, view {},
projection {
glm::perspective(fov, aspect, static_cast<RelativeDistance>(zNear), static_cast<RelativeDistance>(zFar))},
viewProjection {}, inverseViewProjection {}
@@ -16,15 +16,18 @@ Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNe
Ray<GlobalPosition3D>
Camera::unProject(const ScreenRelCoord & mouse) const
{
- static constexpr const glm::vec4 screen {0, 0, 1, 1};
- const auto mouseProjection = glm::lookAt({}, forward, up);
- return {position, glm::normalize(glm::unProject(mouse || 1.F, mouseProjection, projection, screen))};
+ static constexpr const glm::vec4 SCREEN {0, 0, 1, 1};
+ return {
+ .start = position,
+ .direction = glm::normalize(glm::unProject(mouse || 1.F, view, projection, SCREEN)),
+ };
}
void
Camera::updateView()
{
- viewProjection = projection * glm::lookAt({}, forward, up);
+ view = glm::lookAt({}, forward, up);
+ viewProjection = projection * view;
inverseViewProjection = glm::inverse(viewProjection);
}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 8d53261..5c37744 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -82,6 +82,6 @@ private:
Direction3D up;
GlobalDistance near, far;
- glm::mat4 projection;
+ glm::mat4 view, projection;
glm::mat4 viewProjection, inverseViewProjection;
};