OgreDualQuaternion.h
Go to the documentation of this file.
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
48 {
49 public:
52 : w(1), x(0), y(0), z(0), dw(1), dx(0), dy(0), dz(0)
53 {
54 }
55
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
64 inline DualQuaternion(const Matrix4& rot)
65 {
66 this->fromTransformationMatrix(rot);
67 }
68
70 inline DualQuaternion(const Quaternion& q, const Vector3& trans)
71 {
72 this->fromRotationTranslation(q, trans);
73 }
74
76 inline DualQuaternion(Real* valptr)
77 {
78 memcpy(&w, valptr, sizeof(Real)*8);
79 }
80
82 inline Real operator [] ( const size_t i ) const
83 {
84 assert( i < 8 );
85
86 return *(&w+i);
87 }
88
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
123 inline Real* ptr()
124 {
125 return &w;
126 }
127
129 inline const Real* ptr() const
130 {
131 return &w;
132 }
133
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
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
155 void fromRotationTranslation (const Quaternion& q, const Vector3& trans);
156
158 void toRotationTranslation (Quaternion& q, Vector3& translation) const;
159
161 void fromTransformationMatrix (const Matrix4& kTrans);
162
164 void toTransformationMatrix (Matrix4& kTrans) const;
165
166 Real w, x, y, z, dw, dx, dy, dz;
167
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 };
182}
183
184#endif
#define _OgreExport
Definition: OgrePlatform.h:257
Implementation of a dual quaternion, i.e.
DualQuaternion(const Quaternion &q, const Vector3 &trans)
Construct a dual quaternion from a unit quaternion and a translation vector.
DualQuaternion(Real *valptr)
Construct a dual quaternion from 8 manual w/x/y/z/dw/dx/dy/dz values.
DualQuaternion(const Matrix4 &rot)
Construct a dual quaternion from a transformation matrix.
void fromTransformationMatrix(const Matrix4 &kTrans)
Construct a dual quaternion from a 4x4 transformation matrix.
void swap(DualQuaternion &other)
Exchange the contents of this dual quaternion with another.
DualQuaternion()
Default constructor, initializes to identity rotation (aka 0°), and zero translation (0,...
bool isNaN() const
Check whether this dual quaternion contains valid values.
DualQuaternion(Real fW, Real fX, Real fY, Real fZ, Real fdW, Real fdX, Real fdY, Real fdZ)
Construct from an explicit list of values.
void toRotationTranslation(Quaternion &q, Vector3 &translation) const
Convert a dual quaternion into its two components, a Quaternion representing the rotation and a Vecto...
Real * ptr()
Pointer accessor for direct copying.
const Real * ptr() const
Pointer accessor for direct copying.
void toTransformationMatrix(Matrix4 &kTrans) const
Convert a dual quaternion to a 4x4 transformation matrix.
void fromRotationTranslation(const Quaternion &q, const Vector3 &trans)
Construct a dual quaternion from a rotation described by a Quaternion and a translation described by ...
static bool isNaN(Real f)
Definition: OgreMath.h:305
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Implementation of a Quaternion, i.e.
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
float Real
Software floating point type.
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.