Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-03-19 09:39:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-19 09:43:35 +0300
commit4db7842a72cc2f9cdca31c08d45c703ad8519dc0 (patch)
treee99ef8ecd1f5e64a7e20329b0b5b574b81138d35 /source/blender/blenlib
parent40e85a603c982b96fef51212deb086f6ddb73407 (diff)
BLI_math: use fallback for compatible quaternion calculation
Copy the new value when the compatible quaternion isn't usable.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c18
1 files changed, 12 insertions, 6 deletions
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);
}
}