FrustumTests.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "tests/FrustumTests.h"
  2. #include "math/Frustum.h"
  3. #include "test/Test.h"
  4. using V3 = Core::Vector3;
  5. static void testToString() {
  6. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  7. CORE_TEST_STRING("(tan = 0.58, nearClip = 0.10, farClip = 1000.00)", f);
  8. }
  9. static void testPointIsInside() {
  10. Core::IntVector2 size(200, 100);
  11. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  12. f.updatePlanes(V3(0.0f, 0.0f, 0.0f), V3(1.0f, 0.0f, 0.0f),
  13. V3(0.0f, 1.0f, 0.0f), V3(0.0f, 0.0f, 1.0f), size);
  14. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f)));
  15. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, 1004.0f)));
  16. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, -5.0f)));
  17. CORE_TEST_FALSE(f.isInside(V3(0.0f, 50.0f, 5.0f)));
  18. CORE_TEST_FALSE(f.isInside(V3(0.0f, -50.0f, 5.0f)));
  19. CORE_TEST_FALSE(f.isInside(V3(50.0f, 0.0f, 5.0f)));
  20. CORE_TEST_FALSE(f.isInside(V3(-50.0f, 0.0f, 5.0f)));
  21. }
  22. static void testSphereIsInside() {
  23. Core::IntVector2 size(200, 100);
  24. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  25. f.updatePlanes(V3(0.0f, 0.0f, 0.0f), V3(1.0f, 0.0f, 0.0f),
  26. V3(0.0f, 1.0f, 0.0f), V3(0.0f, 0.0f, 1.0f), size);
  27. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f), 3.0f));
  28. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, 1004.0f), 3.0f));
  29. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, -5.0f), 3.0f));
  30. CORE_TEST_FALSE(f.isInside(V3(0.0f, 50.0f, 5.0f), 3.0f));
  31. CORE_TEST_FALSE(f.isInside(V3(0.0f, -50.0f, 5.0f), 3.0f));
  32. CORE_TEST_FALSE(f.isInside(V3(50.0f, 0.0f, 5.0f), 3.0f));
  33. CORE_TEST_FALSE(f.isInside(V3(-50.0f, 0.0f, 5.0f), 3.0f));
  34. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f), 3.0f));
  35. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 1004.0f), 50.0f));
  36. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, -5.0f), 50.0f));
  37. CORE_TEST_TRUE(f.isInside(V3(0.0f, 50.0f, 5.0f), 50.0f));
  38. CORE_TEST_TRUE(f.isInside(V3(0.0f, -50.0f, 5.0f), 50.0f));
  39. CORE_TEST_TRUE(f.isInside(V3(50.0f, 0.0f, 5.0f), 50.0f));
  40. CORE_TEST_TRUE(f.isInside(V3(-50.0f, 0.0f, 5.0f), 50.0f));
  41. }
  42. void Core::FrustumTests::test() {
  43. testToString();
  44. testPointIsInside();
  45. testSphereIsInside();
  46. }