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.

250 lines
9.6 KiB

5 years ago
  1. #include <glm/ext/vector_common.hpp>
  2. #include <glm/ext/vector_bool1.hpp>
  3. #include <glm/ext/vector_bool1_precision.hpp>
  4. #include <glm/ext/vector_bool2.hpp>
  5. #include <glm/ext/vector_bool2_precision.hpp>
  6. #include <glm/ext/vector_bool3.hpp>
  7. #include <glm/ext/vector_bool3_precision.hpp>
  8. #include <glm/ext/vector_bool4.hpp>
  9. #include <glm/ext/vector_bool4_precision.hpp>
  10. #include <glm/ext/vector_float1.hpp>
  11. #include <glm/ext/vector_float1_precision.hpp>
  12. #include <glm/ext/vector_float2.hpp>
  13. #include <glm/ext/vector_float2_precision.hpp>
  14. #include <glm/ext/vector_float3.hpp>
  15. #include <glm/ext/vector_float3_precision.hpp>
  16. #include <glm/ext/vector_float4.hpp>
  17. #include <glm/ext/vector_float4_precision.hpp>
  18. #include <glm/ext/vector_double1.hpp>
  19. #include <glm/ext/vector_double1_precision.hpp>
  20. #include <glm/ext/vector_double2.hpp>
  21. #include <glm/ext/vector_double2_precision.hpp>
  22. #include <glm/ext/vector_double3.hpp>
  23. #include <glm/ext/vector_double3_precision.hpp>
  24. #include <glm/ext/vector_double4.hpp>
  25. #include <glm/ext/vector_double4_precision.hpp>
  26. #include <glm/ext/vector_relational.hpp>
  27. #include <glm/ext/scalar_constants.hpp>
  28. #include <glm/vector_relational.hpp>
  29. #include <glm/common.hpp>
  30. #if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
  31. # define GLM_NAN(T) NAN
  32. #else
  33. # define GLM_NAN(T) (static_cast<T>(0.0f) / static_cast<T>(0.0f))
  34. #endif
  35. template <typename vecType>
  36. static int test_min()
  37. {
  38. typedef typename vecType::value_type T;
  39. int Error = 0;
  40. vecType const N(static_cast<T>(0));
  41. vecType const B(static_cast<T>(1));
  42. Error += glm::all(glm::equal(glm::min(N, B), N, glm::epsilon<T>())) ? 0 : 1;
  43. Error += glm::all(glm::equal(glm::min(B, N), N, glm::epsilon<T>())) ? 0 : 1;
  44. vecType const C(static_cast<T>(2));
  45. Error += glm::all(glm::equal(glm::min(N, B, C), N, glm::epsilon<T>())) ? 0 : 1;
  46. Error += glm::all(glm::equal(glm::min(B, N, C), N, glm::epsilon<T>())) ? 0 : 1;
  47. Error += glm::all(glm::equal(glm::min(C, N, B), N, glm::epsilon<T>())) ? 0 : 1;
  48. Error += glm::all(glm::equal(glm::min(C, B, N), N, glm::epsilon<T>())) ? 0 : 1;
  49. Error += glm::all(glm::equal(glm::min(B, C, N), N, glm::epsilon<T>())) ? 0 : 1;
  50. Error += glm::all(glm::equal(glm::min(N, C, B), N, glm::epsilon<T>())) ? 0 : 1;
  51. vecType const D(static_cast<T>(3));
  52. Error += glm::all(glm::equal(glm::min(D, N, B, C), N, glm::epsilon<T>())) ? 0 : 1;
  53. Error += glm::all(glm::equal(glm::min(B, D, N, C), N, glm::epsilon<T>())) ? 0 : 1;
  54. Error += glm::all(glm::equal(glm::min(C, N, D, B), N, glm::epsilon<T>())) ? 0 : 1;
  55. Error += glm::all(glm::equal(glm::min(C, B, D, N), N, glm::epsilon<T>())) ? 0 : 1;
  56. Error += glm::all(glm::equal(glm::min(B, C, N, D), N, glm::epsilon<T>())) ? 0 : 1;
  57. Error += glm::all(glm::equal(glm::min(N, C, B, D), N, glm::epsilon<T>())) ? 0 : 1;
  58. return Error;
  59. }
  60. template <typename vecType>
  61. static int test_min_nan()
  62. {
  63. typedef typename vecType::value_type T;
  64. int Error = 0;
  65. vecType const B(static_cast<T>(1));
  66. vecType const N(GLM_NAN(T));
  67. Error += glm::all(glm::isnan(glm::min(N, B))) ? 0 : 1;
  68. Error += !glm::all(glm::isnan(glm::min(B, N))) ? 0 : 1;
  69. vecType const C(static_cast<T>(2));
  70. Error += glm::all(glm::isnan(glm::min(N, B, C))) ? 0 : 1;
  71. Error += !glm::all(glm::isnan(glm::min(B, N, C))) ? 0 : 1;
  72. Error += !glm::all(glm::isnan(glm::min(C, N, B))) ? 0 : 1;
  73. Error += !glm::all(glm::isnan(glm::min(C, B, N))) ? 0 : 1;
  74. Error += !glm::all(glm::isnan(glm::min(B, C, N))) ? 0 : 1;
  75. Error += glm::all(glm::isnan(glm::min(N, C, B))) ? 0 : 1;
  76. vecType const D(static_cast<T>(3));
  77. Error += !glm::all(glm::isnan(glm::min(D, N, B, C))) ? 0 : 1;
  78. Error += !glm::all(glm::isnan(glm::min(B, D, N, C))) ? 0 : 1;
  79. Error += !glm::all(glm::isnan(glm::min(C, N, D, B))) ? 0 : 1;
  80. Error += !glm::all(glm::isnan(glm::min(C, B, D, N))) ? 0 : 1;
  81. Error += !glm::all(glm::isnan(glm::min(B, C, N, D))) ? 0 : 1;
  82. Error += glm::all(glm::isnan(glm::min(N, C, B, D))) ? 0 : 1;
  83. return Error;
  84. }
  85. template <typename vecType>
  86. static int test_max()
  87. {
  88. typedef typename vecType::value_type T;
  89. int Error = 0;
  90. vecType const N(static_cast<T>(0));
  91. vecType const B(static_cast<T>(1));
  92. Error += glm::all(glm::equal(glm::max(N, B), B, glm::epsilon<T>())) ? 0 : 1;
  93. Error += glm::all(glm::equal(glm::max(B, N), B, glm::epsilon<T>())) ? 0 : 1;
  94. vecType const C(static_cast<T>(2));
  95. Error += glm::all(glm::equal(glm::max(N, B, C), C, glm::epsilon<T>())) ? 0 : 1;
  96. Error += glm::all(glm::equal(glm::max(B, N, C), C, glm::epsilon<T>())) ? 0 : 1;
  97. Error += glm::all(glm::equal(glm::max(C, N, B), C, glm::epsilon<T>())) ? 0 : 1;
  98. Error += glm::all(glm::equal(glm::max(C, B, N), C, glm::epsilon<T>())) ? 0 : 1;
  99. Error += glm::all(glm::equal(glm::max(B, C, N), C, glm::epsilon<T>())) ? 0 : 1;
  100. Error += glm::all(glm::equal(glm::max(N, C, B), C, glm::epsilon<T>())) ? 0 : 1;
  101. vecType const D(static_cast<T>(3));
  102. Error += glm::all(glm::equal(glm::max(D, N, B, C), D, glm::epsilon<T>())) ? 0 : 1;
  103. Error += glm::all(glm::equal(glm::max(B, D, N, C), D, glm::epsilon<T>())) ? 0 : 1;
  104. Error += glm::all(glm::equal(glm::max(C, N, D, B), D, glm::epsilon<T>())) ? 0 : 1;
  105. Error += glm::all(glm::equal(glm::max(C, B, D, N), D, glm::epsilon<T>())) ? 0 : 1;
  106. Error += glm::all(glm::equal(glm::max(B, C, N, D), D, glm::epsilon<T>())) ? 0 : 1;
  107. Error += glm::all(glm::equal(glm::max(N, C, B, D), D, glm::epsilon<T>())) ? 0 : 1;
  108. return Error;
  109. }
  110. template <typename vecType>
  111. static int test_max_nan()
  112. {
  113. typedef typename vecType::value_type T;
  114. int Error = 0;
  115. vecType const B(static_cast<T>(1));
  116. vecType const N(GLM_NAN(T));
  117. Error += glm::all(glm::isnan(glm::max(N, B))) ? 0 : 1;
  118. Error += !glm::all(glm::isnan(glm::max(B, N))) ? 0 : 1;
  119. vecType const C(static_cast<T>(2));
  120. Error += glm::all(glm::isnan(glm::max(N, B, C))) ? 0 : 1;
  121. Error += !glm::all(glm::isnan(glm::max(B, N, C))) ? 0 : 1;
  122. Error += !glm::all(glm::isnan(glm::max(C, N, B))) ? 0 : 1;
  123. Error += !glm::all(glm::isnan(glm::max(C, B, N))) ? 0 : 1;
  124. Error += !glm::all(glm::isnan(glm::max(B, C, N))) ? 0 : 1;
  125. Error += glm::all(glm::isnan(glm::max(N, C, B))) ? 0 : 1;
  126. vecType const D(static_cast<T>(3));
  127. Error += !glm::all(glm::isnan(glm::max(D, N, B, C))) ? 0 : 1;
  128. Error += !glm::all(glm::isnan(glm::max(B, D, N, C))) ? 0 : 1;
  129. Error += !glm::all(glm::isnan(glm::max(C, N, D, B))) ? 0 : 1;
  130. Error += !glm::all(glm::isnan(glm::max(C, B, D, N))) ? 0 : 1;
  131. Error += !glm::all(glm::isnan(glm::max(B, C, N, D))) ? 0 : 1;
  132. Error += glm::all(glm::isnan(glm::max(N, C, B, D))) ? 0 : 1;
  133. return Error;
  134. }
  135. template <typename vecType>
  136. static int test_fmin()
  137. {
  138. typedef typename vecType::value_type T;
  139. int Error = 0;
  140. vecType const B(static_cast<T>(1));
  141. vecType const N(GLM_NAN(T));
  142. Error += glm::all(glm::equal(glm::fmin(N, B), B, glm::epsilon<T>())) ? 0 : 1;
  143. Error += glm::all(glm::equal(glm::fmin(B, N), B, glm::epsilon<T>())) ? 0 : 1;
  144. vecType const C(static_cast<T>(2));
  145. Error += glm::all(glm::equal(glm::fmin(N, B, C), B, glm::epsilon<T>())) ? 0 : 1;
  146. Error += glm::all(glm::equal(glm::fmin(B, N, C), B, glm::epsilon<T>())) ? 0 : 1;
  147. Error += glm::all(glm::equal(glm::fmin(C, N, B), B, glm::epsilon<T>())) ? 0 : 1;
  148. Error += glm::all(glm::equal(glm::fmin(C, B, N), B, glm::epsilon<T>())) ? 0 : 1;
  149. Error += glm::all(glm::equal(glm::fmin(B, C, N), B, glm::epsilon<T>())) ? 0 : 1;
  150. Error += glm::all(glm::equal(glm::fmin(N, C, B), B, glm::epsilon<T>())) ? 0 : 1;
  151. vecType const D(static_cast<T>(3));
  152. Error += glm::all(glm::equal(glm::fmin(D, N, B, C), B, glm::epsilon<T>())) ? 0 : 1;
  153. Error += glm::all(glm::equal(glm::fmin(B, D, N, C), B, glm::epsilon<T>())) ? 0 : 1;
  154. Error += glm::all(glm::equal(glm::fmin(C, N, D, B), B, glm::epsilon<T>())) ? 0 : 1;
  155. Error += glm::all(glm::equal(glm::fmin(C, B, D, N), B, glm::epsilon<T>())) ? 0 : 1;
  156. Error += glm::all(glm::equal(glm::fmin(B, C, N, D), B, glm::epsilon<T>())) ? 0 : 1;
  157. Error += glm::all(glm::equal(glm::fmin(N, C, B, D), B, glm::epsilon<T>())) ? 0 : 1;
  158. return Error;
  159. }
  160. template <typename vecType>
  161. static int test_fmax()
  162. {
  163. typedef typename vecType::value_type T;
  164. int Error = 0;
  165. vecType const B(static_cast<T>(1));
  166. vecType const N(GLM_NAN(T));
  167. Error += glm::all(glm::equal(glm::fmax(N, B), B, glm::epsilon<T>())) ? 0 : 1;
  168. Error += glm::all(glm::equal(glm::fmax(B, N), B, glm::epsilon<T>())) ? 0 : 1;
  169. vecType const C(static_cast<T>(2));
  170. Error += glm::all(glm::equal(glm::fmax(N, B, C), C, glm::epsilon<T>())) ? 0 : 1;
  171. Error += glm::all(glm::equal(glm::fmax(B, N, C), C, glm::epsilon<T>())) ? 0 : 1;
  172. Error += glm::all(glm::equal(glm::fmax(C, N, B), C, glm::epsilon<T>())) ? 0 : 1;
  173. Error += glm::all(glm::equal(glm::fmax(C, B, N), C, glm::epsilon<T>())) ? 0 : 1;
  174. Error += glm::all(glm::equal(glm::fmax(B, C, N), C, glm::epsilon<T>())) ? 0 : 1;
  175. Error += glm::all(glm::equal(glm::fmax(N, C, B), C, glm::epsilon<T>())) ? 0 : 1;
  176. vecType const D(static_cast<T>(3));
  177. Error += glm::all(glm::equal(glm::fmax(D, N, B, C), D, glm::epsilon<T>())) ? 0 : 1;
  178. Error += glm::all(glm::equal(glm::fmax(B, D, N, C), D, glm::epsilon<T>())) ? 0 : 1;
  179. Error += glm::all(glm::equal(glm::fmax(C, N, D, B), D, glm::epsilon<T>())) ? 0 : 1;
  180. Error += glm::all(glm::equal(glm::fmax(C, B, D, N), D, glm::epsilon<T>())) ? 0 : 1;
  181. Error += glm::all(glm::equal(glm::fmax(B, C, N, D), D, glm::epsilon<T>())) ? 0 : 1;
  182. Error += glm::all(glm::equal(glm::fmax(N, C, B, D), D, glm::epsilon<T>())) ? 0 : 1;
  183. return Error;
  184. }
  185. int main()
  186. {
  187. int Error = 0;
  188. Error += test_min<glm::vec3>();
  189. Error += test_min<glm::vec2>();
  190. Error += test_min_nan<glm::vec3>();
  191. Error += test_min_nan<glm::vec2>();
  192. Error += test_max<glm::vec3>();
  193. Error += test_max<glm::vec2>();
  194. Error += test_max_nan<glm::vec3>();
  195. Error += test_max_nan<glm::vec2>();
  196. Error += test_fmin<glm::vec3>();
  197. Error += test_fmin<glm::vec2>();
  198. Error += test_fmax<glm::vec3>();
  199. Error += test_fmax<glm::vec2>();
  200. return Error;
  201. }