Platformer in OpenGL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7 KiB

5 years ago
  1. #include <glm/ext/quaternion_transform.hpp>
  2. #include <glm/ext/quaternion_float.hpp>
  3. #include <glm/ext/vector_relational.hpp>
  4. #include <glm/ext/scalar_constants.hpp>
  5. #define GLM_ENABLE_EXPERIMENTAL
  6. #include <glm/gtx/quaternion.hpp>
  7. static int test_lookAt()
  8. {
  9. int Error(0);
  10. glm::vec3 eye(0.0f);
  11. glm::vec3 center(1.1f, -2.0f, 3.1416f);
  12. glm::vec3 up(-0.17f, 7.23f, -1.744f);
  13. glm::quat test_quat = glm::quatLookAt(glm::normalize(center - eye), up);
  14. glm::quat test_mat = glm::conjugate(glm::quat_cast(glm::lookAt(eye, center, up)));
  15. Error += static_cast<int>(glm::abs(glm::length(test_quat) - 1.0f) > glm::epsilon<float>());
  16. Error += static_cast<int>(glm::min(glm::length(test_quat + (-test_mat)), glm::length(test_quat + test_mat)) > glm::epsilon<float>());
  17. // Test left-handed implementation
  18. glm::quat test_quatLH = glm::quatLookAtLH(glm::normalize(center - eye), up);
  19. glm::quat test_matLH = glm::conjugate(glm::quat_cast(glm::lookAtLH(eye, center, up)));
  20. Error += static_cast<int>(glm::abs(glm::length(test_quatLH) - 1.0f) > glm::epsilon<float>());
  21. Error += static_cast<int>(glm::min(glm::length(test_quatLH - test_matLH), glm::length(test_quatLH + test_matLH)) > glm::epsilon<float>());
  22. // Test right-handed implementation
  23. glm::quat test_quatRH = glm::quatLookAtRH(glm::normalize(center - eye), up);
  24. glm::quat test_matRH = glm::conjugate(glm::quat_cast(glm::lookAtRH(eye, center, up)));
  25. Error += static_cast<int>(glm::abs(glm::length(test_quatRH) - 1.0f) > glm::epsilon<float>());
  26. Error += static_cast<int>(glm::min(glm::length(test_quatRH - test_matRH), glm::length(test_quatRH + test_matRH)) > glm::epsilon<float>());
  27. return Error;
  28. }
  29. int main()
  30. {
  31. int Error = 0;
  32. Error += test_lookAt();
  33. return Error;
  34. }