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.

154 lines
4.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-03-05
  5. // Updated : 2007-03-05
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/matrix_query.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Dependency:
  10. // - GLM core
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12. namespace glm
  13. {
  14. template<typename T>
  15. GLM_FUNC_QUALIFIER bool isNull
  16. (
  17. detail::tmat2x2<T> const & m,
  18. T const & epsilon)
  19. {
  20. bool result = true;
  21. for(int i = 0; result && i < 2 ; ++i)
  22. result = isNull(m[i], epsilon);
  23. return result;
  24. }
  25. template<typename T>
  26. GLM_FUNC_QUALIFIER bool isNull
  27. (
  28. detail::tmat3x3<T> const & m,
  29. T const & epsilon
  30. )
  31. {
  32. bool result = true;
  33. for(int i = 0; result && i < 3 ; ++i)
  34. result = isNull(m[i], epsilon);
  35. return result;
  36. }
  37. template<typename T>
  38. GLM_FUNC_QUALIFIER bool isNull
  39. (
  40. detail::tmat4x4<T> const & m,
  41. T const & epsilon
  42. )
  43. {
  44. bool result = true;
  45. for(int i = 0; result && i < 4 ; ++i)
  46. result = isNull(m[i], epsilon);
  47. return result;
  48. }
  49. template<typename genType>
  50. GLM_FUNC_QUALIFIER bool isIdentity
  51. (
  52. genType const & m,
  53. typename genType::value_type const & epsilon
  54. )
  55. {
  56. bool result = true;
  57. for(typename genType::size_type i = typename genType::size_type(0); result && i < genType::col_size(); ++i)
  58. {
  59. for(typename genType::size_type j = typename genType::size_type(0); result && j < i ; ++j)
  60. result = abs(m[i][j]) <= epsilon;
  61. if(result)
  62. result = abs(m[i][i] - typename genType::value_type(1)) <= epsilon;
  63. for(typename genType::size_type j = i + typename genType::size_type(1); result && j < genType::row_size(); ++j)
  64. result = abs(m[i][j]) <= epsilon;
  65. }
  66. return result;
  67. }
  68. template<typename genType>
  69. GLM_FUNC_QUALIFIER bool isNormalized
  70. (
  71. detail::tmat2x2<genType> const & m,
  72. genType const & epsilon
  73. )
  74. {
  75. bool result(true);
  76. for(typename detail::tmat2x2<genType>::size_type i(0); result && i < m.length(); ++i)
  77. result = isNormalized(m[i], epsilon);
  78. for(typename detail::tmat2x2<genType>::size_type i(0); result && i < m.length(); ++i)
  79. {
  80. typename detail::tmat2x2<genType>::col_type v;
  81. for(typename detail::tmat2x2<genType>::size_type j(0); j < m.length(); ++j)
  82. v[j] = m[j][i];
  83. result = isNormalized(v, epsilon);
  84. }
  85. return result;
  86. }
  87. template<typename genType>
  88. GLM_FUNC_QUALIFIER bool isNormalized
  89. (
  90. detail::tmat3x3<genType> const & m,
  91. genType const & epsilon
  92. )
  93. {
  94. bool result(true);
  95. for(typename detail::tmat3x3<genType>::size_type i(0); result && i < m.length(); ++i)
  96. result = isNormalized(m[i], epsilon);
  97. for(typename detail::tmat3x3<genType>::size_type i(0); result && i < m.length(); ++i)
  98. {
  99. typename detail::tmat3x3<genType>::col_type v;
  100. for(typename detail::tmat3x3<genType>::size_type j(0); j < m.length(); ++j)
  101. v[j] = m[j][i];
  102. result = isNormalized(v, epsilon);
  103. }
  104. return result;
  105. }
  106. template<typename genType>
  107. GLM_FUNC_QUALIFIER bool isNormalized
  108. (
  109. detail::tmat4x4<genType> const & m,
  110. genType const & epsilon
  111. )
  112. {
  113. bool result(true);
  114. for(typename detail::tmat4x4<genType>::size_type i(0); result && i < m.length(); ++i)
  115. result = isNormalized(m[i], epsilon);
  116. for(typename detail::tmat4x4<genType>::size_type i(0); result && i < m.length(); ++i)
  117. {
  118. typename detail::tmat4x4<genType>::col_type v;
  119. for(typename detail::tmat4x4<genType>::size_type j(0); j < m.length(); ++j)
  120. v[j] = m[j][i];
  121. result = isNormalized(v, epsilon);
  122. }
  123. return result;
  124. }
  125. template<typename genType, template <typename> class matType>
  126. GLM_FUNC_QUALIFIER bool isOrthogonal
  127. (
  128. matType<genType> const & m,
  129. genType const & epsilon
  130. )
  131. {
  132. bool result(true);
  133. for(typename matType<genType>::size_type i(0); result && i < m.length() - 1; ++i)
  134. for(typename matType<genType>::size_type j(i + 1); result && j < m.length(); ++j)
  135. result = areOrthogonal(m[i], m[j], epsilon);
  136. if(result)
  137. {
  138. matType<genType> tmp = transpose(m);
  139. for(typename matType<genType>::size_type i(0); result && i < m.length() - 1 ; ++i)
  140. for(typename matType<genType>::size_type j(i + 1); result && j < m.length(); ++j)
  141. result = areOrthogonal(tmp[i], tmp[j], epsilon);
  142. }
  143. return result;
  144. }
  145. }//namespace glm