OgreDualQuaternion.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __DualQuaternion_H__
    00030 #define __DualQuaternion_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreMath.h"
    00034
    00035 namespace Ogre {
    00036
    00047     class _OgreExport DualQuaternion
    00048     {
    00049     public:
    00051         inline DualQuaternion ()
    00052             : w(1), x(0), y(0), z(0), dw(1), dx(0), dy(0), dz(0)
    00053         {
    00054         }
    00055
    00057         inline DualQuaternion (Real fW, Real fX, Real fY, Real fZ,
    00058                 Real fdW, Real fdX, Real fdY, Real fdZ)
    00059             : w(fW), x(fX), y(fY), z(fZ), dw(fdW), dx(fdX), dy(fdY), dz(fdZ)
    00060         {
    00061         }
    00062
    00064         inline DualQuaternion(const Matrix4& rot)
    00065         {
    00066             this->fromTransformationMatrix(rot);
    00067         }
    00068
    00070         inline DualQuaternion(const Quaternion& q, const Vector3& trans)
    00071         {
    00072             this->fromRotationTranslation(q, trans);
    00073         }
    00074
    00076         inline DualQuaternion(Real* valptr)
    00077         {
    00078             memcpy(&w, valptr, sizeof(Real)*8);
    00079         }
    00080
    00082         inline Real operator [] ( const size_t i ) const
    00083         {
    00084             assert( i < 8 );
    00085
    00086             return *(&w+i);
    00087         }
    00088
    00090         inline Real& operator [] ( const size_t i )
    00091         {
    00092             assert( i < 8 );
    00093
    00094             return *(&w+i);
    00095         }
    00096
    00097         inline DualQuaternion& operator= (const DualQuaternion& rkQ)
    00098         {
    00099             w = rkQ.w;
    00100             x = rkQ.x;
    00101             y = rkQ.y;
    00102             z = rkQ.z;
    00103             dw = rkQ.dw;
    00104             dx = rkQ.dx;
    00105             dy = rkQ.dy;
    00106             dz = rkQ.dz;
    00107
    00108             return *this;
    00109         }
    00110
    00111         inline bool operator== (const DualQuaternion& rhs) const
    00112         {
    00113             return (rhs.w == w) && (rhs.x == x) && (rhs.y == y) && (rhs.z == z) &&
    00114                 (rhs.dw == dw) && (rhs.dx == dx) && (rhs.dy == dy) && (rhs.dz == dz);
    00115         }
    00116
    00117         inline bool operator!= (const DualQuaternion& rhs) const
    00118         {
    00119             return !operator==(rhs);
    00120         }
    00121
    00123         inline Real* ptr()
    00124         {
    00125             return &w;
    00126         }
    00127
    00129         inline const Real* ptr() const
    00130         {
    00131             return &w;
    00132         }
    00133
    00135         inline void swap(DualQuaternion& other)
    00136         {
    00137             std::swap(w, other.w);
    00138             std::swap(x, other.x);
    00139             std::swap(y, other.y);
    00140             std::swap(z, other.z);
    00141             std::swap(dw, other.dw);
    00142             std::swap(dx, other.dx);
    00143             std::swap(dy, other.dy);
    00144             std::swap(dz, other.dz);
    00145         }
    00146
    00148         inline bool isNaN() const
    00149         {
    00150             return Math::isNaN(w) || Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) ||
    00151                 Math::isNaN(dw) || Math::isNaN(dx) || Math::isNaN(dy) || Math::isNaN(dz);
    00152         }
    00153
    00155         void fromRotationTranslation (const Quaternion& q, const Vector3& trans);
    00156
    00158         void toRotationTranslation (Quaternion& q, Vector3& translation) const;
    00159
    00161         void fromTransformationMatrix (const Matrix4& kTrans);
    00162
    00164         void toTransformationMatrix (Matrix4& kTrans) const;
    00165
    00166         Real w, x, y, z, dw, dx, dy, dz;
    00167
    00172         inline _OgreExport friend std::ostream& operator <<
    00173         ( std::ostream& o, const DualQuaternion& q )
    00174         {
    00175             o << "DualQuaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ", " << q.dw << ", " << q.dx << ", " << q.dy << ", " << q.dz << ")";
    00176             return o;
    00177         }
    00178     };
    00182 }
    00183
    00184 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21