From 21e1a24ebe3b4a4679702314ee77dc5259d13070 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Mar 2025 01:52:02 +0000 Subject: Add support for changing the aspect ratio of a camera --- gfx/camera.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'gfx/camera.cpp') 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 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(near), static_cast(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(near), static_cast(far)); + Frustum::updateCache(); +} + Ray Camera::unProject(const ScreenRelCoord & mouse) const { -- cgit v1.2.3