Rev Author Line No. Line
23 ovan 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 /// Restrictions:
16 /// By making use of the Software for military purposes, you choose to make
17 /// a Bunny unhappy.
18 ///
19 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 /// THE SOFTWARE.
26 ///
27 /// @ref gtx_rotate_normalized_axis
28 /// @file glm/gtx/rotate_normalized_axis.inl
29 /// @date 2012-12-13 / 2012-12-13
30 /// @author Christophe Riccio
31 ///////////////////////////////////////////////////////////////////////////////////
32  
33 namespace glm
34 {
35 template <typename T, precision P>
36 GLM_FUNC_QUALIFIER tmat4x4<T, P> rotateNormalizedAxis
37 (
38 tmat4x4<T, P> const & m,
39 T const & angle,
40 tvec3<T, P> const & v
41 )
42 {
43 T const a = angle;
44 T const c = cos(a);
45 T const s = sin(a);
46  
47 tvec3<T, P> const axis(v);
48  
49 tvec3<T, P> const temp((static_cast<T>(1) - c) * axis);
50  
51 tmat4x4<T, P> Rotate(uninitialize);
52 Rotate[0][0] = c + temp[0] * axis[0];
53 Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
54 Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1];
55  
56 Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2];
57 Rotate[1][1] = c + temp[1] * axis[1];
58 Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0];
59  
60 Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1];
61 Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0];
62 Rotate[2][2] = c + temp[2] * axis[2];
63  
64 tmat4x4<T, P> Result(uninitialize);
65 Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
66 Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
67 Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
68 Result[3] = m[3];
69 return Result;
70 }
71  
72 template <typename T, precision P>
73 GLM_FUNC_QUALIFIER tquat<T, P> rotateNormalizedAxis
74 (
75 tquat<T, P> const & q,
76 T const & angle,
77 tvec3<T, P> const & v
78 )
79 {
80 tvec3<T, P> const Tmp(v);
81  
82 T const AngleRad(angle);
83 T const Sin = sin(AngleRad * T(0.5));
84  
85 return q * tquat<T, P>(cos(AngleRad * static_cast<T>(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
86 //return gtc::quaternion::cross(q, tquat<T, P>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
87 }
88 }//namespace glm