summaryrefslogtreecommitdiff
path: root/gfx/gl/camera.h
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.h
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.h')
-rw-r--r--gfx/gl/camera.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 5b9d339..94eb8fc 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -8,18 +8,24 @@ class Camera {
public:
Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar);
- [[nodiscard]] glm::mat4 getViewProjection() const;
+ [[nodiscard]] glm::mat4
+ getViewProjection() const
+ {
+ return viewProjection;
+ }
[[nodiscard]] Ray unProject(const glm::vec2 &) const;
void
setPosition(const glm::vec3 & p)
{
position = p;
+ updateView();
}
void
setForward(const glm::vec3 & f)
{
forward = f;
+ updateView();
}
void
setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u = ::up)
@@ -27,6 +33,7 @@ public:
position = p;
forward = f;
up = u;
+ updateView();
}
void
lookAt(const glm::vec3 & target)
@@ -45,10 +52,14 @@ public:
}
private:
+ void updateView();
+
glm::vec3 position;
glm::vec3 forward;
glm::vec3 up;
float fov, aspect, near, far;
glm::mat4 projection;
+ glm::mat4 view;
+ glm::mat4 viewProjection;
};