FrustumTests.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../Tests.hpp"
  2. #include "core/math/Frustum.hpp"
  3. using V3 = Core::Vector3;
  4. static void testToString() {
  5. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  6. CORE_TEST_STRING("(tan = 0.58, nearClip = 0.10, farClip = 1000.00)", f);
  7. }
  8. static void testPointIsInside() {
  9. Core::IntVector2 size(200, 100);
  10. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  11. f.updatePlanes(V3(0.0f, 0.0f, 0.0f), V3(1.0f, 0.0f, 0.0f),
  12. V3(0.0f, 1.0f, 0.0f), V3(0.0f, 0.0f, 1.0f), size);
  13. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f)));
  14. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, 1004.0f)));
  15. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, -5.0f)));
  16. CORE_TEST_FALSE(f.isInside(V3(0.0f, 50.0f, 5.0f)));
  17. CORE_TEST_FALSE(f.isInside(V3(0.0f, -50.0f, 5.0f)));
  18. CORE_TEST_FALSE(f.isInside(V3(50.0f, 0.0f, 5.0f)));
  19. CORE_TEST_FALSE(f.isInside(V3(-50.0f, 0.0f, 5.0f)));
  20. }
  21. static void testSphereIsInside() {
  22. Core::IntVector2 size(200, 100);
  23. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  24. f.updatePlanes(V3(0.0f, 0.0f, 0.0f), V3(1.0f, 0.0f, 0.0f),
  25. V3(0.0f, 1.0f, 0.0f), V3(0.0f, 0.0f, 1.0f), size);
  26. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f), 3.0f));
  27. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, 1004.0f), 3.0f));
  28. CORE_TEST_FALSE(f.isInside(V3(0.0f, 0.0f, -5.0f), 3.0f));
  29. CORE_TEST_FALSE(f.isInside(V3(0.0f, 50.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(50.0f, 0.0f, 5.0f), 3.0f));
  32. CORE_TEST_FALSE(f.isInside(V3(-50.0f, 0.0f, 5.0f), 3.0f));
  33. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 5.0f), 3.0f));
  34. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, 1004.0f), 50.0f));
  35. CORE_TEST_TRUE(f.isInside(V3(0.0f, 0.0f, -5.0f), 50.0f));
  36. CORE_TEST_TRUE(f.isInside(V3(0.0f, 50.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(50.0f, 0.0f, 5.0f), 50.0f));
  39. CORE_TEST_TRUE(f.isInside(V3(-50.0f, 0.0f, 5.0f), 50.0f));
  40. }
  41. static void testUpdateProjection() {
  42. Core::Frustum f(60.0f, 0.1f, 1000.0f);
  43. CORE_TEST_STRING("[[1.30, 0.00, 0.00, 0.00], "
  44. "[0.00, 1.73, 0.00, 0.00], "
  45. "[0.00, 0.00, -1.00, -0.20], "
  46. "[0.00, 0.00, -1.00, 0.00]]",
  47. f.updateProjection(Core::IntVector2(400, 300)));
  48. }
  49. void Core::testFrustum() {
  50. testToString();
  51. testPointIsInside();
  52. testSphereIsInside();
  53. testUpdateProjection();
  54. }