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.

207 lines
7.4 KiB

5 years ago
  1. #include <glm/ext/scalar_common.hpp>
  2. #include <glm/ext/scalar_constants.hpp>
  3. #include <glm/ext/scalar_relational.hpp>
  4. #include <glm/common.hpp>
  5. #if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
  6. # define GLM_NAN(T) NAN
  7. #else
  8. # define GLM_NAN(T) (static_cast<T>(0.0f) / static_cast<T>(0.0f))
  9. #endif
  10. template <typename T>
  11. static int test_min()
  12. {
  13. int Error = 0;
  14. T const N = static_cast<T>(0);
  15. T const B = static_cast<T>(1);
  16. Error += glm::equal(glm::min(N, B), N, glm::epsilon<T>()) ? 0 : 1;
  17. Error += glm::equal(glm::min(B, N), N, glm::epsilon<T>()) ? 0 : 1;
  18. T const C = static_cast<T>(2);
  19. Error += glm::equal(glm::min(N, B, C), N, glm::epsilon<T>()) ? 0 : 1;
  20. Error += glm::equal(glm::min(B, N, C), N, glm::epsilon<T>()) ? 0 : 1;
  21. Error += glm::equal(glm::min(C, N, B), N, glm::epsilon<T>()) ? 0 : 1;
  22. Error += glm::equal(glm::min(C, B, N), N, glm::epsilon<T>()) ? 0 : 1;
  23. Error += glm::equal(glm::min(B, C, N), N, glm::epsilon<T>()) ? 0 : 1;
  24. Error += glm::equal(glm::min(N, C, B), N, glm::epsilon<T>()) ? 0 : 1;
  25. T const D = static_cast<T>(3);
  26. Error += glm::equal(glm::min(D, N, B, C), N, glm::epsilon<T>()) ? 0 : 1;
  27. Error += glm::equal(glm::min(B, D, N, C), N, glm::epsilon<T>()) ? 0 : 1;
  28. Error += glm::equal(glm::min(C, N, D, B), N, glm::epsilon<T>()) ? 0 : 1;
  29. Error += glm::equal(glm::min(C, B, D, N), N, glm::epsilon<T>()) ? 0 : 1;
  30. Error += glm::equal(glm::min(B, C, N, D), N, glm::epsilon<T>()) ? 0 : 1;
  31. Error += glm::equal(glm::min(N, C, B, D), N, glm::epsilon<T>()) ? 0 : 1;
  32. return Error;
  33. }
  34. template <typename T>
  35. static int test_min_nan()
  36. {
  37. int Error = 0;
  38. T const B = static_cast<T>(1);
  39. T const N = static_cast<T>(GLM_NAN(T));
  40. Error += glm::isnan(glm::min(N, B)) ? 0 : 1;
  41. Error += !glm::isnan(glm::min(B, N)) ? 0 : 1;
  42. T const C = static_cast<T>(2);
  43. Error += glm::isnan(glm::min(N, B, C)) ? 0 : 1;
  44. Error += !glm::isnan(glm::min(B, N, C)) ? 0 : 1;
  45. Error += !glm::isnan(glm::min(C, N, B)) ? 0 : 1;
  46. Error += !glm::isnan(glm::min(C, B, N)) ? 0 : 1;
  47. Error += !glm::isnan(glm::min(B, C, N)) ? 0 : 1;
  48. Error += glm::isnan(glm::min(N, C, B)) ? 0 : 1;
  49. T const D = static_cast<T>(3);
  50. Error += !glm::isnan(glm::min(D, N, B, C)) ? 0 : 1;
  51. Error += !glm::isnan(glm::min(B, D, N, C)) ? 0 : 1;
  52. Error += !glm::isnan(glm::min(C, N, D, B)) ? 0 : 1;
  53. Error += !glm::isnan(glm::min(C, B, D, N)) ? 0 : 1;
  54. Error += !glm::isnan(glm::min(B, C, N, D)) ? 0 : 1;
  55. Error += glm::isnan(glm::min(N, C, B, D)) ? 0 : 1;
  56. return Error;
  57. }
  58. template <typename T>
  59. static int test_max()
  60. {
  61. int Error = 0;
  62. T const N = static_cast<T>(0);
  63. T const B = static_cast<T>(1);
  64. Error += glm::equal(glm::max(N, B), B, glm::epsilon<T>()) ? 0 : 1;
  65. Error += glm::equal(glm::max(B, N), B, glm::epsilon<T>()) ? 0 : 1;
  66. T const C = static_cast<T>(2);
  67. Error += glm::equal(glm::max(N, B, C), C, glm::epsilon<T>()) ? 0 : 1;
  68. Error += glm::equal(glm::max(B, N, C), C, glm::epsilon<T>()) ? 0 : 1;
  69. Error += glm::equal(glm::max(C, N, B), C, glm::epsilon<T>()) ? 0 : 1;
  70. Error += glm::equal(glm::max(C, B, N), C, glm::epsilon<T>()) ? 0 : 1;
  71. Error += glm::equal(glm::max(B, C, N), C, glm::epsilon<T>()) ? 0 : 1;
  72. Error += glm::equal(glm::max(N, C, B), C, glm::epsilon<T>()) ? 0 : 1;
  73. T const D = static_cast<T>(3);
  74. Error += glm::equal(glm::max(D, N, B, C), D, glm::epsilon<T>()) ? 0 : 1;
  75. Error += glm::equal(glm::max(B, D, N, C), D, glm::epsilon<T>()) ? 0 : 1;
  76. Error += glm::equal(glm::max(C, N, D, B), D, glm::epsilon<T>()) ? 0 : 1;
  77. Error += glm::equal(glm::max(C, B, D, N), D, glm::epsilon<T>()) ? 0 : 1;
  78. Error += glm::equal(glm::max(B, C, N, D), D, glm::epsilon<T>()) ? 0 : 1;
  79. Error += glm::equal(glm::max(N, C, B, D), D, glm::epsilon<T>()) ? 0 : 1;
  80. return Error;
  81. }
  82. template <typename T>
  83. static int test_max_nan()
  84. {
  85. int Error = 0;
  86. T const B = static_cast<T>(1);
  87. T const N = static_cast<T>(GLM_NAN(T));
  88. Error += glm::isnan(glm::max(N, B)) ? 0 : 1;
  89. Error += !glm::isnan(glm::max(B, N)) ? 0 : 1;
  90. T const C = static_cast<T>(2);
  91. Error += glm::isnan(glm::max(N, B, C)) ? 0 : 1;
  92. Error += !glm::isnan(glm::max(B, N, C)) ? 0 : 1;
  93. Error += !glm::isnan(glm::max(C, N, B)) ? 0 : 1;
  94. Error += !glm::isnan(glm::max(C, B, N)) ? 0 : 1;
  95. Error += !glm::isnan(glm::max(B, C, N)) ? 0 : 1;
  96. Error += glm::isnan(glm::max(N, C, B)) ? 0 : 1;
  97. T const D = static_cast<T>(3);
  98. Error += !glm::isnan(glm::max(D, N, B, C)) ? 0 : 1;
  99. Error += !glm::isnan(glm::max(B, D, N, C)) ? 0 : 1;
  100. Error += !glm::isnan(glm::max(C, N, D, B)) ? 0 : 1;
  101. Error += !glm::isnan(glm::max(C, B, D, N)) ? 0 : 1;
  102. Error += !glm::isnan(glm::max(B, C, N, D)) ? 0 : 1;
  103. Error += glm::isnan(glm::max(N, C, B, D)) ? 0 : 1;
  104. return Error;
  105. }
  106. template <typename T>
  107. static int test_fmin()
  108. {
  109. int Error = 0;
  110. T const B = static_cast<T>(1);
  111. T const N = static_cast<T>(GLM_NAN(T));
  112. Error += glm::equal(glm::fmin(N, B), B, glm::epsilon<T>()) ? 0 : 1;
  113. Error += glm::equal(glm::fmin(B, N), B, glm::epsilon<T>()) ? 0 : 1;
  114. T const C = static_cast<T>(2);
  115. Error += glm::equal(glm::fmin(N, B, C), B, glm::epsilon<T>()) ? 0 : 1;
  116. Error += glm::equal(glm::fmin(B, N, C), B, glm::epsilon<T>()) ? 0 : 1;
  117. Error += glm::equal(glm::fmin(C, N, B), B, glm::epsilon<T>()) ? 0 : 1;
  118. Error += glm::equal(glm::fmin(C, B, N), B, glm::epsilon<T>()) ? 0 : 1;
  119. Error += glm::equal(glm::fmin(B, C, N), B, glm::epsilon<T>()) ? 0 : 1;
  120. Error += glm::equal(glm::fmin(N, C, B), B, glm::epsilon<T>()) ? 0 : 1;
  121. T const D = static_cast<T>(3);
  122. Error += glm::equal(glm::fmin(D, N, B, C), B, glm::epsilon<T>()) ? 0 : 1;
  123. Error += glm::equal(glm::fmin(B, D, N, C), B, glm::epsilon<T>()) ? 0 : 1;
  124. Error += glm::equal(glm::fmin(C, N, D, B), B, glm::epsilon<T>()) ? 0 : 1;
  125. Error += glm::equal(glm::fmin(C, B, D, N), B, glm::epsilon<T>()) ? 0 : 1;
  126. Error += glm::equal(glm::fmin(B, C, N, D), B, glm::epsilon<T>()) ? 0 : 1;
  127. Error += glm::equal(glm::fmin(N, C, B, D), B, glm::epsilon<T>()) ? 0 : 1;
  128. return Error;
  129. }
  130. template <typename T>
  131. static int test_fmax()
  132. {
  133. int Error = 0;
  134. T const B = static_cast<T>(1);
  135. T const N = static_cast<T>(GLM_NAN(T));
  136. Error += glm::equal(glm::fmax(N, B), B, glm::epsilon<T>()) ? 0 : 1;
  137. Error += glm::equal(glm::fmax(B, N), B, glm::epsilon<T>()) ? 0 : 1;
  138. T const C = static_cast<T>(2);
  139. Error += glm::equal(glm::fmax(N, B, C), C, glm::epsilon<T>()) ? 0 : 1;
  140. Error += glm::equal(glm::fmax(B, N, C), C, glm::epsilon<T>()) ? 0 : 1;
  141. Error += glm::equal(glm::fmax(C, N, B), C, glm::epsilon<T>()) ? 0 : 1;
  142. Error += glm::equal(glm::fmax(C, B, N), C, glm::epsilon<T>()) ? 0 : 1;
  143. Error += glm::equal(glm::fmax(B, C, N), C, glm::epsilon<T>()) ? 0 : 1;
  144. Error += glm::equal(glm::fmax(N, C, B), C, glm::epsilon<T>()) ? 0 : 1;
  145. T const D = static_cast<T>(3);
  146. Error += glm::equal(glm::fmax(D, N, B, C), D, glm::epsilon<T>()) ? 0 : 1;
  147. Error += glm::equal(glm::fmax(B, D, N, C), D, glm::epsilon<T>()) ? 0 : 1;
  148. Error += glm::equal(glm::fmax(C, N, D, B), D, glm::epsilon<T>()) ? 0 : 1;
  149. Error += glm::equal(glm::fmax(C, B, D, N), D, glm::epsilon<T>()) ? 0 : 1;
  150. Error += glm::equal(glm::fmax(B, C, N, D), D, glm::epsilon<T>()) ? 0 : 1;
  151. Error += glm::equal(glm::fmax(N, C, B, D), D, glm::epsilon<T>()) ? 0 : 1;
  152. return Error;
  153. }
  154. int main()
  155. {
  156. int Error = 0;
  157. Error += test_min<float>();
  158. Error += test_min<double>();
  159. Error += test_min_nan<float>();
  160. Error += test_min_nan<double>();
  161. Error += test_max<float>();
  162. Error += test_max<double>();
  163. Error += test_max_nan<float>();
  164. Error += test_max_nan<double>();
  165. Error += test_fmin<float>();
  166. Error += test_fmin<double>();
  167. Error += test_fmax<float>();
  168. Error += test_fmax<double>();
  169. return Error;
  170. }