9
3

matrix_query.inl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /// @ref gtx_matrix_query
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER bool isNull(mat<2, 2, T, Q> const& m, T const& epsilon)
  6. {
  7. bool result = true;
  8. for(length_t i = 0; result && i < m.length() ; ++i)
  9. result = isNull(m[i], epsilon);
  10. return result;
  11. }
  12. template<typename T, qualifier Q>
  13. GLM_FUNC_QUALIFIER bool isNull(mat<3, 3, T, Q> const& m, T const& epsilon)
  14. {
  15. bool result = true;
  16. for(length_t i = 0; result && i < m.length() ; ++i)
  17. result = isNull(m[i], epsilon);
  18. return result;
  19. }
  20. template<typename T, qualifier Q>
  21. GLM_FUNC_QUALIFIER bool isNull(mat<4, 4, T, Q> const& m, T const& epsilon)
  22. {
  23. bool result = true;
  24. for(length_t i = 0; result && i < m.length() ; ++i)
  25. result = isNull(m[i], epsilon);
  26. return result;
  27. }
  28. template<length_t C, length_t R, typename T, qualifier Q>
  29. GLM_FUNC_QUALIFIER bool isIdentity(mat<C, R, T, Q> const& m, T const& epsilon)
  30. {
  31. bool result = true;
  32. for(length_t i = 0; result && i < m[0].length() ; ++i)
  33. {
  34. for(length_t j = 0; result && j < i ; ++j)
  35. result = abs(m[i][j]) <= epsilon;
  36. if(result)
  37. result = abs(m[i][i] - 1) <= epsilon;
  38. for(length_t j = i + 1; result && j < m.length(); ++j)
  39. result = abs(m[i][j]) <= epsilon;
  40. }
  41. return result;
  42. }
  43. template<typename T, qualifier Q>
  44. GLM_FUNC_QUALIFIER bool isNormalized(mat<2, 2, T, Q> const& m, T const& epsilon)
  45. {
  46. bool result(true);
  47. for(length_t i = 0; result && i < m.length(); ++i)
  48. result = isNormalized(m[i], epsilon);
  49. for(length_t i = 0; result && i < m.length(); ++i)
  50. {
  51. typename mat<2, 2, T, Q>::col_type v;
  52. for(length_t j = 0; j < m.length(); ++j)
  53. v[j] = m[j][i];
  54. result = isNormalized(v, epsilon);
  55. }
  56. return result;
  57. }
  58. template<typename T, qualifier Q>
  59. GLM_FUNC_QUALIFIER bool isNormalized(mat<3, 3, T, Q> const& m, T const& epsilon)
  60. {
  61. bool result(true);
  62. for(length_t i = 0; result && i < m.length(); ++i)
  63. result = isNormalized(m[i], epsilon);
  64. for(length_t i = 0; result && i < m.length(); ++i)
  65. {
  66. typename mat<3, 3, T, Q>::col_type v;
  67. for(length_t j = 0; j < m.length(); ++j)
  68. v[j] = m[j][i];
  69. result = isNormalized(v, epsilon);
  70. }
  71. return result;
  72. }
  73. template<typename T, qualifier Q>
  74. GLM_FUNC_QUALIFIER bool isNormalized(mat<4, 4, T, Q> const& m, T const& epsilon)
  75. {
  76. bool result(true);
  77. for(length_t i = 0; result && i < m.length(); ++i)
  78. result = isNormalized(m[i], epsilon);
  79. for(length_t i = 0; result && i < m.length(); ++i)
  80. {
  81. typename mat<4, 4, T, Q>::col_type v;
  82. for(length_t j = 0; j < m.length(); ++j)
  83. v[j] = m[j][i];
  84. result = isNormalized(v, epsilon);
  85. }
  86. return result;
  87. }
  88. template<length_t C, length_t R, typename T, qualifier Q>
  89. GLM_FUNC_QUALIFIER bool isOrthogonal(mat<C, R, T, Q> const& m, T const& epsilon)
  90. {
  91. bool result = true;
  92. for(length_t i(0); result && i < m.length() - 1; ++i)
  93. for(length_t j(i + 1); result && j < m.length(); ++j)
  94. result = areOrthogonal(m[i], m[j], epsilon);
  95. if(result)
  96. {
  97. mat<C, R, T, Q> tmp = transpose(m);
  98. for(length_t i(0); result && i < m.length() - 1 ; ++i)
  99. for(length_t j(i + 1); result && j < m.length(); ++j)
  100. result = areOrthogonal(tmp[i], tmp[j], epsilon);
  101. }
  102. return result;
  103. }
  104. }//namespace glm