38 inline Quat() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=1.0; }
40 inline Quat( value_type x, value_type y, value_type z, value_type w )
66 makeRotate(angle,axis);
70 makeRotate(angle,axis);
74 value_type angle2,
const Vec3f& axis2,
75 value_type angle3,
const Vec3f& axis3)
77 makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
81 value_type angle2,
const Vec3d& axis2,
82 value_type angle3,
const Vec3d& axis3)
84 makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
87 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; }
89 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]; }
91 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]; }
93 inline bool operator < (
const Quat& v)
const
95 if (_v[0]<v.
_v[0])
return true;
96 else if (_v[0]>v.
_v[0])
return false;
97 else if (_v[1]<v.
_v[1])
return true;
98 else if (_v[1]>v.
_v[1])
return false;
99 else if (_v[2]<v.
_v[2])
return true;
100 else if (_v[2]>v.
_v[2])
return false;
101 else return (_v[3]<v.
_v[3]);
110 return Vec4d(_v[0], _v[1], _v[2], _v[3]);
115 return Vec3d(_v[0], _v[1], _v[2]);
118 inline void set(value_type x, value_type y, value_type z, value_type w)
142 void set(
const Matrixf& matrix);
144 void set(
const Matrixd& matrix);
146 void get(
Matrixf& matrix)
const;
148 void get(
Matrixd& matrix)
const;
151 inline value_type & operator [] (
int i) {
return _v[i]; }
152 inline value_type operator [] (
int i)
const {
return _v[i]; }
154 inline value_type &
x() {
return _v[0]; }
155 inline value_type &
y() {
return _v[1]; }
156 inline value_type &
z() {
return _v[2]; }
157 inline value_type &
w() {
return _v[3]; }
159 inline value_type
x()
const {
return _v[0]; }
160 inline value_type
y()
const {
return _v[1]; }
161 inline value_type
z()
const {
return _v[2]; }
162 inline value_type
w()
const {
return _v[3]; }
165 bool zeroRotation()
const {
return _v[0]==0.0 && _v[1]==0.0 && _v[2]==0.0 && _v[3]==1.0; }
178 return Quat(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
182 inline Quat& operator *= (value_type rhs)
194 return Quat( rhs.
_v[3]*_v[0] + rhs.
_v[0]*_v[3] + rhs.
_v[1]*_v[2] - rhs.
_v[2]*_v[1],
195 rhs.
_v[3]*_v[1] - rhs.
_v[0]*_v[2] + rhs.
_v[1]*_v[3] + rhs.
_v[2]*_v[0],
196 rhs.
_v[3]*_v[2] + rhs.
_v[0]*_v[1] - rhs.
_v[1]*_v[0] + rhs.
_v[2]*_v[3],
197 rhs.
_v[3]*_v[3] - rhs.
_v[0]*_v[0] - rhs.
_v[1]*_v[1] - rhs.
_v[2]*_v[2] );
203 value_type x = rhs.
_v[3]*_v[0] + rhs.
_v[0]*_v[3] + rhs.
_v[1]*_v[2] - rhs.
_v[2]*_v[1];
204 value_type y = rhs.
_v[3]*_v[1] - rhs.
_v[0]*_v[2] + rhs.
_v[1]*_v[3] + rhs.
_v[2]*_v[0];
205 value_type z = rhs.
_v[3]*_v[2] + rhs.
_v[0]*_v[1] - rhs.
_v[1]*_v[0] + rhs.
_v[2]*_v[3];
206 _v[3] = rhs.
_v[3]*_v[3] - rhs.
_v[0]*_v[0] - rhs.
_v[1]*_v[1] - rhs.
_v[2]*_v[2];
216 inline Quat operator / (value_type rhs)
const
218 value_type div = 1.0/rhs;
219 return Quat(_v[0]*div, _v[1]*div, _v[2]*div, _v[3]*div);
223 inline Quat& operator /= (value_type rhs)
225 value_type div = 1.0/rhs;
236 return ( (*
this) * denom.
inverse() );
242 (*this) = (*this) * denom.
inverse();
247 inline const Quat operator + (
const Quat& rhs)
const
249 return Quat(_v[0]+rhs.
_v[0], _v[1]+rhs.
_v[1],
250 _v[2]+rhs.
_v[2], _v[3]+rhs.
_v[3]);
264 inline const Quat operator - (
const Quat& rhs)
const
266 return Quat(_v[0]-rhs.
_v[0], _v[1]-rhs.
_v[1],
267 _v[2]-rhs.
_v[2], _v[3]-rhs.
_v[3] );
282 inline const Quat operator - ()
const
284 return Quat (-_v[0], -_v[1], -_v[2], -_v[3]);
290 return sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
296 return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
302 return Quat( -_v[0], -_v[1], -_v[2], _v[3] );
308 return conj() / length2();
321 void makeRotate( value_type angle,
322 value_type x, value_type y, value_type z );
323 void makeRotate ( value_type angle,
const Vec3f& vec );
324 void makeRotate ( value_type angle,
const Vec3d& vec );
326 void makeRotate ( value_type angle1,
const Vec3f& axis1,
327 value_type angle2,
const Vec3f& axis2,
328 value_type angle3,
const Vec3f& axis3);
329 void makeRotate ( value_type angle1,
const Vec3d& axis1,
330 value_type angle2,
const Vec3d& axis2,
331 value_type angle3,
const Vec3d& axis3);
338 void makeRotate(
const Vec3f& vec1,
const Vec3f& vec2 );
344 void makeRotate(
const Vec3d& vec1,
const Vec3d& vec2 );
346 void makeRotate_original(
const Vec3d& vec1,
const Vec3d& vec2 );
349 void getRotate ( value_type & angle, value_type & x, value_type & y, value_type & z )
const;
352 void getRotate ( value_type & angle,
Vec3f& vec )
const;
355 void getRotate ( value_type & angle,
Vec3d& vec )
const;
359 void slerp ( value_type t,
const Quat& from,
const Quat& to);
366 Vec3f qvec(_v[0], _v[1], _v[2]);
369 uv *= ( 2.0f * _v[3] );
379 Vec3d qvec(_v[0], _v[1], _v[2]);
382 uv *= ( 2.0f * _v[3] );
Quat(value_type angle1, const Vec3f &axis1, value_type angle2, const Vec3f &axis2, value_type angle3, const Vec3f &axis3)
bool zeroRotation() const
const Quat inverse() const
Multiplicative inverse method: q^(-1) = q^*/(q.q^*)
Quat(value_type angle1, const Vec3d &axis1, value_type angle2, const Vec3d &axis2, value_type angle3, const Vec3d &axis3)
Quat(value_type angle, const Vec3f &axis)
void set(const osg::Vec4d &v)
value_type length2() const
Length of the quaternion = vec . vec.
const Quat operator/(const Quat &denom) const
Binary divide.
Quat(value_type x, value_type y, value_type z, value_type w)
value_type length() const
Length of the quaternion = sqrt( vec . vec )
const Quat operator*(const Quat &rhs) const
Binary multiply.
void set(value_type x, value_type y, value_type z, value_type w)
Vec3f operator*(const Vec3f &v, const Matrixd &m)
void set(const osg::Vec4f &v)
Quat & operator/=(const Quat &denom)
Unary divide.
Quat conj() const
Conjugate.
Quat & operator*=(const Quat &rhs)
Unary multiply.
Quat(value_type angle, const Vec3d &axis)