#include "../Tests.h" #include "core/Frustum.h" #include "core/Utility.h" #define R60 degreeToRadian(60.0f) static void testToString() { Frustum f; initFrustum(&f, R60, 0.1f, 1000.0f); TEST_FLOAT(0.577f, f.tan, 0.01f); TEST_FLOAT(0.100f, f.nearClip, 0.01f); TEST_FLOAT(1000.0f, f.farClip, 0.01f); } static void testPointIsInside() { Frustum f; initFrustum(&f, R60, 0.1f, 1000.0f); updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1), &IV(200, 100)); TEST_TRUE(isInsideFrustum(&f, &V(0, 0, 5))); TEST_FALSE(isInsideFrustum(&f, &V(0, 0, 1004))); TEST_FALSE(isInsideFrustum(&f, &V(0, 0, -5))); TEST_FALSE(isInsideFrustum(&f, &V(0, 50, 5))); TEST_FALSE(isInsideFrustum(&f, &V(0, -50, 5))); TEST_FALSE(isInsideFrustum(&f, &V(50, 0, 5))); TEST_FALSE(isInsideFrustum(&f, &V(-50, 0, 5))); } static void testSphereIsInside() { IntVector2 size = {{200, 100}}; Frustum f; initFrustum(&f, R60, 0.1f, 1000.0f); updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1), &size); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 5), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 0, 1004), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 0, -5), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 50, 5), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(0, -50, 5), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(50, 0, 5), 3)); TEST_FALSE(isInsideFrustumRadius(&f, &V(-50, 0, 5), 3)); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 5), 3)); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 1004), 50)); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, -5), 50)); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 50, 5), 50)); TEST_TRUE(isInsideFrustumRadius(&f, &V(0, -50, 5), 50)); TEST_TRUE(isInsideFrustumRadius(&f, &V(50, 0, 5), 50)); TEST_TRUE(isInsideFrustumRadius(&f, &V(-50, 0, 5), 50)); } static void testUpdateProjection() { Frustum f; initFrustum(&f, R60, 0.1f, 1000.0f); const Matrix* m = updateProjection(&f, &IV(400, 300)); char buffer[128]; toStringMatrix(m, buffer, sizeof(buffer)); TEST_STRING("[[1.299, 0.000, 0.000, 0.000], " "[0.000, 1.732, 0.000, 0.000], " "[0.000, 0.000, -1.000, -0.200], " "[0.000, 0.000, -1.000, 0.000]]", buffer); } void testFrustum() { testToString(); testPointIsInside(); testSphereIsInside(); testUpdateProjection(); }