[Bf-blender-cvs] [4db7842a72c] master: BLI_math: use fallback for compatible quaternion calculation

Campbell Barton noreply at git.blender.org
Tue Mar 19 07:45:04 CET 2019


Commit: 4db7842a72cc2f9cdca31c08d45c703ad8519dc0
Author: Campbell Barton
Date:   Tue Mar 19 17:39:14 2019 +1100
Branches: master
https://developer.blender.org/rB4db7842a72cc2f9cdca31c08d45c703ad8519dc0

BLI_math: use fallback for compatible quaternion calculation

Copy the new value when the compatible quaternion isn't usable.

===================================================================

M	source/blender/blenlib/intern/math_rotation.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index d52c8f54096..5f6bbcce3b3 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -207,14 +207,20 @@ void pow_qt_fl_normalized(float q[4], const float fac)
  */
 void quat_to_compatible_quat(float q[4], const float a[4], const float old[4])
 {
+	const float eps = 1e-4f;
 	BLI_ASSERT_UNIT_QUAT(a);
-	float delta[4];
 	float old_unit[4];
-	normalize_qt_qt(old_unit, old);
-	rotation_between_quats_to_quat(delta, old_unit, a);
-	mul_qt_qtqt(q, old, delta);
-	if ((q[0] < 0.0f) != (old[0] < 0.0f)) {
-		negate_v4(q);
+	/* Skips `!finite_v4(old)` case too. */
+	if (normalize_qt_qt(old_unit, old) > eps) {
+		float delta[4];
+		rotation_between_quats_to_quat(delta, old_unit, a);
+		mul_qt_qtqt(q, old, delta);
+		if ((q[0] < 0.0f) != (old[0] < 0.0f)) {
+			negate_v4(q);
+		}
+	}
+	else {
+		copy_qt_qt(q, a);
 	}
 }



More information about the Bf-blender-cvs mailing list