18 #ifndef TF2_QUATERNION_H_
19 #define TF2_QUATERNION_H_
38 : QuadWord(x, y, z, w)
53 #ifndef TF2_EULER_DEFAULT_ZYX
67 setValue(axis.x() *
s, axis.y() *
s, axis.z() *
s,
85 setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
86 cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
87 sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
88 cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
105 setValue(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
106 cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
107 cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
108 cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
122 m_floats[0] += q.x(); m_floats[1] += q.y(); m_floats[2] += q.z(); m_floats[3] += q.m_floats[3];
130 m_floats[0] -= q.x(); m_floats[1] -= q.y(); m_floats[2] -= q.z(); m_floats[3] -= q.m_floats[3];
138 m_floats[0] *=
s; m_floats[1] *=
s; m_floats[2] *=
s; m_floats[3] *=
s;
147 setValue(m_floats[3] * q.x() + m_floats[0] * q.m_floats[3] + m_floats[1] * q.z() - m_floats[2] * q.y(),
148 m_floats[3] * q.y() + m_floats[1] * q.m_floats[3] + m_floats[2] * q.x() - m_floats[0] * q.z(),
149 m_floats[3] * q.z() + m_floats[2] * q.m_floats[3] + m_floats[0] * q.y() - m_floats[1] * q.x(),
150 m_floats[3] * q.m_floats[3] - m_floats[0] * q.x() - m_floats[1] * q.y() - m_floats[2] * q.z());
157 return m_floats[0] * q.x() + m_floats[1] * q.y() + m_floats[2] * q.z() + m_floats[3] * q.m_floats[3];
239 if (m_floats[3] >= 0)
254 return Vector3(m_floats[0] /
s, m_floats[1] /
s, m_floats[2] /
s);
260 return Quaternion(-m_floats[0], -m_floats[1], -m_floats[2], m_floats[3]);
269 return Quaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_floats[3] + q2.m_floats[3]);
278 return Quaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_floats[3] - q2.m_floats[3]);
286 return Quaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_floats[3]);
294 if( diff.dot(diff) > sum.dot(sum) )
305 if( diff.dot(diff) < sum.dot(sum) )
324 return Quaternion((m_floats[0] * s0 + -q.x() * s1) *
d,
325 (m_floats[1] * s0 + -q.y() * s1) *
d,
326 (m_floats[2] * s0 + -q.z() * s1) *
d,
327 (m_floats[3] * s0 + -q.m_floats[3] * s1) *
d);
329 return Quaternion((m_floats[0] * s0 + q.x() * s1) *
d,
330 (m_floats[1] * s0 + q.y() * s1) *
d,
331 (m_floats[2] * s0 + q.z() * s1) *
d,
332 (m_floats[3] * s0 + q.m_floats[3] * s1) *
d);
357 return Quaternion(-q.x(), -q.y(), -q.z(), -q.w());
365 return Quaternion(q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(),
366 q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(),
367 q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(),
368 q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z());
374 return Quaternion( q.w() * w.x() + q.y() * w.z() - q.z() * w.y(),
375 q.w() * w.y() + q.z() * w.x() - q.x() * w.z(),
376 q.w() * w.z() + q.x() * w.y() - q.y() * w.x(),
377 -q.x() * w.x() - q.y() * w.y() - q.z() * w.z());
383 return Quaternion( w.x() * q.w() + w.y() * q.z() - w.z() * q.y(),
384 w.y() * q.w() + w.z() * q.x() - w.x() * q.z(),
385 w.z() * q.w() + w.x() * q.y() - w.y() * q.x(),
386 -w.x() * q.x() - w.y() * q.y() - w.z() * q.z());
415 return q1.angleShortestPath(q2);
433 return q1.slerp(q2,
t);
440 q *= rotation.inverse();
441 return Vector3(q.getX(),q.getY(),q.getZ());