From 4e10d57f83f719e02005fe41e70fe1a4721a9439 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 5 Mar 2025 23:52:18 +0000 Subject: Split core view definition out of Camera into Frustum --- gfx/camera.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'gfx/camera.cpp') diff --git a/gfx/camera.cpp b/gfx/camera.cpp index 9e165fa..cc6a2dd 100644 --- a/gfx/camera.cpp +++ b/gfx/camera.cpp @@ -4,13 +4,16 @@ #include #include -Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNear, GlobalDistance zFar) : - position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, view {}, - projection { - glm::perspective(fov, aspect, static_cast(zNear), static_cast(zFar))}, - viewProjection {}, inverseViewProjection {} +Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance near, GlobalDistance far) : + Camera {pos, 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 {view, projection}, position {pos}, forward {::north}, up {::up}, near {near}, far {far} { - updateView(); } Ray @@ -26,14 +29,7 @@ Camera::unProject(const ScreenRelCoord & mouse) const void Camera::updateView() { - view = glm::lookAt({}, forward, up); - viewProjection = projection * view; - inverseViewProjection = glm::inverse(viewProjection); - static constexpr auto PLANES = std::array {0, 1, 2} * std::array {1.F, -1.F}; - std::ranges::transform(PLANES, frustumPlanes.begin(), [vpt = glm::transpose(viewProjection)](const auto & idxs) { - const auto [idx, sgn] = idxs; - return vpt[3] + (vpt[idx] * sgn); - }); + Frustum::updateView(glm::lookAt({}, forward, up)); } Direction3D -- cgit v1.2.3