1/// @ref gtx_rotate_normalized_axis 2/// @file glm/gtx/rotate_normalized_axis.inl 3 4namespace glm 5{ 6 template <typename T, precision P> 7 GLM_FUNC_QUALIFIER tmat4x4<T, P> rotateNormalizedAxis 8 ( 9 tmat4x4<T, P> const & m, 10 T const & angle, 11 tvec3<T, P> const & v 12 ) 13 { 14 T const a = angle; 15 T const c = cos(a); 16 T const s = sin(a); 17 18 tvec3<T, P> const axis(v); 19 20 tvec3<T, P> const temp((static_cast<T>(1) - c) * axis); 21 22 tmat4x4<T, P> Rotate(uninitialize); 23 Rotate[0][0] = c + temp[0] * axis[0]; 24 Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2]; 25 Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1]; 26 27 Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2]; 28 Rotate[1][1] = c + temp[1] * axis[1]; 29 Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0]; 30 31 Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1]; 32 Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0]; 33 Rotate[2][2] = c + temp[2] * axis[2]; 34 35 tmat4x4<T, P> Result(uninitialize); 36 Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]; 37 Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2]; 38 Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2]; 39 Result[3] = m[3]; 40 return Result; 41 } 42 43 template <typename T, precision P> 44 GLM_FUNC_QUALIFIER tquat<T, P> rotateNormalizedAxis 45 ( 46 tquat<T, P> const & q, 47 T const & angle, 48 tvec3<T, P> const & v 49 ) 50 { 51 tvec3<T, P> const Tmp(v); 52 53 T const AngleRad(angle); 54 T const Sin = sin(AngleRad * T(0.5)); 55 56 return q * tquat<T, P>(cos(AngleRad * static_cast<T>(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin); 57 //return gtc::quaternion::cross(q, tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin)); 58 } 59}//namespace glm 60