1/////////////////////////////////////////////////////////////////////////////////// 2/// OpenGL Mathematics (glm.g-truc.net) 3/// 4/// Copyright (c) 2005 - 2012 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 gtx_rotate_normalized_axis 24/// @file glm/gtx/rotate_normalized_axis.inl 25/// @date 2012-12-13 / 2012-12-13 26/// @author Christophe Riccio 27/////////////////////////////////////////////////////////////////////////////////// 28 29namespace glm 30{ 31 template <typename T, precision P> 32 GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> rotateNormalizedAxis 33 ( 34 detail::tmat4x4<T, P> const & m, 35 T const & angle, 36 detail::tvec3<T, P> const & v 37 ) 38 { 39#ifdef GLM_FORCE_RADIANS 40 T a = angle; 41#else 42# pragma message("GLM: rotateNormalizedAxis function taking degrees as parameters is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.") 43 T a = radians(angle); 44#endif 45 T c = cos(a); 46 T s = sin(a); 47 48 detail::tvec3<T, P> axis = v; 49 50 detail::tvec3<T, P> temp = (T(1) - c) * axis; 51 52 detail::tmat4x4<T, P> Rotate(detail::tmat4x4<T, P>::_null); 53 Rotate[0][0] = c + temp[0] * axis[0]; 54 Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2]; 55 Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1]; 56 57 Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2]; 58 Rotate[1][1] = c + temp[1] * axis[1]; 59 Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0]; 60 61 Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1]; 62 Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0]; 63 Rotate[2][2] = c + temp[2] * axis[2]; 64 65 detail::tmat4x4<T, P> Result(detail::tmat4x4<T, P>::_null); 66 Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]; 67 Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2]; 68 Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2]; 69 Result[3] = m[3]; 70 return Result; 71 } 72 73 template <typename T, precision P> 74 GLM_FUNC_QUALIFIER detail::tquat<T, P> rotateNormalizedAxis 75 ( 76 detail::tquat<T, P> const & q, 77 T const & angle, 78 detail::tvec3<T, P> const & v 79 ) 80 { 81 detail::tvec3<T, P> Tmp = v; 82 83#ifdef GLM_FORCE_RADIANS 84 T const AngleRad(angle); 85#else 86# pragma message("GLM: rotateNormalizedAxis function taking degrees as parameters is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.") 87 T const AngleRad = radians(angle); 88#endif 89 T const Sin = sin(AngleRad * T(0.5)); 90 91 return q * detail::tquat<T, P>(cos(AngleRad * static_cast<T>(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin); 92 //return gtc::quaternion::cross(q, detail::tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin)); 93 } 94}//namespace glm 95