Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreDualQuaternion.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 5.4 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __DualQuaternion_H__
30#define __DualQuaternion_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreMath.h"
34
35namespace Ogre {
36
37        /** \addtogroup Core
38        *  @{
39        */
40        /** \addtogroup Math
41        *  @{
42        */
43        /** Implementation of a dual quaternion, i.e. a rotation around an axis and a translation.
44            This implementation may note be appropriate as a general implementation, but is intended for use with
45            dual quaternion skinning.
46        */
47        class _OgreExport DualQuaternion
48        {
49        public:
50                /// Default constructor, initializes to identity rotation (aka 0°), and zero translation (0,0,0)
51                inline DualQuaternion ()
52                        : w(1), x(0), y(0), z(0), dw(1), dx(0), dy(0), dz(0)
53                {
54                }
55               
56                /// Construct from an explicit list of values
57                inline DualQuaternion (Real fW, Real fX, Real fY, Real fZ, 
58                                Real fdW, Real fdX, Real fdY, Real fdZ)
59                        : w(fW), x(fX), y(fY), z(fZ), dw(fdW), dx(fdX), dy(fdY), dz(fdZ)
60                {
61                }
62       
63                /// Construct a dual quaternion from a transformation matrix
64                inline DualQuaternion(const Matrix4& rot)
65                {
66                        this->fromTransformationMatrix(rot);
67                }
68               
69                /// Construct a dual quaternion from a unit quaternion and a translation vector
70                inline DualQuaternion(const Quaternion& q, const Vector3& trans)
71                {
72                        this->fromRotationTranslation(q, trans);
73                }
74               
75                /// Construct a dual quaternion from 8 manual w/x/y/z/dw/dx/dy/dz values
76                inline DualQuaternion(Real* valptr)
77                {
78                        memcpy(&w, valptr, sizeof(Real)*8);
79                }
80
81                /// Array accessor operator
82                inline Real operator [] ( const size_t i ) const
83                {
84                        assert( i < 8 );
85
86                        return *(&w+i);
87                }
88
89                /// Array accessor operator
90                inline Real& operator [] ( const size_t i )
91                {
92                        assert( i < 8 );
93
94                        return *(&w+i);
95                }
96               
97                inline DualQuaternion& operator= (const DualQuaternion& rkQ)
98                {
99                        w = rkQ.w;
100                        x = rkQ.x;
101                        y = rkQ.y;
102                        z = rkQ.z;
103                        dw = rkQ.dw;
104                        dx = rkQ.dx;
105                        dy = rkQ.dy;
106                        dz = rkQ.dz;
107                       
108                        return *this;
109                }
110
111                inline bool operator== (const DualQuaternion& rhs) const
112                {
113                        return (rhs.w == w) && (rhs.x == x) && (rhs.y == y) && (rhs.z == z) && 
114                                (rhs.dw == dw) && (rhs.dx == dx) && (rhs.dy == dy) && (rhs.dz == dz);
115                }
116
117                inline bool operator!= (const DualQuaternion& rhs) const
118                {
119                        return !operator==(rhs);
120                }
121
122                /// Pointer accessor for direct copying
123                inline Real* ptr()
124                {
125                        return &w;
126                }
127
128                /// Pointer accessor for direct copying
129                inline const Real* ptr() const
130                {
131                        return &w;
132                }
133               
134                /// Exchange the contents of this dual quaternion with another.
135                inline void swap(DualQuaternion& other)
136                {
137                        std::swap(w, other.w);
138                        std::swap(x, other.x);
139                        std::swap(y, other.y);
140                        std::swap(z, other.z);
141                        std::swap(dw, other.dw);
142                        std::swap(dx, other.dx);
143                        std::swap(dy, other.dy);
144                        std::swap(dz, other.dz);
145                }
146               
147                /// Check whether this dual quaternion contains valid values
148                inline bool isNaN() const
149                {
150                        return Math::isNaN(w) || Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || 
151                                Math::isNaN(dw) || Math::isNaN(dx) || Math::isNaN(dy) || Math::isNaN(dz);
152                }
153
154                /// Construct a dual quaternion from a rotation described by a Quaternion and a translation described by a Vector3
155                void fromRotationTranslation (const Quaternion& q, const Vector3& trans);
156               
157                /// Convert a dual quaternion into its two components, a Quaternion representing the rotation and a Vector3 representing the translation
158                void toRotationTranslation (Quaternion& q, Vector3& translation) const;
159
160                /// Construct a dual quaternion from a 4x4 transformation matrix
161                void fromTransformationMatrix (const Matrix4& kTrans);
162               
163                /// Convert a dual quaternion to a 4x4 transformation matrix
164                void toTransformationMatrix (Matrix4& kTrans) const;
165
166                Real w, x, y, z, dw, dx, dy, dz;
167
168                /**
169                Function for writing to a stream. Outputs "DualQuaternion(w, x, y, z, dw, dx, dy, dz)" with w, x, y, z, dw, dx, dy, dz
170                being the member values of the dual quaternion.
171                */
172                inline _OgreExport friend std::ostream& operator <<
173                ( std::ostream& o, const DualQuaternion& q )
174                {
175                        o << "DualQuaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ", " << q.dw << ", " << q.dx << ", " << q.dy << ", " << q.dz << ")";
176                        return o;
177                }
178        };
179        /** @} */
180        /** @} */
181
182}
183
184#endif
Note: See TracBrowser for help on using the repository browser.