FrustumTests.cpp 3.5 KB

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