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.

142 lines
2.6 KiB

5 years ago
  1. #include <glm/ext/scalar_relational.hpp>
  2. #include <glm/ext/vector_relational.hpp>
  3. #include <glm/ext/matrix_relational.hpp>
  4. #include <glm/gtc/constants.hpp>
  5. #include <glm/mat2x2.hpp>
  6. #include <glm/mat2x3.hpp>
  7. #include <glm/mat2x4.hpp>
  8. #include <glm/mat3x2.hpp>
  9. #include <glm/mat3x3.hpp>
  10. #include <glm/mat3x4.hpp>
  11. #include <glm/mat4x2.hpp>
  12. #include <glm/mat4x3.hpp>
  13. #include <glm/mat4x4.hpp>
  14. #include <vector>
  15. static int test_operators()
  16. {
  17. glm::mat2x3 l(1.0f);
  18. glm::mat2x3 m(1.0f);
  19. glm::vec2 u(1.0f);
  20. glm::vec3 v(1.0f);
  21. float x = 1.0f;
  22. glm::vec3 a = m * u;
  23. glm::vec2 b = v * m;
  24. glm::mat2x3 n = x / m;
  25. glm::mat2x3 o = m / x;
  26. glm::mat2x3 p = x * m;
  27. glm::mat2x3 q = m * x;
  28. bool R = glm::any(glm::notEqual(m, q, glm::epsilon<float>()));
  29. bool S = glm::all(glm::equal(m, l, glm::epsilon<float>()));
  30. return (S && !R) ? 0 : 1;
  31. }
  32. int test_ctr()
  33. {
  34. int Error(0);
  35. #if GLM_HAS_INITIALIZER_LISTS
  36. glm::mat2x3 m0(
  37. glm::vec3(0, 1, 2),
  38. glm::vec3(3, 4, 5));
  39. glm::mat2x3 m1{0, 1, 2, 3, 4, 5};
  40. glm::mat2x3 m2{
  41. {0, 1, 2},
  42. {3, 4, 5}};
  43. Error += glm::all(glm::equal(m0, m2, glm::epsilon<float>())) ? 0 : 1;
  44. Error += glm::all(glm::equal(m1, m2, glm::epsilon<float>())) ? 0 : 1;
  45. std::vector<glm::mat2x3> v1{
  46. {0, 1, 2, 3, 4, 5},
  47. {0, 1, 2, 3, 4, 5}
  48. };
  49. std::vector<glm::mat2x3> v2{
  50. {
  51. { 0, 1, 2},
  52. { 4, 5, 6}
  53. },
  54. {
  55. { 0, 1, 2},
  56. { 4, 5, 6}
  57. }
  58. };
  59. #endif//GLM_HAS_INITIALIZER_LISTS
  60. return Error;
  61. }
  62. namespace cast
  63. {
  64. template<typename genType>
  65. int entry()
  66. {
  67. int Error = 0;
  68. genType A(1.0f);
  69. glm::mat2x3 B(A);
  70. glm::mat2x3 Identity(1.0f);
  71. Error += glm::all(glm::equal(B, Identity, glm::epsilon<float>())) ? 0 : 1;
  72. return Error;
  73. }
  74. int test()
  75. {
  76. int Error = 0;
  77. Error += entry<glm::mat2x2>();
  78. Error += entry<glm::mat2x3>();
  79. Error += entry<glm::mat2x4>();
  80. Error += entry<glm::mat3x2>();
  81. Error += entry<glm::mat3x3>();
  82. Error += entry<glm::mat3x4>();
  83. Error += entry<glm::mat4x2>();
  84. Error += entry<glm::mat4x3>();
  85. Error += entry<glm::mat4x4>();
  86. return Error;
  87. }
  88. }//namespace cast
  89. int test_size()
  90. {
  91. int Error = 0;
  92. Error += 24 == sizeof(glm::mat2x3) ? 0 : 1;
  93. Error += 48 == sizeof(glm::dmat2x3) ? 0 : 1;
  94. Error += glm::mat2x3().length() == 2 ? 0 : 1;
  95. Error += glm::dmat2x3().length() == 2 ? 0 : 1;
  96. Error += glm::mat2x3::length() == 2 ? 0 : 1;
  97. Error += glm::dmat2x3::length() == 2 ? 0 : 1;
  98. return Error;
  99. }
  100. int test_constexpr()
  101. {
  102. #if GLM_HAS_CONSTEXPR
  103. static_assert(glm::mat2x3::length() == 2, "GLM: Failed constexpr");
  104. #endif
  105. return 0;
  106. }
  107. int main()
  108. {
  109. int Error = 0;
  110. Error += cast::test();
  111. Error += test_ctr();
  112. Error += test_operators();
  113. Error += test_size();
  114. Error += test_constexpr();
  115. return Error;
  116. }