From 6b407b2778c69314ba034e9ea265697a51f331d4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Feb 2026 13:30:46 +0000 Subject: Use RelativeDistance in Camera near/fear and expose member variables --- gfx/camera.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gfx/camera.cpp') diff --git a/gfx/camera.cpp b/gfx/camera.cpp index 3bb785d..db748e9 100644 --- a/gfx/camera.cpp +++ b/gfx/camera.cpp @@ -4,13 +4,13 @@ #include #include -Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance near, GlobalDistance far) : +Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, RelativeDistance near, RelativeDistance far) : Camera {pos, fov, aspect, near, far, glm::lookAt({}, ::north, ::up), glm::perspective(fov, aspect, static_cast(near), static_cast(far))} { } -Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance near, GlobalDistance far, +Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, RelativeDistance near, RelativeDistance 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} { @@ -58,9 +58,8 @@ Camera::extentsAtDist(const GlobalDistance dist) const } return {target, dist}; }; - const auto depth = -(2.F * (static_cast(dist - near)) * static_cast(far)) - / (static_cast(dist) * (static_cast(near - far))) - - 1.F; + const auto depth + = -(2.F * (static_cast(dist) - near) * far) / (static_cast(dist) * (near - far)) - 1.F; static constexpr const std::array extents {-1.F, 1.F}; static constexpr const auto cartesianExtents = extents * extents; return cartesianExtents * [&depth, this, &clampToSeaFloor](const auto & extent) { -- cgit v1.3