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:
authorGaia Clary <gaia.clary@machinimatrix.org>2019-05-28 23:08:23 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2019-06-03 00:00:57 +0300
commit0bcf29b8cd9dc2c99f3f63c7761fe9e1223641ef (patch)
treeb16f5aa57f4204004d2ff97275cf3eb4cd39b18d /source/blender/collada
parentd04622e427c2e017fd6ea0c9a915168cee40c798 (diff)
refactor: use Quat and BCQuat instead of float[4] arrays for Quaternions (wip)
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/AnimationImporter.cpp18
-rw-r--r--source/blender/collada/BCMath.cpp18
-rw-r--r--source/blender/collada/BCMath.h3
-rw-r--r--source/blender/collada/TransformWriter.cpp2
4 files changed, 29 insertions, 12 deletions
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<float>::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 :