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.

164 lines
3.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-03-05
  5. // Updated : 2010-02-16
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/vector_query.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Dependency:
  10. // - GLM core
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12. #include <cassert>
  13. namespace glm
  14. {
  15. template <typename T>
  16. GLM_FUNC_QUALIFIER bool areCollinear
  17. (
  18. detail::tvec2<T> const & v0,
  19. detail::tvec2<T> const & v1,
  20. typename detail::tvec2<T>::value_type const & epsilon
  21. )
  22. {
  23. return length(cross(detail::tvec3<T>(v0, T(0)), detail::tvec3<T>(v1, T(0)))) < epsilon;
  24. }
  25. template <typename T>
  26. GLM_FUNC_QUALIFIER bool areCollinear
  27. (
  28. detail::tvec3<T> const & v0,
  29. detail::tvec3<T> const & v1,
  30. typename detail::tvec3<T>::value_type const & epsilon
  31. )
  32. {
  33. return length(cross(v0, v1)) < epsilon;
  34. }
  35. template <typename T>
  36. GLM_FUNC_QUALIFIER bool areCollinear
  37. (
  38. detail::tvec4<T> const & v0,
  39. detail::tvec4<T> const & v1,
  40. typename detail::tvec4<T>::value_type const & epsilon
  41. )
  42. {
  43. return length(cross(detail::tvec3<T>(v0), detail::tvec3<T>(v1))) < epsilon;
  44. }
  45. template <typename genType>
  46. GLM_FUNC_QUALIFIER bool areOrthogonal
  47. (
  48. genType const & v0,
  49. genType const & v1,
  50. typename genType::value_type const & epsilon
  51. )
  52. {
  53. return abs(dot(v0, v1)) <= max(
  54. typename genType::value_type(1),
  55. length(v0)) * max(
  56. typename genType::value_type(1),
  57. length(v1)) * epsilon;
  58. }
  59. template <typename genType, template <typename> class vecType>
  60. GLM_FUNC_QUALIFIER bool isNormalized
  61. (
  62. vecType<genType> const & v,
  63. genType const & epsilon
  64. )
  65. {
  66. return abs(length(v) - genType(1)) <= genType(2) * epsilon;
  67. }
  68. template <typename valType>
  69. GLM_FUNC_QUALIFIER bool isNull
  70. (
  71. detail::tvec2<valType> const & v,
  72. valType const & epsilon
  73. )
  74. {
  75. return length(v) <= epsilon;
  76. }
  77. template <typename valType>
  78. GLM_FUNC_QUALIFIER bool isNull
  79. (
  80. detail::tvec3<valType> const & v,
  81. valType const & epsilon
  82. )
  83. {
  84. return length(v) <= epsilon;
  85. }
  86. template <typename valType>
  87. GLM_FUNC_QUALIFIER bool isNull
  88. (
  89. detail::tvec4<valType> const & v,
  90. valType const & epsilon
  91. )
  92. {
  93. return length(v) <= epsilon;
  94. }
  95. template <typename T>
  96. GLM_FUNC_QUALIFIER bool isCompNull
  97. (
  98. T const & s,
  99. T const & epsilon
  100. )
  101. {
  102. return abs(s) < epsilon;
  103. }
  104. template <typename T>
  105. GLM_FUNC_QUALIFIER detail::tvec2<bool> isCompNull
  106. (
  107. detail::tvec2<T> const & v,
  108. T const & epsilon)
  109. {
  110. return detail::tvec2<bool>(
  111. (abs(v.x) < epsilon),
  112. (abs(v.y) < epsilon));
  113. }
  114. template <typename T>
  115. GLM_FUNC_QUALIFIER detail::tvec3<bool> isCompNull
  116. (
  117. detail::tvec3<T> const & v,
  118. T const & epsilon
  119. )
  120. {
  121. return detail::tvec3<bool>(
  122. abs(v.x) < epsilon,
  123. abs(v.y) < epsilon,
  124. abs(v.z) < epsilon);
  125. }
  126. template <typename T>
  127. GLM_FUNC_QUALIFIER detail::tvec4<bool> isCompNull
  128. (
  129. detail::tvec4<T> const & v,
  130. T const & epsilon
  131. )
  132. {
  133. return detail::tvec4<bool>(
  134. abs(v.x) < epsilon,
  135. abs(v.y) < epsilon,
  136. abs(v.z) < epsilon,
  137. abs(v.w) < epsilon);
  138. }
  139. template <typename genType>
  140. GLM_FUNC_QUALIFIER bool areOrthonormal
  141. (
  142. genType const & v0,
  143. genType const & v1,
  144. typename genType::value_type const & epsilon
  145. )
  146. {
  147. return isNormalized(v0, epsilon) && isNormalized(v1, epsilon) && (abs(dot(v0, v1)) <= epsilon);
  148. }
  149. }//namespace glm