From 3d082505f7ca720bd34b1311a2ae7bca5e20a5f0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 4 Mar 2025 20:15:43 +0000 Subject: Have Camera keep an array of frustum plane definitions Based on code from https://ktstephano.github.io/rendering/stratusgfx/aabbs --- gfx/gl/camera.cpp | 5 +++++ gfx/gl/camera.h | 7 +++++++ 2 files changed, 12 insertions(+) (limited to 'gfx') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index f03e85b..9e165fa 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -29,6 +29,11 @@ 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); + }); } Direction3D diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 5c37744..d4fe6de 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -70,6 +70,12 @@ public: return position; } + [[nodiscard]] auto & + getFrustumPlanes() const + { + return frustumPlanes; + } + [[nodiscard]] std::array extentsAtDist(GlobalDistance) const; [[nodiscard]] static Direction3D upFromForward(const Direction3D & forward); @@ -84,4 +90,5 @@ private: GlobalDistance near, far; glm::mat4 view, projection; glm::mat4 viewProjection, inverseViewProjection; + std::array frustumPlanes; }; -- cgit v1.2.3