summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-11 14:52:09 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2022-12-12 09:21:54 +0000
commitc2abacf2e7d188aa0999a38dce259b0d8e76b982 (patch)
tree91bed055ce71f3a848753eb8212807d710f71678
parentCache view and viewProject matrices, update only on camera movement (diff)
downloadilt-c2abacf2e7d188aa0999a38dce259b0d8e76b982.tar.bz2
ilt-c2abacf2e7d188aa0999a38dce259b0d8e76b982.tar.xz
ilt-c2abacf2e7d188aa0999a38dce259b0d8e76b982.zip
Cache unView matrix for unprojecting mouse clicks, update only on camera movement
-rw-r--r--gfx/gl/camera.cpp4
-rw-r--r--gfx/gl/camera.h2
2 files changed, 3 insertions, 3 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 994d8ab..72b5240 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -14,13 +14,13 @@ Ray
Camera::unProject(const glm::vec2 & mouse) const
{
static constexpr const glm::vec4 screen {0, 0, 1, 1};
- return {position,
- glm::normalize(glm::unProject(mouse ^ 1, glm::lookAt(::origin, forward, up), projection, screen))};
+ return {position, glm::normalize(glm::unProject(mouse ^ 1, unView, projection, screen))};
}
void
Camera::updateView()
{
view = glm::lookAt(position, position + forward, up);
+ unView = glm::lookAt(::origin, forward, up);
viewProjection = projection * view;
}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 94eb8fc..bcc7469 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -60,6 +60,6 @@ private:
float fov, aspect, near, far;
glm::mat4 projection;
- glm::mat4 view;
+ glm::mat4 view, unView;
glm::mat4 viewProjection;
};