1/////////////////////////////////////////////////////////////////////////////////// 2/// OpenGL Mathematics (glm.g-truc.net) 3/// 4/// Copyright (c) 2005 - 2014 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 29#include "_vectorize.hpp" 30#include <cmath> 31#include <limits> 32 33namespace glm 34{ 35 // radians 36 template <typename genType> 37 GLM_FUNC_QUALIFIER genType radians 38 ( 39 genType const & degrees 40 ) 41 { 42 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'radians' only accept floating-point input"); 43 44 return degrees * genType(0.01745329251994329576923690768489); 45 } 46 47 VECTORIZE_VEC(radians) 48 49 // degrees 50 template <typename genType> 51 GLM_FUNC_QUALIFIER genType degrees 52 ( 53 genType const & radians 54 ) 55 { 56 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'degrees' only accept floating-point input"); 57 58 return radians * genType(57.295779513082320876798154814105); 59 } 60 61 VECTORIZE_VEC(degrees) 62 63 // sin 64 template <typename genType> 65 GLM_FUNC_QUALIFIER genType sin 66 ( 67 genType const & angle 68 ) 69 { 70 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'sin' only accept floating-point input"); 71 72 return genType(::std::sin(angle)); 73 } 74 75 VECTORIZE_VEC(sin) 76 77 // cos 78 template <typename genType> 79 GLM_FUNC_QUALIFIER genType cos(genType const & angle) 80 { 81 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'cos' only accept floating-point input"); 82 83 return genType(::std::cos(angle)); 84 } 85 86 VECTORIZE_VEC(cos) 87 88 // tan 89 template <typename genType> 90 GLM_FUNC_QUALIFIER genType tan 91 ( 92 genType const & angle 93 ) 94 { 95 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'tan' only accept floating-point input"); 96 97 return genType(::std::tan(angle)); 98 } 99 100 VECTORIZE_VEC(tan) 101 102 // asin 103 template <typename genType> 104 GLM_FUNC_QUALIFIER genType asin 105 ( 106 genType const & x 107 ) 108 { 109 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'asin' only accept floating-point input"); 110 111 return genType(::std::asin(x)); 112 } 113 114 VECTORIZE_VEC(asin) 115 116 // acos 117 template <typename genType> 118 GLM_FUNC_QUALIFIER genType acos 119 ( 120 genType const & x 121 ) 122 { 123 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'acos' only accept floating-point input"); 124 125 return genType(::std::acos(x)); 126 } 127 128 VECTORIZE_VEC(acos) 129 130 // atan 131 template <typename genType> 132 GLM_FUNC_QUALIFIER genType atan 133 ( 134 genType const & y, 135 genType const & x 136 ) 137 { 138 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atan' only accept floating-point input"); 139 140 return genType(::std::atan2(y, x)); 141 } 142 143 VECTORIZE_VEC_VEC(atan) 144 145 template <typename genType> 146 GLM_FUNC_QUALIFIER genType atan 147 ( 148 genType const & x 149 ) 150 { 151 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atan' only accept floating-point input"); 152 153 return genType(::std::atan(x)); 154 } 155 156 VECTORIZE_VEC(atan) 157 158 // sinh 159 template <typename genType> 160 GLM_FUNC_QUALIFIER genType sinh 161 ( 162 genType const & angle 163 ) 164 { 165 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'sinh' only accept floating-point input"); 166 167 return genType(std::sinh(angle)); 168 } 169 170 VECTORIZE_VEC(sinh) 171 172 // cosh 173 template <typename genType> 174 GLM_FUNC_QUALIFIER genType cosh 175 ( 176 genType const & angle 177 ) 178 { 179 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'cosh' only accept floating-point input"); 180 181 return genType(std::cosh(angle)); 182 } 183 184 VECTORIZE_VEC(cosh) 185 186 // tanh 187 template <typename genType> 188 GLM_FUNC_QUALIFIER genType tanh 189 ( 190 genType const & angle 191 ) 192 { 193 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'tanh' only accept floating-point input"); 194 195 return genType(std::tanh(angle)); 196 } 197 198 VECTORIZE_VEC(tanh) 199 200 // asinh 201 template <typename genType> 202 GLM_FUNC_QUALIFIER genType asinh 203 ( 204 genType const & x 205 ) 206 { 207 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'asinh' only accept floating-point input"); 208 209 return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x)); 210 } 211 212 VECTORIZE_VEC(asinh) 213 214 // acosh 215 template <typename genType> 216 GLM_FUNC_QUALIFIER genType acosh 217 ( 218 genType const & x 219 ) 220 { 221 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'acosh' only accept floating-point input"); 222 223 if(x < genType(1)) 224 return genType(0); 225 return log(x + sqrt(x * x - genType(1))); 226 } 227 228 VECTORIZE_VEC(acosh) 229 230 // atanh 231 template <typename genType> 232 GLM_FUNC_QUALIFIER genType atanh 233 ( 234 genType const & x 235 ) 236 { 237 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atanh' only accept floating-point input"); 238 239 if(abs(x) >= genType(1)) 240 return 0; 241 return genType(0.5) * log((genType(1) + x) / (genType(1) - x)); 242 } 243 244 VECTORIZE_VEC(atanh) 245 246}//namespace glm 247