diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-04 20:15:43 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-05 20:08:25 +0000 |
commit | 3d082505f7ca720bd34b1311a2ae7bca5e20a5f0 (patch) | |
tree | c02ba7cdfb703089c0df779f682aea820abe7455 /gfx | |
parent | Constrain operator* for array*functor (diff) | |
download | ilt-3d082505f7ca720bd34b1311a2ae7bca5e20a5f0.tar.bz2 ilt-3d082505f7ca720bd34b1311a2ae7bca5e20a5f0.tar.xz ilt-3d082505f7ca720bd34b1311a2ae7bca5e20a5f0.zip |
Based on code from https://ktstephano.github.io/rendering/stratusgfx/aabbs
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/gl/camera.cpp | 5 | ||||
-rw-r--r-- | gfx/gl/camera.h | 7 |
2 files changed, 12 insertions, 0 deletions
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<GlobalPosition4D, 4> 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<glm::vec4, 6> frustumPlanes; }; |