refactor: use Quat and BCQuat instead of float[4] arrays for Quaternions (wip)

This commit is contained in:
Gaia Clary 2019-05-28 22:08:23 +02:00
parent d04622e427
commit 0bcf29b8cd
4 changed files with 29 additions and 12 deletions

View File

@ -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]);
}

View File

@ -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);

View File

@ -52,6 +52,9 @@ class BCQuat {
{
return q;
}
void rotate_to(Matrix &mat_to);
};
class BCMatrix {

View File

@ -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 :