ViewTests.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "tests/ViewTests.h"
  2. #include "math/View.h"
  3. #include "tests/Test.h"
  4. #include "utils/StringBuffer.h"
  5. const float eps = 0.0001f;
  6. template<int N, typename T>
  7. static void compareVectors(Test& test, const Vector<N, T>& wanted,
  8. const Vector<N, T>& actual, const char* text) {
  9. for(int i = 0; i < N; i++) {
  10. test.checkFloat(
  11. wanted[i], actual[i], eps,
  12. StringBuffer<100>(text).append(" (").append(i).append(")"));
  13. }
  14. }
  15. static void testFromAngles(Test& test) {
  16. View v;
  17. v.updateDirections(0.0f, 0.0f);
  18. compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
  19. compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
  20. compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");
  21. compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), v.getRight(), "right");
  22. compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), v.getFront(), "front");
  23. compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f), v.getBack(), "back");
  24. }
  25. static void testFromQuaternion(Test& test) {
  26. View v;
  27. v.updateDirections(Quaternion());
  28. compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
  29. compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
  30. compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");
  31. compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), v.getRight(), "right");
  32. compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), v.getFront(), "front");
  33. compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f), v.getBack(), "back");
  34. }
  35. void ViewTests::test() {
  36. Test test("View");
  37. testFromAngles(test);
  38. testFromQuaternion(test);
  39. test.finalize();
  40. }