From 0bcf29b8cd9dc2c99f3f63c7761fe9e1223641ef Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Tue, 28 May 2019 22:08:23 +0200 Subject: refactor: use Quat and BCQuat instead of float[4] arrays for Quaternions (wip) --- source/blender/collada/AnimationImporter.cpp | 18 ++++++++---------- source/blender/collada/BCMath.cpp | 18 ++++++++++++++++++ source/blender/collada/BCMath.h | 3 +++ source/blender/collada/TransformWriter.cpp | 2 -- 4 files changed, 29 insertions(+), 12 deletions(-) (limited to 'source/blender/collada') diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 311df47cdd5..4c96ebf2603 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -1313,8 +1313,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, std::sort(frames.begin(), frames.end()); - float qref[4]; - unit_qt(qref); + BCQuat qref; std::vector::iterator it; @@ -1322,8 +1321,8 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, for (it = frames.begin(); it != frames.end(); it++) { float fra = *it; - float mat[4][4]; - float matfra[4][4]; + Matrix mat; + Matrix matfra; unit_m4(matfra); @@ -1335,7 +1334,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, * where R, iR are bone rest and inverse rest mats in world space (Blender bones), * iR_dae is joint inverse rest matrix (DAE) * and M is an evaluated joint world-space matrix (DAE). */ - float temp[4][4], par[4][4]; + Matrix temp, par; /* calc M */ calc_joint_parent_mat_rest(par, NULL, root, node); @@ -1346,10 +1345,9 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, /* calc special matrix */ mul_m4_series(mat, irest, temp, irest_dae, rest); - float rot[4], loc[3], scale[3]; + Vector loc, scale; - bc_rotate_from_reference_quat(rot, qref, mat); - copy_qt_qt(qref, rot); + qref.rotate_to(mat); copy_v3_v3(loc, mat[3]); mat4_to_size(scale, mat); @@ -1357,8 +1355,8 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, /* add keys */ for (int i = 0; i < totcu; i++) { if (i < 4) { - add_bezt(newcu[i], fra, rot[i]); - } + add_bezt(newcu[i], fra, qref.quat()[i]); + } else if (i < 7) { add_bezt(newcu[i], fra, loc[i - 4]); } diff --git a/source/blender/collada/BCMath.cpp b/source/blender/collada/BCMath.cpp index a07d1e735ff..31f8bd1c2bc 100644 --- a/source/blender/collada/BCMath.cpp +++ b/source/blender/collada/BCMath.cpp @@ -20,6 +20,24 @@ #include "BCMath.h" #include "BlenderContext.h" +void BCQuat::rotate_to(Matrix &mat_to) +{ + Quat qd; + Matrix matd; + Matrix mati; + Matrix mat_from; + + quat_to_mat4(mat_from, q); + + /* Calculate the difference matrix matd between mat_from and mat_to */ + invert_m4_m4(mati, mat_from); + mul_m4_m4m4(matd, mati, mat_to); + + mat4_to_quat(qd, matd); + + mul_qt_qtqt(q, qd, q); /* rotate to the final rotation to mat_to */ +} + BCMatrix::BCMatrix(const BCMatrix &mat) { set_transform(mat.matrix); diff --git a/source/blender/collada/BCMath.h b/source/blender/collada/BCMath.h index 00e8f24c970..cc2ce7ce315 100644 --- a/source/blender/collada/BCMath.h +++ b/source/blender/collada/BCMath.h @@ -52,6 +52,9 @@ class BCQuat { { return q; } + + void rotate_to(Matrix &mat_to); + }; class BCMatrix { diff --git a/source/blender/collada/TransformWriter.cpp b/source/blender/collada/TransformWriter.cpp index d3e97e5c7fa..931801e38ce 100644 --- a/source/blender/collada/TransformWriter.cpp +++ b/source/blender/collada/TransformWriter.cpp @@ -27,7 +27,6 @@ static BC_export_transformation_type get_transformation_type(BCExportSettings &export_settings) { - BC_export_transformation_type transformation_type; bool enforce_matrix_export = export_settings.get_include_animations(); return (enforce_matrix_export) ? BC_TRANSFORMATION_TYPE_MATRIX : @@ -37,7 +36,6 @@ static BC_export_transformation_type get_transformation_type(BCExportSettings &e static BC_export_transformation_type get_transformation_type(Object *ob, BCExportSettings &export_settings) { - BC_export_transformation_type transformation_type; bool enforce_matrix_export = ob->type == OB_ARMATURE && export_settings.get_include_animations(); return (enforce_matrix_export) ? BC_TRANSFORMATION_TYPE_MATRIX : -- cgit v1.2.3