test: add tests for camera view-frustum culling planes
This commit is contained in:
1 parent
5e81d6b1af
commit
13b0089e8d
1 file changed
+47
@@ -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));
|
||||
}
|
||||
Reference in new issue
Block a user