/src/ogre/OgreMain/src/OgreDualQuaternion.cpp
Line | Count | Source |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
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 | | */ |
28 | | |
29 | | /* dqconv.c |
30 | | |
31 | | Conversion routines between (regular quaternion, translation) and dual quaternion. |
32 | | |
33 | | Version 1.0.0, February 7th, 2007 |
34 | | |
35 | | Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights |
36 | | Reserved |
37 | | |
38 | | This software is provided 'as-is', without any express or implied |
39 | | warranty. In no event will the author(s) be held liable for any damages |
40 | | arising from the use of this software. |
41 | | |
42 | | Permission is granted to anyone to use this software for any purpose, |
43 | | including commercial applications, and to alter it and redistribute it |
44 | | freely, subject to the following restrictions: |
45 | | |
46 | | 1. The origin of this software must not be misrepresented; you must not |
47 | | claim that you wrote the original software. If you use this software |
48 | | in a product, an acknowledgment in the product documentation would be |
49 | | appreciated but is not required. |
50 | | 2. Altered source versions must be plainly marked as such, and must not be |
51 | | misrepresented as being the original software. |
52 | | 3. This notice may not be removed or altered from any source distribution. |
53 | | |
54 | | Author: Ladislav Kavan, kavanl@cs.tcd.ie |
55 | | |
56 | | */ |
57 | | |
58 | | #include "OgreStableHeaders.h" |
59 | | #include "OgreDualQuaternion.h" |
60 | | |
61 | | |
62 | | namespace Ogre { |
63 | | |
64 | | //Based on dqconv.c from http://isg.cs.tcd.ie/projects/DualQuaternions/ |
65 | | //----------------------------------------------------------------------- |
66 | | void DualQuaternion::fromRotationTranslation (const Quaternion& q, const Vector3& trans) |
67 | 0 | { |
68 | | // non-dual part (just copy the quaternion): |
69 | 0 | w = q.w; |
70 | 0 | x = q.x; |
71 | 0 | y = q.y; |
72 | 0 | z = q.z; |
73 | | |
74 | | // dual part: |
75 | 0 | Real half = 0.5; |
76 | 0 | dw = -half * (trans.x * x + trans.y * y + trans.z * z ); |
77 | 0 | dx = half * (trans.x * w + trans.y * z - trans.z * y ); |
78 | 0 | dy = half * (-trans.x * z + trans.y * w + trans.z * x ); |
79 | 0 | dz = half * (trans.x * y - trans.y * x + trans.z * w ); |
80 | 0 | } |
81 | | |
82 | | //Based on dqconv.c from http://isg.cs.tcd.ie/projects/DualQuaternions/ |
83 | | //----------------------------------------------------------------------- |
84 | | void DualQuaternion::toRotationTranslation (Quaternion& q, Vector3& translation) const |
85 | 0 | { |
86 | | // regular quaternion (just copy the non-dual part): |
87 | 0 | q.w = w; |
88 | 0 | q.x = x; |
89 | 0 | q.y = y; |
90 | 0 | q.z = z; |
91 | | |
92 | | // translation vector: |
93 | 0 | Real doub = 2.0; |
94 | 0 | translation.x = doub * (-dw*x + dx*w - dy*z + dz*y); |
95 | 0 | translation.y = doub * (-dw*y + dx*z + dy*w - dz*x); |
96 | 0 | translation.z = doub * (-dw*z - dx*y + dy*x + dz*w); |
97 | 0 | } |
98 | | |
99 | | //----------------------------------------------------------------------- |
100 | | void DualQuaternion::fromTransformationMatrix (const Affine3& kTrans) |
101 | 0 | { |
102 | 0 | Vector3 pos; |
103 | 0 | Vector3 scale; |
104 | 0 | Quaternion rot; |
105 | |
|
106 | 0 | kTrans.decomposition(pos, scale, rot); |
107 | 0 | fromRotationTranslation(rot, pos); |
108 | 0 | } |
109 | | |
110 | | //----------------------------------------------------------------------- |
111 | | void DualQuaternion::toTransformationMatrix (Affine3& kTrans) const |
112 | 0 | { |
113 | 0 | Vector3 pos; |
114 | 0 | Quaternion rot; |
115 | 0 | toRotationTranslation(rot, pos); |
116 | |
|
117 | 0 | Vector3 scale = Vector3::UNIT_SCALE; |
118 | 0 | kTrans.makeTransform(pos, scale, rot); |
119 | 0 | } |
120 | | } |