gtx_quaternion.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-05-25
  5. // Updated : 2011-05-31
  6. // Licence : This source is under MIT licence
  7. // File : test/gtx/quaternion.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #define GLM_FORCE_RADIANS
  10. #include <glm/glm.hpp>
  11. #include <glm/gtc/epsilon.hpp>
  12. #include <glm/gtx/quaternion.hpp>
  13. int test_quat_fastMix()
  14. {
  15. int Error = 0;
  16. glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
  17. glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  18. glm::quat C = glm::fastMix(A, B, 0.5f);
  19. glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
  20. Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
  21. Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
  22. Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
  23. Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
  24. return Error;
  25. }
  26. int test_quat_shortMix()
  27. {
  28. int Error(0);
  29. glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
  30. glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  31. glm::quat C = glm::shortMix(A, B, 0.5f);
  32. glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
  33. Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
  34. Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
  35. Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
  36. Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
  37. return Error;
  38. }
  39. int test_orientation()
  40. {
  41. int Error(0);
  42. {
  43. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  44. float p = glm::roll(q);
  45. }
  46. {
  47. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  48. float p = glm::pitch(q);
  49. }
  50. {
  51. glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
  52. float p = glm::yaw(q);
  53. }
  54. return Error;
  55. }
  56. int test_rotation()
  57. {
  58. int Error(0);
  59. glm::vec3 v(1, 0, 0);
  60. glm::vec3 u(0, 1, 0);
  61. glm::quat Rotation = glm::rotation(v, u);
  62. float Angle = glm::angle(Rotation);
  63. Error += glm::abs(Angle - glm::pi<float>() * 0.5f) < glm::epsilon<float>() ? 0 : 1;
  64. return Error;
  65. }
  66. int main()
  67. {
  68. int Error(0);
  69. Error += test_rotation();
  70. Error += test_quat_fastMix();
  71. Error += test_quat_shortMix();
  72. return Error;
  73. }