歐拉角表明了三維向量中的偏轉角度函數
四元數表明了當有了歐拉角以後,還要根據哪一個軸來旋轉this
矩陣變換包含了平移變換 旋轉變換 縮放變換spa
三個能夠互相轉換3d
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); } };
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] *= div; return *this; } inline