core_func_matrix.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2012 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/glm.hpp>
  10. int test_matrixCompMult()
  11. {
  12. return 0;
  13. }
  14. int test_outerProduct()
  15. {
  16. return 0;
  17. }
  18. int test_transpose()
  19. {
  20. int Error(0);
  21. {
  22. glm::mat2 m(0, 1, 2, 3);
  23. glm::mat2 t = glm::transpose(m);
  24. Error += t == glm::mat2(0, 2, 1, 3) ? 0 : 1;
  25. }
  26. {
  27. glm::mat2x3 m(0, 1, 2, 3, 4, 5);
  28. glm::mat3x2 t = glm::transpose(m);
  29. Error += t == glm::mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
  30. }
  31. {
  32. glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
  33. glm::mat4x2 t = glm::transpose(m);
  34. Error += t == glm::mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
  35. }
  36. {
  37. glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
  38. glm::mat3 t = glm::transpose(m);
  39. Error += t == glm::mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
  40. }
  41. {
  42. glm::mat3x2 m(0, 1, 2, 3, 4, 5);
  43. glm::mat2x3 t = glm::transpose(m);
  44. Error += t == glm::mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
  45. }
  46. {
  47. glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  48. glm::mat4x3 t = glm::transpose(m);
  49. Error += t == glm::mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
  50. }
  51. {
  52. glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  53. glm::mat4 t = glm::transpose(m);
  54. Error += t == glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
  55. }
  56. {
  57. glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
  58. glm::mat2x4 t = glm::transpose(m);
  59. Error += t == glm::mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
  60. }
  61. {
  62. glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  63. glm::mat3x4 t = glm::transpose(m);
  64. Error += t == glm::mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
  65. }
  66. return Error;
  67. }
  68. int test_determinant()
  69. {
  70. return 0;
  71. }
  72. int test_inverse()
  73. {
  74. int Failed(0);
  75. glm::mat4x4 A4x4(
  76. glm::vec4(1, 0, 1, 0),
  77. glm::vec4(0, 1, 0, 0),
  78. glm::vec4(0, 0, 1, 0),
  79. glm::vec4(0, 0, 0, 1));
  80. glm::mat4x4 B4x4 = glm::inverse(A4x4);
  81. glm::mat4x4 I4x4 = A4x4 * B4x4;
  82. Failed += I4x4 == glm::mat4x4(1) ? 0 : 1;
  83. glm::mat3x3 A3x3(
  84. glm::vec3(1, 0, 1),
  85. glm::vec3(0, 1, 0),
  86. glm::vec3(0, 0, 1));
  87. glm::mat3x3 B3x3 = glm::inverse(A3x3);
  88. glm::mat3x3 I3x3 = A3x3 * B3x3;
  89. Failed += I3x3 == glm::mat3x3(1) ? 0 : 1;
  90. glm::mat2x2 A2x2(
  91. glm::vec2(1, 1),
  92. glm::vec2(0, 1));
  93. glm::mat2x2 B2x2 = glm::inverse(A2x2);
  94. glm::mat2x2 I2x2 = A2x2 * B2x2;
  95. Failed += I2x2 == glm::mat2x2(1) ? 0 : 1;
  96. return Failed;
  97. }
  98. int main()
  99. {
  100. int Failed = 0;
  101. Failed += test_matrixCompMult();
  102. Failed += test_outerProduct();
  103. Failed += test_transpose();
  104. Failed += test_determinant();
  105. Failed += test_inverse();
  106. return Failed;
  107. }