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.

383 lines
12 KiB

5 years ago
  1. #include <glm/ext/vector_relational.hpp>
  2. #include <glm/gtc/constants.hpp>
  3. #include <glm/gtc/matrix_access.hpp>
  4. #include <glm/mat2x2.hpp>
  5. #include <glm/mat2x3.hpp>
  6. #include <glm/mat2x4.hpp>
  7. #include <glm/mat3x2.hpp>
  8. #include <glm/mat3x3.hpp>
  9. #include <glm/mat3x4.hpp>
  10. #include <glm/mat4x2.hpp>
  11. #include <glm/mat4x3.hpp>
  12. #include <glm/mat4x4.hpp>
  13. int test_mat2x2_row_set()
  14. {
  15. int Error = 0;
  16. glm::mat2x2 m(1);
  17. m = glm::row(m, 0, glm::vec2( 0, 1));
  18. m = glm::row(m, 1, glm::vec2( 4, 5));
  19. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  20. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  21. return Error;
  22. }
  23. int test_mat2x2_col_set()
  24. {
  25. int Error = 0;
  26. glm::mat2x2 m(1);
  27. m = glm::column(m, 0, glm::vec2( 0, 1));
  28. m = glm::column(m, 1, glm::vec2( 4, 5));
  29. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  30. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  31. return Error;
  32. }
  33. int test_mat2x3_row_set()
  34. {
  35. int Error = 0;
  36. glm::mat2x3 m(1);
  37. m = glm::row(m, 0, glm::vec2( 0, 1));
  38. m = glm::row(m, 1, glm::vec2( 4, 5));
  39. m = glm::row(m, 2, glm::vec2( 8, 9));
  40. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  41. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  42. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
  43. return Error;
  44. }
  45. int test_mat2x3_col_set()
  46. {
  47. int Error = 0;
  48. glm::mat2x3 m(1);
  49. m = glm::column(m, 0, glm::vec3( 0, 1, 2));
  50. m = glm::column(m, 1, glm::vec3( 4, 5, 6));
  51. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  52. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  53. return Error;
  54. }
  55. int test_mat2x4_row_set()
  56. {
  57. int Error = 0;
  58. glm::mat2x4 m(1);
  59. m = glm::row(m, 0, glm::vec2( 0, 1));
  60. m = glm::row(m, 1, glm::vec2( 4, 5));
  61. m = glm::row(m, 2, glm::vec2( 8, 9));
  62. m = glm::row(m, 3, glm::vec2(12, 13));
  63. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  64. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  65. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
  66. Error += glm::all(glm::equal(glm::row(m, 3), glm::vec2(12, 13), glm::epsilon<float>())) ? 0 : 1;
  67. return Error;
  68. }
  69. int test_mat2x4_col_set()
  70. {
  71. int Error = 0;
  72. glm::mat2x4 m(1);
  73. m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
  74. m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
  75. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  76. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  77. return Error;
  78. }
  79. int test_mat3x2_row_set()
  80. {
  81. int Error = 0;
  82. glm::mat3x2 m(1);
  83. m = glm::row(m, 0, glm::vec3( 0, 1, 2));
  84. m = glm::row(m, 1, glm::vec3( 4, 5, 6));
  85. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  86. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  87. return Error;
  88. }
  89. int test_mat3x2_col_set()
  90. {
  91. int Error = 0;
  92. glm::mat3x2 m(1);
  93. m = glm::column(m, 0, glm::vec2( 0, 1));
  94. m = glm::column(m, 1, glm::vec2( 4, 5));
  95. m = glm::column(m, 2, glm::vec2( 8, 9));
  96. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  97. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  98. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
  99. return Error;
  100. }
  101. int test_mat3x3_row_set()
  102. {
  103. int Error = 0;
  104. glm::mat3x3 m(1);
  105. m = glm::row(m, 0, glm::vec3( 0, 1, 2));
  106. m = glm::row(m, 1, glm::vec3( 4, 5, 6));
  107. m = glm::row(m, 2, glm::vec3( 8, 9, 10));
  108. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  109. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  110. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
  111. return Error;
  112. }
  113. int test_mat3x3_col_set()
  114. {
  115. int Error = 0;
  116. glm::mat3x3 m(1);
  117. m = glm::column(m, 0, glm::vec3( 0, 1, 2));
  118. m = glm::column(m, 1, glm::vec3( 4, 5, 6));
  119. m = glm::column(m, 2, glm::vec3( 8, 9, 10));
  120. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  121. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  122. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
  123. return Error;
  124. }
  125. int test_mat3x4_row_set()
  126. {
  127. int Error = 0;
  128. glm::mat3x4 m(1);
  129. m = glm::row(m, 0, glm::vec3( 0, 1, 2));
  130. m = glm::row(m, 1, glm::vec3( 4, 5, 6));
  131. m = glm::row(m, 2, glm::vec3( 8, 9, 10));
  132. m = glm::row(m, 3, glm::vec3(12, 13, 14));
  133. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  134. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  135. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
  136. Error += glm::all(glm::equal(glm::row(m, 3), glm::vec3(12, 13, 14), glm::epsilon<float>())) ? 0 : 1;
  137. return Error;
  138. }
  139. int test_mat3x4_col_set()
  140. {
  141. int Error = 0;
  142. glm::mat3x4 m(1);
  143. m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
  144. m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
  145. m = glm::column(m, 2, glm::vec4( 8, 9, 10, 11));
  146. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  147. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  148. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
  149. return Error;
  150. }
  151. int test_mat4x2_row_set()
  152. {
  153. int Error = 0;
  154. glm::mat4x2 m(1);
  155. m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
  156. m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
  157. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  158. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  159. return Error;
  160. }
  161. int test_mat4x2_col_set()
  162. {
  163. int Error = 0;
  164. glm::mat4x2 m(1);
  165. m = glm::column(m, 0, glm::vec2( 0, 1));
  166. m = glm::column(m, 1, glm::vec2( 4, 5));
  167. m = glm::column(m, 2, glm::vec2( 8, 9));
  168. m = glm::column(m, 3, glm::vec2(12, 13));
  169. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec2( 0, 1), glm::epsilon<float>())) ? 0 : 1;
  170. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec2( 4, 5), glm::epsilon<float>())) ? 0 : 1;
  171. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec2( 8, 9), glm::epsilon<float>())) ? 0 : 1;
  172. Error += glm::all(glm::equal(glm::column(m, 3), glm::vec2(12, 13), glm::epsilon<float>())) ? 0 : 1;
  173. return Error;
  174. }
  175. int test_mat4x3_row_set()
  176. {
  177. int Error = 0;
  178. glm::mat4x3 m(1);
  179. m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
  180. m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
  181. m = glm::row(m, 2, glm::vec4( 8, 9, 10, 11));
  182. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  183. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  184. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
  185. return Error;
  186. }
  187. int test_mat4x3_col_set()
  188. {
  189. int Error = 0;
  190. glm::mat4x3 m(1);
  191. m = glm::column(m, 0, glm::vec3( 0, 1, 2));
  192. m = glm::column(m, 1, glm::vec3( 4, 5, 6));
  193. m = glm::column(m, 2, glm::vec3( 8, 9, 10));
  194. m = glm::column(m, 3, glm::vec3(12, 13, 14));
  195. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec3( 0, 1, 2), glm::epsilon<float>())) ? 0 : 1;
  196. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec3( 4, 5, 6), glm::epsilon<float>())) ? 0 : 1;
  197. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec3( 8, 9, 10), glm::epsilon<float>())) ? 0 : 1;
  198. Error += glm::all(glm::equal(glm::column(m, 3), glm::vec3(12, 13, 14), glm::epsilon<float>())) ? 0 : 1;
  199. return Error;
  200. }
  201. int test_mat4x4_row_set()
  202. {
  203. int Error = 0;
  204. glm::mat4 m(1);
  205. m = glm::row(m, 0, glm::vec4( 0, 1, 2, 3));
  206. m = glm::row(m, 1, glm::vec4( 4, 5, 6, 7));
  207. m = glm::row(m, 2, glm::vec4( 8, 9, 10, 11));
  208. m = glm::row(m, 3, glm::vec4(12, 13, 14, 15));
  209. Error += glm::all(glm::equal(glm::row(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  210. Error += glm::all(glm::equal(glm::row(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  211. Error += glm::all(glm::equal(glm::row(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
  212. Error += glm::all(glm::equal(glm::row(m, 3), glm::vec4(12, 13, 14, 15), glm::epsilon<float>())) ? 0 : 1;
  213. return Error;
  214. }
  215. int test_mat4x4_col_set()
  216. {
  217. int Error = 0;
  218. glm::mat4 m(1);
  219. m = glm::column(m, 0, glm::vec4( 0, 1, 2, 3));
  220. m = glm::column(m, 1, glm::vec4( 4, 5, 6, 7));
  221. m = glm::column(m, 2, glm::vec4( 8, 9, 10, 11));
  222. m = glm::column(m, 3, glm::vec4(12, 13, 14, 15));
  223. Error += glm::all(glm::equal(glm::column(m, 0), glm::vec4( 0, 1, 2, 3), glm::epsilon<float>())) ? 0 : 1;
  224. Error += glm::all(glm::equal(glm::column(m, 1), glm::vec4( 4, 5, 6, 7), glm::epsilon<float>())) ? 0 : 1;
  225. Error += glm::all(glm::equal(glm::column(m, 2), glm::vec4( 8, 9, 10, 11), glm::epsilon<float>())) ? 0 : 1;
  226. Error += glm::all(glm::equal(glm::column(m, 3), glm::vec4(12, 13, 14, 15), glm::epsilon<float>())) ? 0 : 1;
  227. return Error;
  228. }
  229. int test_mat4x4_row_get()
  230. {
  231. int Error = 0;
  232. glm::mat4 m(1);
  233. glm::vec4 A = glm::row(m, 0);
  234. Error += glm::all(glm::equal(A, glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
  235. glm::vec4 B = glm::row(m, 1);
  236. Error += glm::all(glm::equal(B, glm::vec4(0, 1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
  237. glm::vec4 C = glm::row(m, 2);
  238. Error += glm::all(glm::equal(C, glm::vec4(0, 0, 1, 0), glm::epsilon<float>())) ? 0 : 1;
  239. glm::vec4 D = glm::row(m, 3);
  240. Error += glm::all(glm::equal(D, glm::vec4(0, 0, 0, 1), glm::epsilon<float>())) ? 0 : 1;
  241. return Error;
  242. }
  243. int test_mat4x4_col_get()
  244. {
  245. int Error = 0;
  246. glm::mat4 m(1);
  247. glm::vec4 A = glm::column(m, 0);
  248. Error += glm::all(glm::equal(A, glm::vec4(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
  249. glm::vec4 B = glm::column(m, 1);
  250. Error += glm::all(glm::equal(B, glm::vec4(0, 1, 0, 0), glm::epsilon<float>())) ? 0 : 1;
  251. glm::vec4 C = glm::column(m, 2);
  252. Error += glm::all(glm::equal(C, glm::vec4(0, 0, 1, 0), glm::epsilon<float>())) ? 0 : 1;
  253. glm::vec4 D = glm::column(m, 3);
  254. Error += glm::all(glm::equal(D, glm::vec4(0, 0, 0, 1), glm::epsilon<float>())) ? 0 : 1;
  255. return Error;
  256. }
  257. int main()
  258. {
  259. int Error = 0;
  260. Error += test_mat2x2_row_set();
  261. Error += test_mat2x2_col_set();
  262. Error += test_mat2x3_row_set();
  263. Error += test_mat2x3_col_set();
  264. Error += test_mat2x4_row_set();
  265. Error += test_mat2x4_col_set();
  266. Error += test_mat3x2_row_set();
  267. Error += test_mat3x2_col_set();
  268. Error += test_mat3x3_row_set();
  269. Error += test_mat3x3_col_set();
  270. Error += test_mat3x4_row_set();
  271. Error += test_mat3x4_col_set();
  272. Error += test_mat4x2_row_set();
  273. Error += test_mat4x2_col_set();
  274. Error += test_mat4x3_row_set();
  275. Error += test_mat4x3_col_set();
  276. Error += test_mat4x4_row_set();
  277. Error += test_mat4x4_col_set();
  278. Error += test_mat4x4_row_get();
  279. Error += test_mat4x4_col_get();
  280. return Error;
  281. }