From 0a0f53ffda0a609a843372fbf7d854a72df54c22 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 23 Jun 2002 00:02:10 +0000 Subject: [PATCH] fix quaternion multiply order --- panda/src/linmath/lquaternion_src.I | 12 ++++++------ panda/src/linmath/lquaternion_src.cxx | 4 ++-- panda/src/pgraph/transformState.cxx | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/panda/src/linmath/lquaternion_src.I b/panda/src/linmath/lquaternion_src.I index 05054949fe..80a1cc95e0 100644 --- a/panda/src/linmath/lquaternion_src.I +++ b/panda/src/linmath/lquaternion_src.I @@ -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); } diff --git a/panda/src/linmath/lquaternion_src.cxx b/panda/src/linmath/lquaternion_src.cxx index 400fca176f..9796514e1d 100644 --- a/panda/src/linmath/lquaternion_src.cxx +++ b/panda/src/linmath/lquaternion_src.cxx @@ -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 diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index eb429c3d3c..2add73f293 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -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(); }