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.

161 lines
3.7 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/gtx/common.hpp>
  3. #include <glm/gtc/integer.hpp>
  4. #include <glm/gtc/epsilon.hpp>
  5. #include <glm/vector_relational.hpp>
  6. #include <glm/common.hpp>
  7. namespace fmod_
  8. {
  9. template<typename genType>
  10. GLM_FUNC_QUALIFIER genType modTrunc(genType a, genType b)
  11. {
  12. return a - b * glm::trunc(a / b);
  13. }
  14. int test()
  15. {
  16. int Error(0);
  17. {
  18. float A0(3.0);
  19. float B0(2.0f);
  20. float C0 = glm::fmod(A0, B0);
  21. Error += glm::abs(C0 - 1.0f) < 0.00001f ? 0 : 1;
  22. glm::vec4 A1(3.0);
  23. float B1(2.0f);
  24. glm::vec4 C1 = glm::fmod(A1, B1);
  25. Error += glm::all(glm::epsilonEqual(C1, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
  26. glm::vec4 A2(3.0);
  27. glm::vec4 B2(2.0f);
  28. glm::vec4 C2 = glm::fmod(A2, B2);
  29. Error += glm::all(glm::epsilonEqual(C2, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
  30. glm::ivec4 A3(3);
  31. int B3(2);
  32. glm::ivec4 C3 = glm::fmod(A3, B3);
  33. Error += glm::all(glm::equal(C3, glm::ivec4(1))) ? 0 : 1;
  34. glm::ivec4 A4(3);
  35. glm::ivec4 B4(2);
  36. glm::ivec4 C4 = glm::fmod(A4, B4);
  37. Error += glm::all(glm::equal(C4, glm::ivec4(1))) ? 0 : 1;
  38. }
  39. {
  40. float A0(22.0);
  41. float B0(-10.0f);
  42. float C0 = glm::fmod(A0, B0);
  43. Error += glm::abs(C0 - 2.0f) < 0.00001f ? 0 : 1;
  44. glm::vec4 A1(22.0);
  45. float B1(-10.0f);
  46. glm::vec4 C1 = glm::fmod(A1, B1);
  47. Error += glm::all(glm::epsilonEqual(C1, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
  48. glm::vec4 A2(22.0);
  49. glm::vec4 B2(-10.0f);
  50. glm::vec4 C2 = glm::fmod(A2, B2);
  51. Error += glm::all(glm::epsilonEqual(C2, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
  52. glm::ivec4 A3(22);
  53. int B3(-10);
  54. glm::ivec4 C3 = glm::fmod(A3, B3);
  55. Error += glm::all(glm::equal(C3, glm::ivec4(2))) ? 0 : 1;
  56. glm::ivec4 A4(22);
  57. glm::ivec4 B4(-10);
  58. glm::ivec4 C4 = glm::fmod(A4, B4);
  59. Error += glm::all(glm::equal(C4, glm::ivec4(2))) ? 0 : 1;
  60. }
  61. // http://stackoverflow.com/questions/7610631/glsl-mod-vs-hlsl-fmod
  62. {
  63. for (float y = -10.0f; y < 10.0f; y += 0.1f)
  64. for (float x = -10.0f; x < 10.0f; x += 0.1f)
  65. {
  66. float const A(std::fmod(x, y));
  67. //float const B(std::remainder(x, y));
  68. float const C(glm::fmod(x, y));
  69. float const D(modTrunc(x, y));
  70. //Error += glm::epsilonEqual(A, B, 0.0001f) ? 0 : 1;
  71. //assert(!Error);
  72. Error += glm::epsilonEqual(A, C, 0.0001f) ? 0 : 1;
  73. assert(!Error);
  74. Error += glm::epsilonEqual(A, D, 0.00001f) ? 0 : 1;
  75. assert(!Error);
  76. }
  77. }
  78. return Error;
  79. }
  80. }//namespace fmod_
  81. int test_isdenormal()
  82. {
  83. int Error = 0;
  84. bool A = glm::isdenormal(1.0f);
  85. Error += !A ? 0 : 1;
  86. glm::bvec1 B = glm::isdenormal(glm::vec1(1.0f));
  87. Error += !glm::any(B) ? 0 : 1;
  88. glm::bvec2 C = glm::isdenormal(glm::vec2(1.0f));
  89. Error += !glm::any(C) ? 0 : 1;
  90. glm::bvec3 D = glm::isdenormal(glm::vec3(1.0f));
  91. Error += !glm::any(D) ? 0 : 1;
  92. glm::bvec4 E = glm::isdenormal(glm::vec4(1.0f));
  93. Error += !glm::any(E) ? 0 : 1;
  94. return Error;
  95. }
  96. int test_openBounded()
  97. {
  98. int Error = 0;
  99. Error += glm::all(glm::openBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  100. Error += !glm::all(glm::openBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  101. Error += !glm::all(glm::openBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  102. return Error;
  103. }
  104. int test_closeBounded()
  105. {
  106. int Error = 0;
  107. Error += glm::all(glm::closeBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  108. Error += glm::all(glm::closeBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  109. Error += glm::all(glm::closeBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
  110. return Error;
  111. }
  112. int main()
  113. {
  114. int Error = 0;
  115. Error += test_isdenormal();
  116. Error += ::fmod_::test();
  117. Error += test_openBounded();
  118. Error += test_closeBounded();
  119. return Error;
  120. }