1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "../Tests.h"
- #include "core/Frustum.h"
- #define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
- static void testToString() {
- CoreFrustum f;
- coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
- char buffer[128];
- coreToStringFrustum(&f, buffer, sizeof(buffer));
- CORE_TEST_STRING("(tan = 0.577, nearClip = 0.100, farClip = 1000.000)",
- buffer);
- }
- static void testPointIsInside() {
- CoreIntVector2 size = {{200, 100}};
- CoreFrustum f;
- coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
- coreUpdateFrustumPlanes(&f, CV3(0, 0, 0), CV3(1, 0, 0), CV3(0, 1, 0),
- CV3(0, 0, 1), &size);
- CORE_TEST_TRUE(coreIsInsideFrustum(&f, CV3(0, 0, 5)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 0, 1004)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 0, -5)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 50, 5)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, -50, 5)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(50, 0, 5)));
- CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(-50, 0, 5)));
- }
- static void testSphereIsInside() {
- CoreIntVector2 size = {{200, 100}};
- CoreFrustum f;
- coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
- coreUpdateFrustumPlanes(&f, CV3(0, 0, 0), CV3(1, 0, 0), CV3(0, 1, 0),
- CV3(0, 0, 1), &size);
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 5), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 1004), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 0, -5), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 50, 5), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, -50, 5), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(50, 0, 5), 3));
- CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(-50, 0, 5), 3));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 5), 3));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 1004), 50));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, -5), 50));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 50, 5), 50));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, -50, 5), 50));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(50, 0, 5), 50));
- CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(-50, 0, 5), 50));
- }
- static void testUpdateProjection() {
- CoreFrustum f;
- coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
- const CoreMatrix* m =
- coreUpdateProjection(&f, &(CoreIntVector2){{400, 300}});
- char buffer[128];
- coreToStringMatrix(m, buffer, sizeof(buffer));
- CORE_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();
- }
|