ext_matrix_common.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #include <glm/ext/matrix_common.hpp>
  2. #include <glm/ext/matrix_double4x4.hpp>
  3. #include <glm/ext/matrix_float4x4.hpp>
  4. #include <glm/ext/matrix_relational.hpp>
  5. #include <glm/ext/vector_bool4.hpp>
  6. #include <glm/ext/matrix_float4x3.hpp>
  7. static int test_mix()
  8. {
  9. int Error = 0;
  10. {
  11. glm::mat4 A(2);
  12. glm::mat4 B(4);
  13. glm::mat4 C = glm::mix(A, B, 0.5f);
  14. glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1);
  15. Error += glm::all(D) ? 0 : 1;
  16. }
  17. {
  18. glm::mat4 A(2);
  19. glm::mat4 B(4);
  20. glm::mat4 C = glm::mix(A, B, 0.5);
  21. glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1);
  22. Error += glm::all(D) ? 0 : 1;
  23. }
  24. {
  25. glm::dmat4 A(2);
  26. glm::dmat4 B(4);
  27. glm::dmat4 C = glm::mix(A, B, 0.5);
  28. glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1);
  29. Error += glm::all(D) ? 0 : 1;
  30. }
  31. {
  32. glm::dmat4 A(2);
  33. glm::dmat4 B(4);
  34. glm::dmat4 C = glm::mix(A, B, 0.5f);
  35. glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1);
  36. Error += glm::all(D) ? 0 : 1;
  37. }
  38. return Error;
  39. }
  40. static int test_abs()
  41. {
  42. int Error = 0;
  43. // -------------------- //
  44. // glm::mat4 variants : //
  45. // -------------------- //
  46. {
  47. glm::mat4 A(
  48. 3.0f, 1.0f, 5.2f, 4.9f,
  49. 1.4f, 0.5f, 9.3f, 3.7f,
  50. 6.8f, 8.4f, 4.3f, 3.9f,
  51. 5.6f, 7.2f, 1.1f, 4.4f
  52. );
  53. glm::mat4 B(
  54. 1.0,-1.0, 1.0, 1.0,
  55. -1.0, 1.0, 1.0,-1.0,
  56. 1.0,-1.0,-1.0,-1.0,
  57. -1.0,-1.0, 1.0, 1.0
  58. );
  59. glm::mat4 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  60. glm::mat4 D = glm::abs(C);
  61. glm::bvec4 const col1 = glm::equal(D[0], A[0], 0.001f);
  62. glm::bvec4 const col2 = glm::equal(D[1], A[1], 0.001f);
  63. glm::bvec4 const col3 = glm::equal(D[2], A[2], 0.001f);
  64. glm::bvec4 const col4 = glm::equal(D[3], A[3], 0.001f);
  65. Error += glm::all(glm::bvec4(glm::all(col1), glm::all(col2), glm::all(col3), glm::all(col4))) ? 0 : 1;
  66. }
  67. {
  68. glm::mat4x3 A(
  69. 3.0f, 1.0f, 5.2f,
  70. 4.9f, 1.4f, 0.5f,
  71. 9.3f, 3.7f, 6.8f,
  72. 8.4f, 4.3f, 3.9f
  73. );
  74. glm::mat4x3 B(
  75. 1.0,-1.0, 1.0,
  76. 1.0,-1.0, 1.0,
  77. 1.0,-1.0, 1.0,
  78. -1.0,-1.0,-1.0
  79. );
  80. glm::mat4x3 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  81. glm::mat4x3 D = glm::abs(C);
  82. glm::bvec3 const col1 = glm::equal(D[0], A[0], 0.001f);
  83. glm::bvec3 const col2 = glm::equal(D[1], A[1], 0.001f);
  84. glm::bvec3 const col3 = glm::equal(D[2], A[2], 0.001f);
  85. glm::bvec3 const col4 = glm::equal(D[3], A[3], 0.001f);
  86. Error += glm::all(glm::bvec4(glm::all(col1), glm::all(col2), glm::all(col3), glm::all(col4))) ? 0 : 1;
  87. }
  88. {
  89. glm::mat4x2 A(
  90. 3.0f, 1.0f,
  91. 1.4f, 0.5f,
  92. 6.8f, 8.4f,
  93. 5.6f, 7.2f
  94. );
  95. glm::mat4x2 B(
  96. 1.0,-1.0,
  97. -1.0, 1.0,
  98. 1.0,-1.0,
  99. -1.0,-1.0
  100. );
  101. glm::mat4x2 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  102. glm::mat4x2 D = glm::abs(C);
  103. glm::bvec2 const col1 = glm::equal(D[0], A[0], 0.001f);
  104. glm::bvec2 const col2 = glm::equal(D[1], A[1], 0.001f);
  105. glm::bvec2 const col3 = glm::equal(D[2], A[2], 0.001f);
  106. glm::bvec2 const col4 = glm::equal(D[3], A[3], 0.001f);
  107. Error += glm::all(glm::bvec4(glm::all(col1), glm::all(col2), glm::all(col3), glm::all(col4))) ? 0 : 1;
  108. }
  109. // -------------------- //
  110. // glm::mat3 variants : //
  111. // -------------------- //
  112. {
  113. glm::mat3x4 A(
  114. 3.0f, 1.0f, 5.2f, 4.9f,
  115. 1.4f, 0.5f, 9.3f, 3.7f,
  116. 6.8f, 8.4f, 4.3f, 3.9f
  117. );
  118. glm::mat3x4 B(
  119. 1.0,-1.0, 1.0, 1.0,
  120. -1.0, 1.0, 1.0,-1.0,
  121. 1.0,-1.0,-1.0,-1.0
  122. );
  123. glm::mat3x4 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  124. glm::mat3x4 D = glm::abs(C);
  125. glm::bvec4 const col1 = glm::equal(D[0], A[0], 0.001f);
  126. glm::bvec4 const col2 = glm::equal(D[1], A[1], 0.001f);
  127. glm::bvec4 const col3 = glm::equal(D[2], A[2], 0.001f);
  128. Error += glm::all(glm::bvec3(glm::all(col1), glm::all(col2), glm::all(col3))) ? 0 : 1;
  129. }
  130. {
  131. glm::mat3 A(
  132. 3.0f, 1.0f, 5.2f,
  133. 1.4f, 0.5f, 9.3f,
  134. 6.8f, 8.4f, 4.3f
  135. );
  136. glm::mat3 B(
  137. 1.0,-1.0, 1.0,
  138. -1.0, 1.0, 1.0,
  139. 1.0,-1.0,-1.0
  140. );
  141. glm::mat3 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  142. glm::mat3 D = glm::abs(C);
  143. glm::bvec3 const col1 = glm::equal(D[0], A[0], 0.001f);
  144. glm::bvec3 const col2 = glm::equal(D[1], A[1], 0.001f);
  145. glm::bvec3 const col3 = glm::equal(D[2], A[2], 0.001f);
  146. Error += glm::all(glm::bvec3(glm::all(col1), glm::all(col2), glm::all(col3))) ? 0 : 1;
  147. }
  148. {
  149. glm::mat3x2 A(
  150. 5.2f, 4.9f,
  151. 9.3f, 3.7f,
  152. 4.3f, 3.9f
  153. );
  154. glm::mat3x2 B(
  155. 1.0, 1.0,
  156. 1.0,-1.0,
  157. -1.0,-1.0
  158. );
  159. glm::mat3x2 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  160. glm::mat3x2 D = glm::abs(C);
  161. glm::bvec2 const col1 = glm::equal(D[0], A[0], 0.001f);
  162. glm::bvec2 const col2 = glm::equal(D[1], A[1], 0.001f);
  163. glm::bvec2 const col3 = glm::equal(D[2], A[2], 0.001f);
  164. Error += glm::all(glm::bvec3(glm::all(col1), glm::all(col2), glm::all(col3))) ? 0 : 1;
  165. }
  166. // -------------------- //
  167. // glm::mat2 variants : //
  168. // -------------------- //
  169. {
  170. glm::mat2x4 A(
  171. 3.0f, 1.0f, 5.2f, 4.9f,
  172. 5.6f, 7.2f, 1.1f, 4.4f
  173. );
  174. glm::mat2x4 B(
  175. 1.0,-1.0, 1.0, 1.0,
  176. -1.0,-1.0, 1.0, 1.0
  177. );
  178. glm::mat2x4 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  179. glm::mat2x4 D = glm::abs(C);
  180. glm::bvec4 const col1 = glm::equal(D[0], A[0], 0.001f);
  181. glm::bvec4 const col2 = glm::equal(D[1], A[1], 0.001f);
  182. Error += glm::all(glm::bvec2(glm::all(col1), glm::all(col2))) ? 0 : 1;
  183. }
  184. {
  185. glm::mat2x3 A(
  186. 3.0f, 1.0f, 5.2f,
  187. 8.4f, 4.3f, 3.9f
  188. );
  189. glm::mat2x3 B(
  190. 1.0,-1.0, 1.0,
  191. -1.0,-1.0,-1.0
  192. );
  193. glm::mat2x3 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  194. glm::mat2x3 D = glm::abs(C);
  195. glm::bvec3 const col1 = glm::equal(D[0], A[0], 0.001f);
  196. glm::bvec3 const col2 = glm::equal(D[1], A[1], 0.001f);
  197. Error += glm::all(glm::bvec2(glm::all(col1), glm::all(col2))) ? 0 : 1;
  198. }
  199. {
  200. glm::mat2 A(
  201. 3.0f, 1.0f,
  202. 5.6f, 7.2f
  203. );
  204. glm::mat2 B(
  205. 1.0,-1.0,
  206. -1.0,-1.0
  207. );
  208. glm::mat2 C = glm::matrixCompMult(A, B); // Not * to avoid matrix product.
  209. glm::mat2 D = glm::abs(C);
  210. glm::bvec2 const col1 = glm::equal(D[0], A[0], 0.001f);
  211. glm::bvec2 const col2 = glm::equal(D[1], A[1], 0.001f);
  212. Error += glm::all(glm::bvec2(glm::all(col1), glm::all(col2))) ? 0 : 1;
  213. }
  214. return Error;
  215. }
  216. int main()
  217. {
  218. int Error = 0;
  219. Error += test_mix();
  220. Error += test_abs();
  221. return Error;
  222. }