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.

147 lines
2.8 KiB

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