26 template <
class QUAT_TYPE>
inline
32 template <
class QUAT_TYPE>
inline
40 template <
class QUAT_TYPE>
inline
48 template <
class QUAT_TYPE>
inline
52 QUAT_TYPE *qThis = this->GetData();
53 if ((qThis[3] <= QUATERNION_EPSILON)
54 &&(qThis[3] >= -QUATERNION_EPSILON)) {
55 if ((qThis[1] <= QUATERNION_EPSILON)
56 &&(qThis[1] >= -QUATERNION_EPSILON)) {
57 if ((qThis[2] <= QUATERNION_EPSILON)
58 &&(qThis[2] >= -QUATERNION_EPSILON)) {
59 if (qThis[0] < 0.0) (*this) *= -1.0;
60 }
else if (qThis[2] < 0.0) {
63 }
else if (qThis[1] < 0.0) {
66 }
else if (qThis[3] < 0.0) {
71 template <
class QUAT_TYPE>
inline
74 QUAT_TYPE s1, s2, s3, s4, s5, s6, s7, s8, s9, t;
75 QUAT_TYPE *qThis = this->GetData();
77 s1 = (qThis[2] - qThis[1]) * (quat[1] - quat[2]);
78 s2 = (qThis[3] + qThis[0]) * (quat[3] + quat[0]);
79 s3 = (qThis[3] - qThis[0]) * (quat[1] + quat[2]);
80 s4 = (qThis[2] + qThis[1]) * (quat[3] - quat[0]);
81 s5 = (qThis[2] - qThis[0]) * (quat[0] - quat[1]);
82 s6 = (qThis[2] + qThis[0]) * (quat[0] + quat[1]);
83 s7 = (qThis[3] + qThis[1]) * (quat[3] - quat[2]);
84 s8 = (qThis[3] - qThis[1]) * (quat[3] + quat[2]);
90 qThis[3] = s1 + t - s6;
91 qThis[0] = s2 + t - s9;
92 qThis[1] = s3 + t - s8;
93 qThis[2] = s4 + t - s7;
96 template <
class QUAT_TYPE>
inline
104 template <
class QUAT_TYPE>
inline
107 QUAT_TYPE s1, s2, s3, s4, s5, s6, s7, s8, s9, t;
108 QUAT_TYPE *qThis = this->GetData();
110 s1 = (quatLeft[2] - quatLeft[1]) * (qThis[1] - qThis[2]);
111 s2 = (quatLeft[3] + quatLeft[0]) * (qThis[3] + qThis[0]);
112 s3 = (quatLeft[3] - quatLeft[0]) * (qThis[1] + qThis[2]);
113 s4 = (quatLeft[2] + quatLeft[1]) * (qThis[3] - qThis[0]);
114 s5 = (quatLeft[2] - quatLeft[0]) * (qThis[0] - qThis[1]);
115 s6 = (quatLeft[2] + quatLeft[0]) * (qThis[0] + qThis[1]);
116 s7 = (quatLeft[3] + quatLeft[1]) * (qThis[3] - qThis[2]);
117 s8 = (quatLeft[3] - quatLeft[1]) * (qThis[3] + qThis[2]);
121 t = (s5 + s9) / 2.0f;
123 qThis[3] = s1 + t - s6;
124 qThis[0] = s2 + t - s9;
125 qThis[1] = s3 + t - s8;
126 qThis[2] = s4 + t - s7;
134 template <
class QUAT_TYPE>
inline
138 register QUAT_TYPE rx,ry,rz;
139 register QUAT_TYPE Vx= vec[0], Vy=vec[1], Vz=vec[2];
140 const QUAT_TYPE *q = this->GetData();
142 register QUAT_TYPE QwQx, QwQy, QwQz, QxQy, QxQz, QyQz;
143 QwQx = q[3] * q[0]; QwQy = q[3] * q[1]; QwQz = q[3] * q[2];
144 QxQy = q[0] * q[1]; QxQz = q[0] * q[2]; QyQz = q[1] * q[2];
145 rx = 2* (Vy * (-QwQz + QxQy) + Vz *( QwQy + QxQz));
146 ry = 2* (Vx * ( QwQz + QxQy) + Vz *(-QwQx + QyQz));
147 rz = 2* (Vx * (-QwQy + QxQz) + Vy *( QwQx + QyQz));
149 register QUAT_TYPE QwQw, QxQx, QyQy, QzQz;
150 QwQw= q[3]*q[3]; QxQx = q[0]*q[0]; QyQy = q[1]*q[1]; QzQz= q[2]*q[2];
151 rx+= Vx * (QwQw + QxQx - QyQy - QzQz);
152 ry+= Vy * (QwQw - QxQx + QyQy - QzQz);
153 rz+= Vz * (QwQw - QxQx - QyQy + QzQz);
154 res[0]=rx; res[1]=ry; res[2]=rz;
158 template <
class QUAT_TYPE>
inline
166 template <
class QUAT_TYPE>
inline
169 (*this)[0] = (*this)[1] = (*this)[2] = 0;
173 template <
class QUAT_TYPE>
inline
175 QUAT_TYPE j, QUAT_TYPE k)
178 this->Set(i,j,k,real);
181 template <
class QUAT_TYPE>
inline
185 SetValueAsAxisRad(axis[0], axis[1], axis[2], angle);
188 template <
class QUAT_TYPE>
inline
190 QUAT_TYPE z, QUAT_TYPE w)
192 QUAT_TYPE rTmp = QUAT_TYPE(sqrt(x * x + y * y + z * z));
194 if(rTmp > QUATERNION_EPSILON)
196 rTmp = QUAT_TYPE(sin(w / 2.0f)) / rTmp;
198 (*this)[0] = x * rTmp;
199 (*this)[1] = y * rTmp;
200 (*this)[2] = z * rTmp;
201 (*this)[3] = QUAT_TYPE(cos(w / 2.0f));
209 template <
class QUAT_TYPE>
inline
214 const QUAT_TYPE s = 1 / ((*this)[3] + ((*this)[3] < 0 ? -1 : 1));
215 p3D[0] = s * (*this)[0];
216 p3D[1] = s * (*this)[1];
217 p3D[2] = s * (*this)[2];
220 template <
class QUAT_TYPE>
inline
224 const QUAT_TYPE s = 2 / (p3D[0]*p3D[0] + p3D[1]*p3D[1] + p3D[2]*p3D[2] + 1);
225 (*this)[0] = s * p3D[0];
226 (*this)[1] = s * p3D[1];
227 (*this)[2] = s * p3D[2];
void Invert()
inverts this, by changing the rotation axis by *=-1
void Mult(const Quaternion< QUAT_TYPE > &quat)
quaternion multiplication: this= this * quat
class Vector3 contains a Vector of fixed dim.
class for rotation with axis and angle