FrustumTests.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "tests/FrustumTests.h"
  2. #include "tests/Test.h"
  3. #include "math/Frustum.h"
  4. #include "utils/StringBuffer.h"
  5. typedef StringBuffer<250> String;
  6. static void testToString(Test& test) {
  7. Size size(200, 100);
  8. Frustum f(60.0f, 0.1f, 1000.0f, size);
  9. test.checkEqual(String("("
  10. "fieldOfView = 60.00, "
  11. "nearClip = 0.10, "
  12. "farClip = 1000.00, "
  13. "width = 200, "
  14. "height = 100)"), String(f), "to string");
  15. }
  16. static void testPointIsInside(Test& test) {
  17. Size size(200, 100);
  18. Frustum f(60.0f, 0.1f, 1000.0f, size);
  19. f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f),
  20. Vector3(1.0f, 0.0f, 0.0f),
  21. Vector3(0.0f, 1.0f, 0.0f),
  22. Vector3(0.0f, 0.0f, 1.0f));
  23. test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f)), "point is inside 1");
  24. test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f)), "point is inside 2");
  25. test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f)), "point is inside 3");
  26. test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f)), "point is inside 4");
  27. test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f)), "point is inside 5");
  28. test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f)), "point is inside 6");
  29. test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f)), "point is inside 7");
  30. }
  31. static void testSphereIsInside(Test& test) {
  32. Size size(200, 100);
  33. Frustum f(60.0f, 0.1f, 1000.0f, size);
  34. f.updatePlanes(Vector3(0.0f, 0.0f, 0.0f),
  35. Vector3(1.0f, 0.0f, 0.0f),
  36. Vector3(0.0f, 1.0f, 0.0f),
  37. Vector3(0.0f, 0.0f, 1.0f));
  38. test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 1");
  39. test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 3.0f), "sphere is inside 2");
  40. test.checkEqual(false, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 3.0f), "sphere is inside 3");
  41. test.checkEqual(false, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 3.0f), "sphere is inside 4");
  42. test.checkEqual(false, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 3.0f), "sphere is inside 5");
  43. test.checkEqual(false, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 6");
  44. test.checkEqual(false, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 7");
  45. test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 5.0f), 3.0f), "sphere is inside 8");
  46. test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, 1004.0f), 50.0f), "sphere is inside 9");
  47. test.checkEqual(true, f.isInside(Vector3(0.0f, 0.0f, -5.0f), 50.0f), "sphere is inside 10");
  48. test.checkEqual(true, f.isInside(Vector3(0.0f, 50.0f, 5.0f), 50.0f), "sphere is inside 11");
  49. test.checkEqual(true, f.isInside(Vector3(0.0f, -50.0f, 5.0f), 50.0f), "sphere is inside 12");
  50. test.checkEqual(true, f.isInside(Vector3(50.0f, 0.0f, 5.0f), 50.0f), "sphere is inside 13");
  51. test.checkEqual(true, f.isInside(Vector3(-50.0f, 0.0f, 5.0f), 50.0f), "sphere is inside 14");
  52. }
  53. void FrustumTests::test() {
  54. Test test("Frustum");
  55. testToString(test);
  56. testPointIsInside(test);
  57. testSphereIsInside(test);
  58. test.finalize();
  59. }