core_func_matrix.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-01-15
  5. // Updated : 2012-05-02
  6. // Licence : This source is under MIT licence
  7. // File : test/core/func_matrix.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/core/func_matrix.hpp>
  10. int test_matrixCompMult()
  11. {
  12. int Error(0);
  13. {
  14. glm::mat2 m(0, 1, 2, 3);
  15. glm::mat2 n = glm::matrixCompMult(m, m);
  16. Error += n == glm::mat2(0, 1, 4, 9) ? 0 : 1;
  17. }
  18. {
  19. glm::mat2x3 m(0, 1, 2, 3, 4, 5);
  20. glm::mat2x3 n = glm::matrixCompMult(m, m);
  21. Error += n == glm::mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1;
  22. }
  23. {
  24. glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
  25. glm::mat2x4 n = glm::matrixCompMult(m, m);
  26. Error += n == glm::mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
  27. }
  28. {
  29. glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
  30. glm::mat3 n = glm::matrixCompMult(m, m);
  31. Error += n == glm::mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1;
  32. }
  33. {
  34. glm::mat3x2 m(0, 1, 2, 3, 4, 5);
  35. glm::mat3x2 n = glm::matrixCompMult(m, m);
  36. Error += n == glm::mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1;
  37. }
  38. {
  39. glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  40. glm::mat3x4 n = glm::matrixCompMult(m, m);
  41. Error += n == glm::mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
  42. }
  43. {
  44. glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  45. glm::mat4 n = glm::matrixCompMult(m, m);
  46. Error += n == glm::mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1;
  47. }
  48. {
  49. glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
  50. glm::mat4x2 n = glm::matrixCompMult(m, m);
  51. Error += n == glm::mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
  52. }
  53. {
  54. glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  55. glm::mat4x3 n = glm::matrixCompMult(m, m);
  56. Error += n == glm::mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
  57. }
  58. return Error;
  59. }
  60. int test_outerProduct()
  61. {
  62. return 0;
  63. }
  64. int test_transpose()
  65. {
  66. int Error(0);
  67. {
  68. glm::mat2 m(0, 1, 2, 3);
  69. glm::mat2 t = glm::transpose(m);
  70. Error += t == glm::mat2(0, 2, 1, 3) ? 0 : 1;
  71. }
  72. {
  73. glm::mat2x3 m(0, 1, 2, 3, 4, 5);
  74. glm::mat3x2 t = glm::transpose(m);
  75. Error += t == glm::mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
  76. }
  77. {
  78. glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
  79. glm::mat4x2 t = glm::transpose(m);
  80. Error += t == glm::mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
  81. }
  82. {
  83. glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
  84. glm::mat3 t = glm::transpose(m);
  85. Error += t == glm::mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
  86. }
  87. {
  88. glm::mat3x2 m(0, 1, 2, 3, 4, 5);
  89. glm::mat2x3 t = glm::transpose(m);
  90. Error += t == glm::mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
  91. }
  92. {
  93. glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  94. glm::mat4x3 t = glm::transpose(m);
  95. Error += t == glm::mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
  96. }
  97. {
  98. glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  99. glm::mat4 t = glm::transpose(m);
  100. Error += t == glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
  101. }
  102. {
  103. glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
  104. glm::mat2x4 t = glm::transpose(m);
  105. Error += t == glm::mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
  106. }
  107. {
  108. glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  109. glm::mat3x4 t = glm::transpose(m);
  110. Error += t == glm::mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
  111. }
  112. return Error;
  113. }
  114. int test_determinant()
  115. {
  116. return 0;
  117. }
  118. int test_inverse()
  119. {
  120. int Failed(0);
  121. glm::mat4x4 A4x4(
  122. glm::vec4(1, 0, 1, 0),
  123. glm::vec4(0, 1, 0, 0),
  124. glm::vec4(0, 0, 1, 0),
  125. glm::vec4(0, 0, 0, 1));
  126. glm::mat4x4 B4x4 = glm::inverse(A4x4);
  127. glm::mat4x4 I4x4 = A4x4 * B4x4;
  128. Failed += I4x4 == glm::mat4x4(1) ? 0 : 1;
  129. glm::mat3x3 A3x3(
  130. glm::vec3(1, 0, 1),
  131. glm::vec3(0, 1, 0),
  132. glm::vec3(0, 0, 1));
  133. glm::mat3x3 B3x3 = glm::inverse(A3x3);
  134. glm::mat3x3 I3x3 = A3x3 * B3x3;
  135. Failed += I3x3 == glm::mat3x3(1) ? 0 : 1;
  136. glm::mat2x2 A2x2(
  137. glm::vec2(1, 1),
  138. glm::vec2(0, 1));
  139. glm::mat2x2 B2x2 = glm::inverse(A2x2);
  140. glm::mat2x2 I2x2 = A2x2 * B2x2;
  141. Failed += I2x2 == glm::mat2x2(1) ? 0 : 1;
  142. return Failed;
  143. }
  144. int main()
  145. {
  146. int Failed = 0;
  147. Failed += test_matrixCompMult();
  148. Failed += test_outerProduct();
  149. Failed += test_transpose();
  150. Failed += test_determinant();
  151. Failed += test_inverse();
  152. return Failed;
  153. }