summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan.goodliffe@octal.co.uk>2026-02-20 13:38:02 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2026-02-20 13:38:02 +0000
commitbc7dbe8b42d86c7d8a45dd02b21f02756fd6f751 (patch)
tree4c676fa4ad9017e374478d347ca5e6ca1f2815d3 /gfx
parentFix up the preFrame process to use both frustums (diff)
downloadilt-bc7dbe8b42d86c7d8a45dd02b21f02756fd6f751.tar.bz2
ilt-bc7dbe8b42d86c7d8a45dd02b21f02756fd6f751.tar.xz
ilt-bc7dbe8b42d86c7d8a45dd02b21f02756fd6f751.zip
Correctly scale frustum plane vectors
Fixes comparison with real world (sphere) size parameter.
Diffstat (limited to 'gfx')
-rw-r--r--gfx/frustum.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/gfx/frustum.cpp b/gfx/frustum.cpp
index 5c85ac0..7050910 100644
--- a/gfx/frustum.cpp
+++ b/gfx/frustum.cpp
@@ -67,8 +67,9 @@ bool
Frustum::contains(const std::span<const RelativePosition4D> points, const size_t nplanes, RelativeDistance size) const
{
return std::ranges::none_of(std::span(planes).subspan(0, nplanes), [&points, size](const auto & frustumPlane) {
- return (std::ranges::all_of(points, [&frustumPlane, size](const auto & corner) {
- return glm::dot(frustumPlane, corner) < -size;
+ return (std::ranges::all_of(points, [&frustumPlane, size](const auto & point) {
+ const auto distanceFromPlane = glm::dot(frustumPlane, point) + frustumPlane.w;
+ return distanceFromPlane < -size;
}));
});
}
@@ -80,6 +81,8 @@ Frustum::updateCache()
inverseViewProjection = glm::inverse(viewProjection);
std::ranges::transform(PLANES, planes.begin(), [vpt = glm::transpose(viewProjection)](const auto & idxs) {
const auto [idx, sgn] = idxs;
- return vpt[3] + (vpt[idx] * sgn);
+ const auto plane = vpt[3] + (vpt[idx] * sgn);
+ const auto mag = glm::length(plane.xyz());
+ return plane / mag;
});
}