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 08:50:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-19 08:54:37 +0300
commite2ec045cc995bb8767a5f88e8830aa1062921011 (patch)
treeb1ee252419b89c8b109843eaf0673d82372e4586 /source/blender/blenlib/intern/math_rotation.c
parente7fd6c8f30cd1161496831859da403eaa34fdf89 (diff)
BLI_math: add utility to calculate compatible quaternions
Diffstat (limited to 'source/blender/blenlib/intern/math_rotation.c')
-rw-r--r--source/blender/blenlib/intern/math_rotation.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index a348edaece8..d52c8f54096 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -201,6 +201,23 @@ void pow_qt_fl_normalized(float q[4], const float fac)
normalize_v3_length(q + 1, si);
}
+/**
+ * Apply the rotation of \a a to \a q keeping the values compatible with \a old.
+ * Avoid axis flipping for animated f-curves for eg.
+ */
+void quat_to_compatible_quat(float q[4], const float a[4], const float old[4])
+{
+ 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);
+ }
+}
+
/* skip error check, currently only needed by mat3_to_quat_is_ok */
static void quat_to_mat3_no_error(float m[3][3], const float q[4])
{