mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
fix quaternion multiply order
This commit is contained in:
parent
c1823b75ca
commit
0a0f53ffda
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user