summaryrefslogtreecommitdiff
path: root/gfx/camera.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-14 01:52:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-14 01:52:02 +0000
commit21e1a24ebe3b4a4679702314ee77dc5259d13070 (patch)
treeb458f0b86c1b60fe1ccd48f505a4d4eb0e6fce49 /gfx/camera.cpp
parentFix ratio to include return type in common intermediary type (diff)
downloadilt-21e1a24ebe3b4a4679702314ee77dc5259d13070.tar.bz2
ilt-21e1a24ebe3b4a4679702314ee77dc5259d13070.tar.xz
ilt-21e1a24ebe3b4a4679702314ee77dc5259d13070.zip
Add support for changing the aspect ratio of a camera
Diffstat (limited to 'gfx/camera.cpp')
-rw-r--r--gfx/camera.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/gfx/camera.cpp b/gfx/camera.cpp
index f01054a..3bb785d 100644
--- a/gfx/camera.cpp
+++ b/gfx/camera.cpp
@@ -5,17 +5,24 @@
#include <ray.h>
Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance near, GlobalDistance far) :
- Camera {pos, near, far, glm::lookAt({}, ::north, ::up),
+ Camera {pos, fov, aspect, near, far, glm::lookAt({}, ::north, ::up),
glm::perspective(fov, aspect, static_cast<RelativeDistance>(near), static_cast<RelativeDistance>(far))}
{
}
-Camera::Camera(GlobalPosition3D pos, GlobalDistance near, GlobalDistance far, const glm::mat4 & view,
- const glm::mat4 & projection) :
- Frustum {pos, view, projection}, forward {::north}, up {::up}, near {near}, far {far}
+Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance near, GlobalDistance far,
+ const glm::mat4 & view, const glm::mat4 & projection) :
+ Frustum {pos, view, projection}, fov {fov}, aspect {aspect}, forward {::north}, up {::up}, near {near}, far {far}
{
}
+void
+Camera::setAspect(Angle aspect)
+{
+ projection = glm::perspective(fov, aspect, static_cast<RelativeDistance>(near), static_cast<RelativeDistance>(far));
+ Frustum::updateCache();
+}
+
Ray<GlobalPosition3D>
Camera::unProject(const ScreenRelCoord & mouse) const
{