一.简介
欧拉角代表了三维向量中的偏转角度
四元数代表了当有了欧拉角之后,还要根据哪个轴来旋转
矩阵变换包含了平移变换 旋转变换 缩放变换
三个可以互相转换
二.osg::Quat类
1.构造函数
class OSG_EXPORT Quat
{
public:
typedef double value_type;
value_type _v[4];
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)
{
_v[0] = x;
_v[1] = y;
_v[2] = z;
_v[3] = w;
}
inline Quat(const Vec4f& v)
{
_v[0] = v.x();
_v[1] = v.y();
_v[2] = v.z();
_v[3] = v.w();
}
inline Quat(const Vec4d& v)
{
_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)
{
makeRotate(angle, axis);
}
inline Quat(value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
makeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
}
inline Quat(value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
makeRotate(angle1, axis1, angle2, axis2, angle3, axis3);
}
};
2.重载操作符函数
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;
}
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];
}
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];
}
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]);
}
inline value_type& operator [] (int i) { return _v[i]; }
inline value_type operator [] (int i) const {return _v[i];}
inline const Quat operator * (value_type rhs) const
{
return Quat(_v[0] * rhs, _v[1] * rhs, _v[2] * rhs, _v[3] * rhs);
}
inline Quat& operator *= (value_type rhs)
{
_v[0] *= rhs;
_v[1] *= rhs;
_v[2] *= rhs'
_v[3] *= rhs;
return *this;
}
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] );
}
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);
}
inline Quat operator / (value_type rhs) const
{
value_type div = 1.0 / rhs;
return Quat(_v[0] * div, _v[1] * div, _v[2] * div, _v[3] * div);
}
inline Quat& operator /= (value_type rhs)
{
value_type div = 1.0 / rhs;
_v[0] *= div;
_v[1] *= div;
_v[2] *= div;
_v[3] *=