From 13b0089e8d6a20ad060ff843122e5da2b9e3b25f Mon Sep 17 00:00:00 2001 From: DualFroz Date: Thu, 27 Aug 2026 14:30:27 +0200 Subject: [PATCH] test: add tests for camera view-frustum culling planes --- tests/testFrustum.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/testFrustum.cpp diff --git a/tests/testFrustum.cpp b/tests/testFrustum.cpp new file mode 100644 index 0000000..63e86ab --- /dev/null +++ b/tests/testFrustum.cpp @@ -0,0 +1,47 @@ +#include "testHarness.h" +#include "vf/Frustum.h" + +using namespace vf; + +namespace { + +Frustum makeFrustum() { + Mat4 proj = perspective(1.0472f, 1.3333f, 0.1f, 100.0f); // 60 degrees + Mat4 view = lookAt({0, 0, 5}, {0, 0, 0}, {0, 1, 0}); // camera looks toward -z + return Frustum::fromMatrix(proj * view); +} + +} // namespace + +VF_TEST(frustumPointInFrontIsVisible) { + Frustum f = makeFrustum(); + CHECK(f.containsPoint({0, 0, 0})); + CHECK(f.containsPoint({0, 0, -10})); +} + +VF_TEST(frustumPointBehindCameraIsCulled) { + Frustum f = makeFrustum(); + CHECK(!f.containsPoint({0, 0, 10})); +} + +VF_TEST(frustumPointBeyondFarIsCulled) { + Frustum f = makeFrustum(); + CHECK(!f.containsPoint({0, 0, -200})); +} + +VF_TEST(frustumWideOffAxisPointIsCulled) { + Frustum f = makeFrustum(); + CHECK(!f.containsPoint({100, 0, -1})); +} + +VF_TEST(frustumAabbInViewIntersects) { + Frustum f = makeFrustum(); + Aabb box{{-1, -1, -2}, {1, 1, 0}}; + CHECK(f.intersectsAabb(box)); +} + +VF_TEST(frustumAabbBehindCameraCulled) { + Frustum f = makeFrustum(); + Aabb box{{-1, -1, 20}, {1, 1, 22}}; + CHECK(!f.intersectsAabb(box)); +}