Coverage Report

Created: 2025-08-29 06:18

/src/ogre/OgreMain/include/OgreDualQuaternion.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef __DualQuaternion_H__
30
#define __DualQuaternion_H__
31
32
#include "OgrePrerequisites.h"
33
#include "OgreMath.h"
34
35
namespace 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
0
            : w(1), x(0), y(0), z(0), dw(1), dx(0), dy(0), dz(0)
53
0
        {
54
0
        }
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
0
        {
61
0
        }
62
        
63
        /// Construct a dual quaternion from a transformation matrix
64
        inline DualQuaternion(const Affine3& rot)
65
0
        {
66
0
            this->fromTransformationMatrix(rot);
67
0
        }
68
        
69
        /// Construct a dual quaternion from a unit quaternion and a translation vector
70
        inline DualQuaternion(const Quaternion& q, const Vector3& trans)
71
0
        {
72
0
            this->fromRotationTranslation(q, trans);
73
0
        }
74
        
75
        /// Construct a dual quaternion from 8 manual w/x/y/z/dw/dx/dy/dz values
76
        inline DualQuaternion(Real* valptr)
77
0
        {
78
0
            memcpy(&w, valptr, sizeof(Real)*8);
79
0
        }
80
81
        /// Array accessor operator
82
        inline Real operator [] ( const size_t i ) const
83
0
        {
84
0
            assert( i < 8 );
85
0
86
0
            return *(&w+i);
87
0
        }
88
89
        /// Array accessor operator
90
        inline Real& operator [] ( const size_t i )
91
0
        {
92
0
            assert( i < 8 );
93
94
0
            return *(&w+i);
95
0
        }
96
        
97
        inline DualQuaternion& operator= (const DualQuaternion& rkQ)
98
0
        {
99
0
            w = rkQ.w;
100
0
            x = rkQ.x;
101
0
            y = rkQ.y;
102
0
            z = rkQ.z;
103
0
            dw = rkQ.dw;
104
0
            dx = rkQ.dx;
105
0
            dy = rkQ.dy;
106
0
            dz = rkQ.dz;
107
0
            
108
0
            return *this;
109
0
        }
110
111
        inline bool operator== (const DualQuaternion& rhs) const
112
0
        {
113
0
            return (rhs.w == w) && (rhs.x == x) && (rhs.y == y) && (rhs.z == z) && 
114
0
                (rhs.dw == dw) && (rhs.dx == dx) && (rhs.dy == dy) && (rhs.dz == dz);
115
0
        }
116
117
        inline bool operator!= (const DualQuaternion& rhs) const
118
0
        {
119
0
            return !operator==(rhs);
120
0
        }
121
122
        /// Pointer accessor for direct copying
123
        inline Real* ptr()
124
0
        {
125
0
            return &w;
126
0
        }
127
128
        /// Pointer accessor for direct copying
129
        inline const Real* ptr() const
130
0
        {
131
0
            return &w;
132
0
        }
133
        
134
        /// Exchange the contents of this dual quaternion with another. 
135
        inline void swap(DualQuaternion& other)
136
0
        {
137
0
            std::swap(w, other.w);
138
0
            std::swap(x, other.x);
139
0
            std::swap(y, other.y);
140
0
            std::swap(z, other.z);
141
0
            std::swap(dw, other.dw);
142
0
            std::swap(dx, other.dx);
143
0
            std::swap(dy, other.dy);
144
0
            std::swap(dz, other.dz);
145
0
        }
146
147
#ifndef OGRE_FAST_MATH
148
        /// Check whether this dual quaternion contains valid values
149
        inline bool isNaN() const
150
0
        {
151
0
            return Math::isNaN(w) || Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) ||  
152
0
                Math::isNaN(dw) || Math::isNaN(dx) || Math::isNaN(dy) || Math::isNaN(dz);
153
0
        }
154
#endif
155
156
        /// Construct a dual quaternion from a rotation described by a Quaternion and a translation described by a Vector3
157
        void fromRotationTranslation (const Quaternion& q, const Vector3& trans);
158
        
159
        /// Convert a dual quaternion into its two components, a Quaternion representing the rotation and a Vector3 representing the translation
160
        void toRotationTranslation (Quaternion& q, Vector3& translation) const;
161
162
        /// Construct a dual quaternion from a 4x4 transformation matrix
163
        void fromTransformationMatrix (const Affine3& kTrans);
164
        
165
        /// Convert a dual quaternion to a 4x4 transformation matrix
166
        void toTransformationMatrix (Affine3& kTrans) const;
167
168
        Real w, x, y, z, dw, dx, dy, dz;
169
170
        /** 
171
        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
172
        being the member values of the dual quaternion.
173
        */
174
        inline _OgreExport friend std::ostream& operator <<
175
        ( std::ostream& o, const DualQuaternion& q )
176
0
        {
177
0
            o << "DualQuaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ", " << q.dw << ", " << q.dx << ", " << q.dy << ", " << q.dz << ")";
178
0
            return o;
179
0
        }
180
    };
181
    /** @} */
182
    /** @} */
183
184
}
185
186
#endif