2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_QUAT
|
|
|
|
#define OSG_QUAT 1
|
|
|
|
|
2003-09-06 04:48:42 +08:00
|
|
|
#include <osg/Export>
|
2004-05-20 18:15:48 +08:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
#include <osg/Vec4f>
|
|
|
|
#include <osg/Vec3d>
|
|
|
|
#include <osg/Vec4d>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2003-09-06 04:52:36 +08:00
|
|
|
class Matrixf;
|
|
|
|
class Matrixd;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** A quaternion class. It can be used to represent an orientation in 3D space.*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Quat
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-07-01 23:04:09 +08:00
|
|
|
/** Data type of vector components.*/
|
2019-03-14 01:05:12 +08:00
|
|
|
#ifdef OSG_USE_FLOAT_QUAT
|
|
|
|
typedef float value_type;
|
|
|
|
#else
|
2003-09-29 21:35:02 +08:00
|
|
|
typedef double value_type;
|
2019-03-14 01:05:12 +08:00
|
|
|
#endif
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2016-07-01 23:04:09 +08:00
|
|
|
/** Number of vector components. */
|
|
|
|
enum { num_components = 4 };
|
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
value_type _v[4]; // a four-vector
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Quat() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=1.0; }
|
|
|
|
|
|
|
|
inline Quat( value_type x, value_type y, value_type z, value_type w )
|
2003-09-29 21:35:02 +08:00
|
|
|
{
|
|
|
|
_v[0]=x;
|
|
|
|
_v[1]=y;
|
|
|
|
_v[2]=z;
|
|
|
|
_v[3]=w;
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2020-08-26 22:19:23 +08:00
|
|
|
inline Quat( const Quat& rhs )
|
|
|
|
{
|
|
|
|
_v[0]=rhs._v[0];
|
|
|
|
_v[1]=rhs._v[1];
|
|
|
|
_v[2]=rhs._v[2];
|
|
|
|
_v[3]=rhs._v[3];
|
|
|
|
}
|
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Quat( const Vec4f& v )
|
2003-09-29 21:35:02 +08:00
|
|
|
{
|
|
|
|
_v[0]=v.x();
|
|
|
|
_v[1]=v.y();
|
|
|
|
_v[2]=v.z();
|
|
|
|
_v[3]=v.w();
|
|
|
|
}
|
2002-10-08 03:51:11 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Quat( const Vec4d& v )
|
2004-05-20 18:15:48 +08:00
|
|
|
{
|
|
|
|
_v[0]=v.x();
|
|
|
|
_v[1]=v.y();
|
|
|
|
_v[2]=v.z();
|
|
|
|
_v[3]=v.w();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Quat( value_type angle, const Vec3f& axis)
|
|
|
|
{
|
|
|
|
makeRotate(angle,axis);
|
|
|
|
}
|
|
|
|
inline Quat( value_type angle, const Vec3d& axis)
|
2002-10-08 03:51:11 +08:00
|
|
|
{
|
|
|
|
makeRotate(angle,axis);
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
inline Quat( value_type angle1, const Vec3f& axis1,
|
2004-05-20 18:15:48 +08:00
|
|
|
value_type angle2, const Vec3f& axis2,
|
|
|
|
value_type angle3, const Vec3f& axis3)
|
2002-10-08 03:51:11 +08:00
|
|
|
{
|
|
|
|
makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
inline Quat( value_type angle1, const Vec3d& axis1,
|
2004-05-20 18:15:48 +08:00
|
|
|
value_type angle2, const Vec3d& axis2,
|
|
|
|
value_type angle3, const Vec3d& axis3)
|
|
|
|
{
|
|
|
|
makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
|
|
|
|
}
|
|
|
|
|
2004-08-31 17:20:31 +08:00
|
|
|
inline Quat& operator = (const Quat& v) { _v[0]=v._v[0]; _v[1]=v._v[1]; _v[2]=v._v[2]; _v[3]=v._v[3]; return *this; }
|
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline bool operator == (const Quat& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
|
2003-05-06 21:13:31 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
inline bool operator != (const Quat& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
|
2003-05-06 21:13:31 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
inline bool operator < (const Quat& v) const
|
|
|
|
{
|
|
|
|
if (_v[0]<v._v[0]) return true;
|
|
|
|
else if (_v[0]>v._v[0]) return false;
|
|
|
|
else if (_v[1]<v._v[1]) return true;
|
|
|
|
else if (_v[1]>v._v[1]) return false;
|
|
|
|
else if (_v[2]<v._v[2]) return true;
|
|
|
|
else if (_v[2]>v._v[2]) return false;
|
|
|
|
else return (_v[3]<v._v[3]);
|
|
|
|
}
|
2003-05-06 21:13:31 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
/* ----------------------------------
|
2004-08-04 03:00:55 +08:00
|
|
|
Methods to access data members
|
|
|
|
---------------------------------- */
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Vec4d asVec4() const
|
|
|
|
{
|
|
|
|
return Vec4d(_v[0], _v[1], _v[2], _v[3]);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Vec3d asVec3() const
|
|
|
|
{
|
|
|
|
return Vec3d(_v[0], _v[1], _v[2]);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
inline void set(value_type x, value_type y, value_type z, value_type w)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
_v[0]=x;
|
|
|
|
_v[1]=y;
|
|
|
|
_v[2]=z;
|
|
|
|
_v[3]=w;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-05-20 18:15:48 +08:00
|
|
|
inline void set(const osg::Vec4f& v)
|
|
|
|
{
|
|
|
|
_v[0]=v.x();
|
|
|
|
_v[1]=v.y();
|
|
|
|
_v[2]=v.z();
|
|
|
|
_v[3]=v.w();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set(const osg::Vec4d& v)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
_v[0]=v.x();
|
|
|
|
_v[1]=v.y();
|
|
|
|
_v[2]=v.z();
|
|
|
|
_v[3]=v.w();
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-06 04:52:36 +08:00
|
|
|
void set(const Matrixf& matrix);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-06 04:52:36 +08:00
|
|
|
void set(const Matrixd& matrix);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-06 04:52:36 +08:00
|
|
|
void get(Matrixf& matrix) const;
|
|
|
|
|
|
|
|
void get(Matrixd& matrix) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
inline value_type & operator [] (int i) { return _v[i]; }
|
|
|
|
inline value_type operator [] (int i) const { return _v[i]; }
|
2002-08-28 04:18:43 +08:00
|
|
|
|
2003-09-29 21:35:02 +08:00
|
|
|
inline value_type & x() { return _v[0]; }
|
|
|
|
inline value_type & y() { return _v[1]; }
|
|
|
|
inline value_type & z() { return _v[2]; }
|
|
|
|
inline value_type & w() { return _v[3]; }
|
2002-08-28 04:18:43 +08:00
|
|
|
|
2004-01-14 23:14:20 +08:00
|
|
|
inline value_type x() const { return _v[0]; }
|
|
|
|
inline value_type y() const { return _v[1]; }
|
|
|
|
inline value_type z() const { return _v[2]; }
|
|
|
|
inline value_type w() const { return _v[3]; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-06-29 23:04:38 +08:00
|
|
|
/** return true if the Quat represents a zero rotation, and therefore can be ignored in computations.*/
|
2012-03-22 01:36:20 +08:00
|
|
|
bool zeroRotation() const { return _v[0]==0.0 && _v[1]==0.0 && _v[2]==0.0 && _v[3]==1.0; }
|
2002-10-25 20:29:03 +08:00
|
|
|
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/* -------------------------------------------------------------
|
|
|
|
BASIC ARITHMETIC METHODS
|
2004-08-04 03:00:55 +08:00
|
|
|
Implemented in terms of Vec4s. Some Vec4 operators, e.g.
|
|
|
|
operator* are not appropriate for quaternions (as
|
|
|
|
mathematical objects) so they are implemented differently.
|
2012-03-22 01:36:20 +08:00
|
|
|
Also define methods for conjugate and the multiplicative inverse.
|
2004-08-04 03:00:55 +08:00
|
|
|
------------------------------------------------------------- */
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Multiply by scalar
|
2004-01-14 23:14:20 +08:00
|
|
|
inline const Quat operator * (value_type rhs) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return Quat(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Unary multiply by scalar
|
2004-01-14 23:14:20 +08:00
|
|
|
inline Quat& operator *= (value_type rhs)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
_v[0]*=rhs;
|
|
|
|
_v[1]*=rhs;
|
|
|
|
_v[2]*=rhs;
|
|
|
|
_v[3]*=rhs;
|
2004-06-29 23:04:38 +08:00
|
|
|
return *this; // enable nesting
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Binary multiply
|
2004-08-04 03:00:55 +08:00
|
|
|
inline const Quat operator*(const Quat& rhs) const
|
|
|
|
{
|
|
|
|
return Quat( rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1],
|
|
|
|
rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0],
|
|
|
|
rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3],
|
|
|
|
rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2] );
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Unary multiply
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Quat& operator*=(const Quat& rhs)
|
|
|
|
{
|
|
|
|
value_type x = rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1];
|
|
|
|
value_type y = rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0];
|
|
|
|
value_type z = rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3];
|
|
|
|
_v[3] = rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2];
|
|
|
|
|
|
|
|
_v[2] = z;
|
|
|
|
_v[1] = y;
|
|
|
|
_v[0] = x;
|
|
|
|
|
|
|
|
return (*this); // enable nesting
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Divide by scalar
|
2004-01-14 23:14:20 +08:00
|
|
|
inline Quat operator / (value_type rhs) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
value_type div = 1.0/rhs;
|
|
|
|
return Quat(_v[0]*div, _v[1]*div, _v[2]*div, _v[3]*div);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Unary divide by scalar
|
2004-01-14 23:14:20 +08:00
|
|
|
inline Quat& operator /= (value_type rhs)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
value_type div = 1.0/rhs;
|
|
|
|
_v[0]*=div;
|
|
|
|
_v[1]*=div;
|
|
|
|
_v[2]*=div;
|
|
|
|
_v[3]*=div;
|
2001-01-11 00:32:10 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Binary divide
|
2004-08-04 03:00:55 +08:00
|
|
|
inline const Quat operator/(const Quat& denom) const
|
|
|
|
{
|
|
|
|
return ( (*this) * denom.inverse() );
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Unary divide
|
2004-08-04 03:00:55 +08:00
|
|
|
inline Quat& operator/=(const Quat& denom)
|
|
|
|
{
|
|
|
|
(*this) = (*this) * denom.inverse();
|
|
|
|
return (*this); // enable nesting
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Binary addition
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Quat operator + (const Quat& rhs) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2004-05-20 18:15:48 +08:00
|
|
|
return Quat(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
|
2004-06-29 23:04:38 +08:00
|
|
|
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
/// Unary addition
|
2001-01-11 00:32:10 +08:00
|
|
|
inline Quat& operator += (const Quat& rhs)
|
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
_v[0] += rhs._v[0];
|
|
|
|
_v[1] += rhs._v[1];
|
|
|
|
_v[2] += rhs._v[2];
|
|
|
|
_v[3] += rhs._v[3];
|
2004-06-29 23:04:38 +08:00
|
|
|
return *this; // enable nesting
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Binary subtraction
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Quat operator - (const Quat& rhs) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return Quat(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
|
2004-06-29 23:04:38 +08:00
|
|
|
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Unary subtraction
|
2001-01-11 00:32:10 +08:00
|
|
|
inline Quat& operator -= (const Quat& rhs)
|
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
_v[0]-=rhs._v[0];
|
|
|
|
_v[1]-=rhs._v[1];
|
|
|
|
_v[2]-=rhs._v[2];
|
|
|
|
_v[3]-=rhs._v[3];
|
2004-06-29 23:04:38 +08:00
|
|
|
return *this; // enable nesting
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
/** Negation operator - returns the negative of the quaternion.
|
2004-06-29 23:04:38 +08:00
|
|
|
Basically just calls operator - () on the Vec4 */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Quat operator - () const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return Quat (-_v[0], -_v[1], -_v[2], -_v[3]);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Length of the quaternion = sqrt( vec . vec )
|
2003-09-29 21:35:02 +08:00
|
|
|
value_type length() const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Length of the quaternion = vec . vec
|
2003-09-29 21:35:02 +08:00
|
|
|
value_type length2() const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/// Conjugate
|
2002-09-02 20:31:35 +08:00
|
|
|
inline Quat conj () const
|
2012-03-22 01:36:20 +08:00
|
|
|
{
|
2003-09-29 21:35:02 +08:00
|
|
|
return Quat( -_v[0], -_v[1], -_v[2], _v[3] );
|
2001-12-15 07:18:28 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
/// Multiplicative inverse method: q^(-1) = q^*/(q.q^*)
|
|
|
|
inline const Quat inverse () const
|
|
|
|
{
|
|
|
|
return conj() / length2();
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/* --------------------------------------------------------
|
2004-06-29 23:04:38 +08:00
|
|
|
METHODS RELATED TO ROTATIONS
|
2004-08-04 03:00:55 +08:00
|
|
|
Set a quaternion which will perform a rotation of an
|
|
|
|
angle around the axis given by the vector (x,y,z).
|
|
|
|
Should be written to also accept an angle and a Vec3?
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
Define Spherical Linear interpolation method also
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-08-04 03:00:55 +08:00
|
|
|
Not inlined - see the Quat.cpp file for implementation
|
|
|
|
-------------------------------------------------------- */
|
2012-03-22 01:36:20 +08:00
|
|
|
void makeRotate( value_type angle,
|
2003-09-29 21:35:02 +08:00
|
|
|
value_type x, value_type y, value_type z );
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeRotate ( value_type angle, const Vec3f& vec );
|
|
|
|
void makeRotate ( value_type angle, const Vec3d& vec );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
void makeRotate ( value_type angle1, const Vec3f& axis1,
|
2004-05-20 18:15:48 +08:00
|
|
|
value_type angle2, const Vec3f& axis2,
|
|
|
|
value_type angle3, const Vec3f& axis3);
|
2012-03-22 01:36:20 +08:00
|
|
|
void makeRotate ( value_type angle1, const Vec3d& axis1,
|
2004-05-20 18:15:48 +08:00
|
|
|
value_type angle2, const Vec3d& axis2,
|
|
|
|
value_type angle3, const Vec3d& axis3);
|
Added DOFTransform, MatrixTransform and PositionAttitudeTransform to NodeVisitor.
Added osg::Matrix/Quat::makeRotate(angle1,axis1,angle2,axis2,angle3,axis3) and
osg::Matrix::rotate(angle1,axis1,angle2,axis2,angle3,axis3) method.
Made osg::Matrix/Quat::makeRotate(heading,pitch,roll) and
osg::Matrix::rotate(heading,pitch,roll) all deprecated API.
Fixed the Quat*Quat & Quat*=Quat multiplication methods so that they multiplied
in the correct order - they were reversed originally due to the Quat code being
based on code example which used the v' = M v ordering, rather than the OSG's
v' = v M ordering.
2002-08-18 22:42:43 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Make a rotation Quat which will rotate vec1 to vec2.
|
2004-09-03 03:10:33 +08:00
|
|
|
Generally take a dot product to get the angle between these
|
2001-01-11 00:32:10 +08:00
|
|
|
and then use a cross product to get the rotation axis
|
2004-09-03 03:10:33 +08:00
|
|
|
Watch out for the two special cases when the vectors
|
2001-01-11 00:32:10 +08:00
|
|
|
are co-incident or opposite in direction.*/
|
2004-05-20 18:15:48 +08:00
|
|
|
void makeRotate( const Vec3f& vec1, const Vec3f& vec2 );
|
|
|
|
/** Make a rotation Quat which will rotate vec1 to vec2.
|
2004-09-03 03:10:33 +08:00
|
|
|
Generally take a dot product to get the angle between these
|
2004-05-20 18:15:48 +08:00
|
|
|
and then use a cross product to get the rotation axis
|
|
|
|
Watch out for the two special cases of when the vectors
|
|
|
|
are co-incident or opposite in direction.*/
|
|
|
|
void makeRotate( const Vec3d& vec1, const Vec3d& vec2 );
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-01-27 22:39:58 +08:00
|
|
|
void makeRotate_original( const Vec3d& vec1, const Vec3d& vec2 );
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
/** Return the angle and vector components represented by the quaternion.*/
|
2003-09-29 21:35:02 +08:00
|
|
|
void getRotate ( value_type & angle, value_type & x, value_type & y, value_type & z ) const;
|
2004-05-20 18:15:48 +08:00
|
|
|
|
|
|
|
/** Return the angle and vector represented by the quaternion.*/
|
|
|
|
void getRotate ( value_type & angle, Vec3f& vec ) const;
|
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
/** Return the angle and vector represented by the quaternion.*/
|
2004-05-20 18:15:48 +08:00
|
|
|
void getRotate ( value_type & angle, Vec3d& vec ) const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
/** Spherical Linear Interpolation.
|
2004-06-29 23:04:38 +08:00
|
|
|
As t goes from 0 to 1, the Quat object goes from "from" to "to". */
|
2003-09-29 21:35:02 +08:00
|
|
|
void slerp ( value_type t, const Quat& from, const Quat& to);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-06-29 23:04:38 +08:00
|
|
|
/** Rotate a vector by this quaternion.*/
|
|
|
|
Vec3f operator* (const Vec3f& v) const
|
|
|
|
{
|
|
|
|
// nVidia SDK implementation
|
2012-03-22 01:36:20 +08:00
|
|
|
Vec3f uv, uuv;
|
2004-06-29 23:04:38 +08:00
|
|
|
Vec3f qvec(_v[0], _v[1], _v[2]);
|
|
|
|
uv = qvec ^ v;
|
2012-03-22 01:36:20 +08:00
|
|
|
uuv = qvec ^ uv;
|
|
|
|
uv *= ( 2.0f * _v[3] );
|
|
|
|
uuv *= 2.0f;
|
2004-06-29 23:04:38 +08:00
|
|
|
return v + uv + uuv;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-06-29 23:04:38 +08:00
|
|
|
/** Rotate a vector by this quaternion.*/
|
|
|
|
Vec3d operator* (const Vec3d& v) const
|
|
|
|
{
|
|
|
|
// nVidia SDK implementation
|
2012-03-22 01:36:20 +08:00
|
|
|
Vec3d uv, uuv;
|
2004-06-29 23:04:38 +08:00
|
|
|
Vec3d qvec(_v[0], _v[1], _v[2]);
|
|
|
|
uv = qvec ^ v;
|
2012-03-22 01:36:20 +08:00
|
|
|
uuv = qvec ^ uv;
|
|
|
|
uv *= ( 2.0f * _v[3] );
|
|
|
|
uuv *= 2.0f;
|
2004-06-29 23:04:38 +08:00
|
|
|
return v + uv + uuv;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-05-22 05:32:56 +08:00
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-06-29 23:04:38 +08:00
|
|
|
}; // end of class prototype
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-06-29 23:04:38 +08:00
|
|
|
} // end of namespace
|
2002-02-03 20:33:41 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
#endif
|