gtx_rotate_vector.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/gtx/rotate_vector.hpp>
  3. #include <glm/gtc/constants.hpp>
  4. #include <glm/ext/vector_relational.hpp>
  5. static int test_rotate()
  6. {
  7. int Error = 0;
  8. glm::vec2 A = glm::rotate(glm::vec2(1, 0), glm::pi<float>() * 0.5f);
  9. Error += glm::all(glm::equal(A, glm::vec2(0.0f, 1.0f), glm::epsilon<float>())) ? 0 : 1;
  10. glm::vec3 B = glm::rotate(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  11. Error += glm::all(glm::equal(B, glm::vec3(0.0f, 1.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
  12. glm::vec4 C = glm::rotate(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
  13. Error += glm::all(glm::equal(C, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::epsilon<float>())) ? 0 : 1;
  14. return Error;
  15. }
  16. static int test_rotateX()
  17. {
  18. int Error = 0;
  19. glm::vec3 D = glm::rotateX(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
  20. Error += glm::all(glm::equal(D, glm::vec3(1.0f, 0.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
  21. glm::vec4 E = glm::rotateX(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
  22. Error += glm::all(glm::equal(E, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), glm::epsilon<float>())) ? 0 : 1;
  23. return Error;
  24. }
  25. static int test_rotateY()
  26. {
  27. int Error = 0;
  28. glm::vec3 F = glm::rotateY(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
  29. Error += glm::all(glm::equal(F, glm::vec3(0.0f, 0.0f, -1.0f), glm::epsilon<float>())) ? 0 : 1;
  30. glm::vec4 G = glm::rotateY(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
  31. Error += glm::all(glm::equal(G, glm::vec4(0.0f, 0.0f, -1.0f, 1.0f), glm::epsilon<float>())) ? 0 : 1;
  32. return Error;
  33. }
  34. static int test_rotateZ()
  35. {
  36. int Error = 0;
  37. glm::vec3 H = glm::rotateZ(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
  38. Error += glm::all(glm::equal(H, glm::vec3(0.0f, 1.0f, 0.0f), glm::epsilon<float>())) ? 0 : 1;
  39. glm::vec4 I = glm::rotateZ(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
  40. Error += glm::all(glm::equal(I, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), glm::epsilon<float>())) ? 0 : 1;
  41. return Error;
  42. }
  43. static int test_orientation()
  44. {
  45. int Error = 0;
  46. glm::mat4 O = glm::orientation(glm::normalize(glm::vec3(1)), glm::vec3(0, 0, 1));
  47. Error += glm::all(glm::equal(O[0], glm::vec4(0.79f, -0.21f,-0.58f, 0.0f), 0.1f)) ? 0 : 1;
  48. Error += glm::all(glm::equal(O[1], glm::vec4(-0.21f, 0.79f,-0.58f, 0.0f), 0.1f)) ? 0 : 1;
  49. Error += glm::all(glm::equal(O[2], glm::vec4(0.58f, 0.58f, 0.58f, 0.0f), 0.1f)) ? 0 : 1;
  50. Error += glm::all(glm::equal(O[3], glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), 0.1f)) ? 0 : 1;
  51. return Error;
  52. }
  53. int main()
  54. {
  55. int Error = 0;
  56. Error += test_rotate();
  57. Error += test_rotateX();
  58. Error += test_rotateY();
  59. Error += test_rotateZ();
  60. Error += test_orientation();
  61. return Error;
  62. }