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.

244 lines
6.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/func_trigonometric.inl
  25. /// @date 2008-08-03 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm
  29. {
  30. // radians
  31. template <typename genType>
  32. GLM_FUNC_QUALIFIER genType radians
  33. (
  34. genType const & degrees
  35. )
  36. {
  37. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'radians' only accept floating-point input");
  38. genType const pi = genType(3.1415926535897932384626433832795);
  39. return degrees * (pi / genType(180));
  40. }
  41. VECTORIZE_VEC(radians)
  42. // degrees
  43. template <typename genType>
  44. GLM_FUNC_QUALIFIER genType degrees
  45. (
  46. genType const & radians
  47. )
  48. {
  49. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'degrees' only accept floating-point input");
  50. const genType pi = genType(3.1415926535897932384626433832795);
  51. return radians * (genType(180) / pi);
  52. }
  53. VECTORIZE_VEC(degrees)
  54. // sin
  55. template <typename genType>
  56. GLM_FUNC_QUALIFIER genType sin
  57. (
  58. genType const & angle
  59. )
  60. {
  61. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input");
  62. return genType(::std::sin(angle));
  63. }
  64. VECTORIZE_VEC(sin)
  65. // cos
  66. template <typename genType>
  67. GLM_FUNC_QUALIFIER genType cos(genType const & angle)
  68. {
  69. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cos' only accept floating-point input");
  70. return genType(::std::cos(angle));
  71. }
  72. VECTORIZE_VEC(cos)
  73. // tan
  74. template <typename genType>
  75. GLM_FUNC_QUALIFIER genType tan
  76. (
  77. genType const & angle
  78. )
  79. {
  80. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tan' only accept floating-point input");
  81. return genType(::std::tan(angle));
  82. }
  83. VECTORIZE_VEC(tan)
  84. // asin
  85. template <typename genType>
  86. GLM_FUNC_QUALIFIER genType asin
  87. (
  88. genType const & x
  89. )
  90. {
  91. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asin' only accept floating-point input");
  92. return genType(::std::asin(x));
  93. }
  94. VECTORIZE_VEC(asin)
  95. // acos
  96. template <typename genType>
  97. GLM_FUNC_QUALIFIER genType acos
  98. (
  99. genType const & x
  100. )
  101. {
  102. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acos' only accept floating-point input");
  103. return genType(::std::acos(x));
  104. }
  105. VECTORIZE_VEC(acos)
  106. // atan
  107. template <typename genType>
  108. GLM_FUNC_QUALIFIER genType atan
  109. (
  110. genType const & y,
  111. genType const & x
  112. )
  113. {
  114. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
  115. return genType(::std::atan2(y, x));
  116. }
  117. VECTORIZE_VEC_VEC(atan)
  118. template <typename genType>
  119. GLM_FUNC_QUALIFIER genType atan
  120. (
  121. genType const & x
  122. )
  123. {
  124. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
  125. return genType(::std::atan(x));
  126. }
  127. VECTORIZE_VEC(atan)
  128. // sinh
  129. template <typename genType>
  130. GLM_FUNC_QUALIFIER genType sinh
  131. (
  132. genType const & angle
  133. )
  134. {
  135. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sinh' only accept floating-point input");
  136. return genType(std::sinh(angle));
  137. }
  138. VECTORIZE_VEC(sinh)
  139. // cosh
  140. template <typename genType>
  141. GLM_FUNC_QUALIFIER genType cosh
  142. (
  143. genType const & angle
  144. )
  145. {
  146. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cosh' only accept floating-point input");
  147. return genType(std::cosh(angle));
  148. }
  149. VECTORIZE_VEC(cosh)
  150. // tanh
  151. template <typename genType>
  152. GLM_FUNC_QUALIFIER genType tanh
  153. (
  154. genType const & angle
  155. )
  156. {
  157. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tanh' only accept floating-point input");
  158. return genType(std::tanh(angle));
  159. }
  160. VECTORIZE_VEC(tanh)
  161. // asinh
  162. template <typename genType>
  163. GLM_FUNC_QUALIFIER genType asinh
  164. (
  165. genType const & x
  166. )
  167. {
  168. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asinh' only accept floating-point input");
  169. return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x));
  170. }
  171. VECTORIZE_VEC(asinh)
  172. // acosh
  173. template <typename genType>
  174. GLM_FUNC_QUALIFIER genType acosh
  175. (
  176. genType const & x
  177. )
  178. {
  179. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acosh' only accept floating-point input");
  180. if(x < genType(1))
  181. return genType(0);
  182. return log(x + sqrt(x * x - genType(1)));
  183. }
  184. VECTORIZE_VEC(acosh)
  185. // atanh
  186. template <typename genType>
  187. GLM_FUNC_QUALIFIER genType atanh
  188. (
  189. genType const & x
  190. )
  191. {
  192. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atanh' only accept floating-point input");
  193. if(abs(x) >= genType(1))
  194. return 0;
  195. return genType(0.5) * log((genType(1) + x) / (genType(1) - x));
  196. }
  197. VECTORIZE_VEC(atanh)
  198. }//namespace glm