OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreDualQuaternion.h
Go to the documentation of this file.
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-2013 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 
48  {
49  public:
51  inline DualQuaternion ()
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
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:233
Implementation of a 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()
Default constructor, initializes to identity rotation (aka 0°), and zero translation (0...
DualQuaternion(const Matrix4 &rot)
Construct a dual quaternion from a transformation matrix.
const Real * ptr() const
Pointer accessor for direct copying.
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
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 swap(DualQuaternion &other)
Exchange the contents of this dual quaternion with another.
static bool isNaN(Real f)
Definition: OgreMath.h:290
Implementation of a dual quaternion, i.e.
Real * ptr()
Pointer accessor for direct copying.
bool isNaN() const
Check whether this dual quaternion contains valid values.
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)