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.

156 lines
2.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2005-12-21
  5. // Updated : 2008-07-24
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/norm.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename T>
  12. GLM_FUNC_QUALIFIER T length2
  13. (
  14. T const & x
  15. )
  16. {
  17. return x * x;
  18. }
  19. template <typename T>
  20. GLM_FUNC_QUALIFIER T length2
  21. (
  22. detail::tvec2<T> const & x
  23. )
  24. {
  25. return dot(x, x);
  26. }
  27. template <typename T>
  28. GLM_FUNC_QUALIFIER T length2
  29. (
  30. detail::tvec3<T> const & x
  31. )
  32. {
  33. return dot(x, x);
  34. }
  35. template <typename T>
  36. GLM_FUNC_QUALIFIER T length2
  37. (
  38. detail::tvec4<T> const & x
  39. )
  40. {
  41. return dot(x, x);
  42. }
  43. template <typename T>
  44. GLM_FUNC_QUALIFIER T length2
  45. (
  46. detail::tquat<T> const & q
  47. )
  48. {
  49. return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
  50. }
  51. template <typename T>
  52. GLM_FUNC_QUALIFIER T distance2
  53. (
  54. T const & p0,
  55. T const & p1
  56. )
  57. {
  58. return length2(p1 - p0);
  59. }
  60. template <typename T>
  61. GLM_FUNC_QUALIFIER T distance2
  62. (
  63. detail::tvec2<T> const & p0,
  64. detail::tvec2<T> const & p1
  65. )
  66. {
  67. return length2(p1 - p0);
  68. }
  69. template <typename T>
  70. GLM_FUNC_QUALIFIER T distance2
  71. (
  72. detail::tvec3<T> const & p0,
  73. detail::tvec3<T> const & p1
  74. )
  75. {
  76. return length2(p1 - p0);
  77. }
  78. template <typename T>
  79. GLM_FUNC_QUALIFIER T distance2
  80. (
  81. detail::tvec4<T> const & p0,
  82. detail::tvec4<T> const & p1
  83. )
  84. {
  85. return length2(p1 - p0);
  86. }
  87. template <typename T>
  88. GLM_FUNC_QUALIFIER T l1Norm
  89. (
  90. detail::tvec3<T> const & a,
  91. detail::tvec3<T> const & b
  92. )
  93. {
  94. return abs(b.x - a.x) + abs(b.y - a.y) + abs(b.z - a.z);
  95. }
  96. template <typename T>
  97. GLM_FUNC_QUALIFIER T l1Norm
  98. (
  99. detail::tvec3<T> const & v
  100. )
  101. {
  102. return abs(v.x) + abs(v.y) + abs(v.z);
  103. }
  104. template <typename T>
  105. GLM_FUNC_QUALIFIER T l2Norm
  106. (
  107. detail::tvec3<T> const & a,
  108. detail::tvec3<T> const & b
  109. )
  110. {
  111. return length(b - a);
  112. }
  113. template <typename T>
  114. GLM_FUNC_QUALIFIER T l2Norm
  115. (
  116. detail::tvec3<T> const & v
  117. )
  118. {
  119. return length(v);
  120. }
  121. template <typename T>
  122. GLM_FUNC_QUALIFIER T lxNorm
  123. (
  124. detail::tvec3<T> const & x,
  125. detail::tvec3<T> const & y,
  126. unsigned int Depth
  127. )
  128. {
  129. return pow(pow(y.x - x.x, T(Depth)) + pow(y.y - x.y, T(Depth)) + pow(y.z - x.z, T(Depth)), T(1) / T(Depth));
  130. }
  131. template <typename T>
  132. GLM_FUNC_QUALIFIER T lxNorm
  133. (
  134. detail::tvec3<T> const & v,
  135. unsigned int Depth
  136. )
  137. {
  138. return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth));
  139. }
  140. }//namespace glm