Merge pull request #10415 from tagcup/euler_hack

Fix incorrect workaround for pure Y (X) rotations in XYZ (YXZ) conven…
This commit is contained in:
Rémi Verschelde 2017-08-22 00:54:39 +02:00 committed by GitHub
commit 92410df24c

View file

@ -365,14 +365,10 @@ Vector3 Basis::get_euler_xyz() const {
if (euler.y < Math_PI * 0.5) { if (euler.y < Math_PI * 0.5) {
if (euler.y > -Math_PI * 0.5) { if (euler.y > -Math_PI * 0.5) {
//if rotation is Y-only, return a proper -pi,pi range like in x or z for the same case. //if rotation is Y-only, return a proper -pi,pi range like in x or z for the same case.
if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[0][0] < 0.0) { if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) {
euler.x = 0; euler.x = 0;
euler.y = atan2(elements[0][2], elements[0][0]);
euler.z = 0; euler.z = 0;
if (euler.y > 0.0)
euler.y = Math_PI - euler.y;
else
euler.y = -(Math_PI + euler.y);
} else { } else {
euler.x = Math::atan2(-elements[1][2], elements[2][2]); euler.x = Math::atan2(-elements[1][2], elements[2][2]);
euler.z = Math::atan2(-elements[0][1], elements[0][0]); euler.z = Math::atan2(-elements[0][1], elements[0][0]);
@ -436,15 +432,10 @@ Vector3 Basis::get_euler_yxz() const {
if (m12 < 1) { if (m12 < 1) {
if (m12 > -1) { if (m12 > -1) {
if (elements[1][0] == 0 && elements[0][1] == 0 && elements[2][2] < 0) { // use pure x rotation if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) { // use pure x rotation
real_t x = asin(-m12); euler.x = atan2(-m12, elements[1][1]);
euler.y = 0; euler.y = 0;
euler.z = 0; euler.z = 0;
if (x > 0.0)
euler.x = Math_PI - x;
else
euler.x = -(Math_PI + x);
} else { } else {
euler.x = asin(-m12); euler.x = asin(-m12);
euler.y = atan2(elements[0][2], elements[2][2]); euler.y = atan2(elements[0][2], elements[2][2]);