fix quaternion multiply order

This commit is contained in:
David Rose 2002-06-23 00:02:10 +00:00
parent c1823b75ca
commit 0a0f53ffda
3 changed files with 10 additions and 10 deletions

View File

@ -56,7 +56,7 @@ xform(const FLOATNAME(LVecBase3) &v) const {
FLOATNAME(LQuaternion) v_quat(0.0f, v[0], v[1], v[2]);
FLOATNAME(LQuaternion) inv(_v.data[0], -_v.data[1], -_v.data[2], -_v.data[3]);
v_quat = (*this) * v_quat * inv;
v_quat = inv * v_quat * (*this);
return FLOATNAME(LVecBase3)(v_quat[1], v_quat[2], v_quat[3]);
}
@ -67,11 +67,11 @@ xform(const FLOATNAME(LVecBase3) &v) const {
// Description: actual multiply call (non virtual)
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LQuaternion) FLOATNAME(LQuaternion)::
multiply(const FLOATNAME(LQuaternion)& rhs) const {
FLOATTYPE r = (_v.data[0] * rhs._v.data[0]) - (_v.data[1] * rhs._v.data[1]) - (_v.data[2] * rhs._v.data[2]) - (_v.data[3] * rhs._v.data[3]);
FLOATTYPE i = (_v.data[1] * rhs._v.data[0]) + (_v.data[0] * rhs._v.data[1]) - (_v.data[3] * rhs._v.data[2]) + (_v.data[2] * rhs._v.data[3]);
FLOATTYPE j = (_v.data[2] * rhs._v.data[0]) + (_v.data[3] * rhs._v.data[1]) + (_v.data[0] * rhs._v.data[2]) - (_v.data[1] * rhs._v.data[3]);
FLOATTYPE k = (_v.data[3] * rhs._v.data[0]) - (_v.data[2] * rhs._v.data[1]) + (_v.data[1] * rhs._v.data[2]) + (_v.data[0] * rhs._v.data[3]);
multiply(const FLOATNAME(LQuaternion) &rhs) const {
FLOATTYPE r = (rhs._v.v._0 * _v.v._0) - (rhs._v.v._1 * _v.v._1) - (rhs._v.v._2 * _v.v._2) - (rhs._v.v._3 * _v.v._3);
FLOATTYPE i = (rhs._v.v._1 * _v.v._0) + (rhs._v.v._0 * _v.v._1) - (rhs._v.v._3 * _v.v._2) + (rhs._v.v._2 * _v.v._3);
FLOATTYPE j = (rhs._v.v._2 * _v.v._0) + (rhs._v.v._3 * _v.v._1) + (rhs._v.v._0 * _v.v._2) - (rhs._v.v._1 * _v.v._3);
FLOATTYPE k = (rhs._v.v._3 * _v.v._0) - (rhs._v.v._2 * _v.v._1) + (rhs._v.v._1 * _v.v._2) + (rhs._v.v._0 * _v.v._3);
return FLOATNAME(LQuaternion)(r, i , j, k);
}

View File

@ -106,11 +106,11 @@ set_hpr(const FLOATNAME(LVecBase3) &hpr) {
csincos(a, &s, &c);
quat_r.set(c, v[0] * s, v[1] * s, v[2] * s);
(*this) = quat_h * quat_p * quat_r;
(*this) = quat_r * quat_p * quat_h;
if (!temp_hpr_fix) {
// Compute the old, broken hpr.
(*this) = invert(quat_r) * quat_h * quat_p;
(*this) = quat_p * quat_h * invert(quat_r);
}
#ifndef NDEBUG

View File

@ -705,7 +705,7 @@ do_compose(const TransformState *other) const {
float scale = get_uniform_scale();
pos += quat.xform(other->get_pos()) * scale;
quat *= other->get_quat();
quat = other->get_quat() * quat;
quat.normalize();
scale *= other->get_uniform_scale();
@ -768,7 +768,7 @@ do_invert_compose(const TransformState *other) const {
// Now compose the inverted transform with the other transform.
if (!other->is_identity()) {
pos += quat.xform(other->get_pos()) * scale;
quat *= other->get_quat();
quat = other->get_quat() * quat;
quat.normalize();
scale *= other->get_uniform_scale();
}