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.

107 lines
2.3 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/gtc/epsilon.hpp>
  3. #include <glm/gtc/type_ptr.hpp>
  4. #include <glm/gtc/matrix_transform.hpp>
  5. #include <glm/gtx/transform.hpp>
  6. #include <glm/gtx/quaternion.hpp>
  7. #include <glm/gtx/compatibility.hpp>
  8. #include <glm/ext.hpp>
  9. int test_quat_fastMix()
  10. {
  11. int Error = 0;
  12. glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
  13. glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  14. glm::quat C = glm::fastMix(A, B, 0.5f);
  15. glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
  16. Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
  17. Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
  18. Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
  19. Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
  20. return Error;
  21. }
  22. int test_quat_shortMix()
  23. {
  24. int Error(0);
  25. glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
  26. glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  27. glm::quat C = glm::shortMix(A, B, 0.5f);
  28. glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
  29. Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
  30. Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
  31. Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
  32. Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
  33. return Error;
  34. }
  35. int test_orientation()
  36. {
  37. int Error = 0;
  38. {
  39. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  40. float p = glm::roll(q);
  41. Error += glm::epsilonEqual(p, glm::pi<float>() * 0.5f, 0.0001f) ? 0 : 1;
  42. }
  43. {
  44. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  45. float p = glm::pitch(q);
  46. Error += glm::epsilonEqual(p, 0.f, 0.0001f) ? 0 : 1;
  47. }
  48. {
  49. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  50. float p = glm::yaw(q);
  51. Error += glm::epsilonEqual(p, 0.f, 0.0001f) ? 0 : 1;
  52. }
  53. return Error;
  54. }
  55. int test_rotation()
  56. {
  57. int Error(0);
  58. glm::vec3 v(1, 0, 0);
  59. glm::vec3 u(0, 1, 0);
  60. glm::quat Rotation = glm::rotation(v, u);
  61. float Angle = glm::angle(Rotation);
  62. Error += glm::abs(Angle - glm::pi<float>() * 0.5f) < glm::epsilon<float>() ? 0 : 1;
  63. return Error;
  64. }
  65. int test_log()
  66. {
  67. int Error(0);
  68. glm::quat q;
  69. glm::quat p = glm::log(q);
  70. glm::quat r = glm::exp(p);
  71. return Error;
  72. }
  73. int main()
  74. {
  75. int Error = 0;
  76. Error += test_log();
  77. Error += test_rotation();
  78. Error += test_orientation();
  79. Error += test_quat_fastMix();
  80. Error += test_quat_shortMix();
  81. return Error;
  82. }