summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/frustum.cpp41
-rw-r--r--gfx/frustum.h7
2 files changed, 14 insertions, 34 deletions
diff --git a/gfx/frustum.cpp b/gfx/frustum.cpp
index 7050910..294fe5d 100644
--- a/gfx/frustum.cpp
+++ b/gfx/frustum.cpp
@@ -21,18 +21,6 @@ Frustum::updateView(const glm::mat4 & newView)
bool
Frustum::contains(const BoundingBox & aabb) const
{
- return boundByPlanes(aabb, FACES);
-}
-
-bool
-Frustum::shadedBy(const BoundingBox & aabb) const
-{
- return boundByPlanes(aabb, FACES - 1);
-}
-
-bool
-Frustum::boundByPlanes(const BoundingBox & aabb, size_t nplanes) const
-{
static constexpr auto EXTENT_CORNER_IDXS = [] {
using Extent = GlobalPosition3D BoundingBox::*;
constexpr auto EXTENTS = std::array {&BoundingBox::min, &BoundingBox::max};
@@ -48,27 +36,21 @@ 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 contains(corners, nplanes, 0);
+ return contains(corners, 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);
+ return contains(std::array {RelativePosition4D {(point - position), 1.F}}, size);
}
bool
-Frustum::contains(const std::span<const RelativePosition4D> points, const size_t nplanes, RelativeDistance size) const
+Frustum::contains(const std::span<const RelativePosition4D> points, RelativeDistance size) const
{
- return std::ranges::none_of(std::span(planes).subspan(0, nplanes), [&points, size](const auto & frustumPlane) {
+ return std::ranges::none_of(planes, [&points, size](const auto & frustumPlane) {
return (std::ranges::all_of(points, [&frustumPlane, size](const auto & point) {
- const auto distanceFromPlane = glm::dot(frustumPlane, point) + frustumPlane.w;
+ const auto distanceFromPlane = glm::dot(frustumPlane, point);
return distanceFromPlane < -size;
}));
});
@@ -79,10 +61,11 @@ Frustum::updateCache()
{
viewProjection = projection * view;
inverseViewProjection = glm::inverse(viewProjection);
- std::ranges::transform(PLANES, planes.begin(), [vpt = glm::transpose(viewProjection)](const auto & idxs) {
- const auto [idx, sgn] = idxs;
- const auto plane = vpt[3] + (vpt[idx] * sgn);
- const auto mag = glm::length(plane.xyz());
- return plane / mag;
- });
+ std::ranges::transform(PLANES | std::views::take(planes.size()), planes.begin(),
+ [vpt = glm::transpose(viewProjection)](const auto & idxs) {
+ const auto [idx, sgn] = idxs;
+ const auto plane = vpt[3] + (vpt[idx] * sgn);
+ const auto mag = glm::length(plane.xyz());
+ return plane / mag;
+ });
}
diff --git a/gfx/frustum.h b/gfx/frustum.h
index 1493a36..cd4cbe1 100644
--- a/gfx/frustum.h
+++ b/gfx/frustum.h
@@ -33,14 +33,11 @@ public:
using BoundingBox = AxisAlignedBoundingBox<GlobalDistance>;
[[nodiscard]] bool contains(const BoundingBox &) const;
[[nodiscard]] bool contains(GlobalPosition3D, RelativeDistance size = 0) const;
- [[nodiscard]] bool shadedBy(const BoundingBox &) const;
- [[nodiscard]] bool shadedBy(GlobalPosition3D, RelativeDistance size = 0) const;
protected:
- static constexpr size_t FACES = 6;
+ static constexpr size_t FACES = 5;
void updateCache();
- [[nodiscard]] bool boundByPlanes(const BoundingBox &, size_t nplanes) const;
- [[nodiscard]] bool contains(std::span<const RelativePosition4D>, size_t nplanes, RelativeDistance) const;
+ [[nodiscard]] bool contains(std::span<const RelativePosition4D>, RelativeDistance) const;
GlobalPosition3D position;
glm::mat4 view, projection;