summaryrefslogtreecommitdiff
path: root/gfx/frustum.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-02-15 00:50:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-02-15 00:50:02 +0000
commit8496bd9720888701267f8f39a2f3a74a65f1006f (patch)
tree6f902b6302f9573cd7f45f9b1d6255d4ae024432 /gfx/frustum.cpp
parentRefactor test-instancing so the data is generated in a common fixture (diff)
downloadilt-8496bd9720888701267f8f39a2f3a74a65f1006f.tar.bz2
ilt-8496bd9720888701267f8f39a2f3a74a65f1006f.tar.xz
ilt-8496bd9720888701267f8f39a2f3a74a65f1006f.zip
Support for testing if a point/sphere is within a Frustum
Use case is the sphere approximating a scenery item such as a tree.
Diffstat (limited to 'gfx/frustum.cpp')
-rw-r--r--gfx/frustum.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/gfx/frustum.cpp b/gfx/frustum.cpp
index faa676d..5c85ac0 100644
--- a/gfx/frustum.cpp
+++ b/gfx/frustum.cpp
@@ -48,9 +48,27 @@ Frustum::boundByPlanes(const BoundingBox & aabb, size_t nplanes) const
= EXTENT_CORNER_IDXS * [relativeAabb = aabb - position](auto idxs) -> glm::vec4 {
return {(relativeAabb.*(idxs.x)).x, (relativeAabb.*(idxs.y)).y, (relativeAabb.*(idxs.z)).z, 1.F};
};
- return std::ranges::none_of(std::span(planes).subspan(0, nplanes), [&corners](const auto & frustumPlane) {
- return (std::ranges::all_of(corners, [&frustumPlane](const auto & corner) {
- return glm::dot(frustumPlane, corner) < 0.F;
+ return contains(corners, nplanes, 0);
+}
+
+bool
+Frustum::contains(GlobalPosition3D point, RelativeDistance size) const
+{
+ return contains(std::array {RelativePosition4D {(point - position), 1.F}}, FACES, size);
+}
+
+bool
+Frustum::shadedBy(GlobalPosition3D point, RelativeDistance size) const
+{
+ return contains(std::array {RelativePosition4D {(point - position), 1.F}}, FACES - 1, size);
+}
+
+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;
}));
});
}