From fbca69c69afb370ddc5a0b52e10d9db61c025752 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 24 Oct 2015 07:02:51 +1100 Subject: BLI_math: add mat3_normalized_to_* functions Many uses of matrices for rotation keep them normalized, so no need to normalize each time. --- source/blender/python/mathutils/mathutils_Matrix.c | 18 +++++++++--------- source/blender/python/mathutils/mathutils_Quaternion.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source/blender/python/mathutils') diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 41baa9b089f..7ad20d41bf1 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -1120,8 +1120,7 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) float eul[3], eul_compatf[3]; EulerObject *eul_compat = NULL; - float tmat[3][3]; - float (*mat)[3]; + float mat[3][3]; if (BaseMath_ReadCallback(self) == -1) return NULL; @@ -1138,11 +1137,10 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) /*must be 3-4 cols, 3-4 rows, square matrix */ if (self->num_row == 3 && self->num_col == 3) { - mat = (float (*)[3])self->matrix; + copy_m3_m3(mat, (float (*)[3])self->matrix); } else if (self->num_row == 4 && self->num_col == 4) { - copy_m3_m4(tmat, (float (*)[4])self->matrix); - mat = tmat; + copy_m3_m4(mat, (float (*)[4])self->matrix); } else { PyErr_SetString(PyExc_ValueError, @@ -1158,13 +1156,15 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) return NULL; } + normalize_m3(mat); + if (eul_compat) { - if (order == 1) mat3_to_compatible_eul(eul, eul_compatf, mat); - else mat3_to_compatible_eulO(eul, eul_compatf, order, mat); + if (order == 1) mat3_normalized_to_compatible_eul(eul, eul_compatf, mat); + else mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat); } else { - if (order == 1) mat3_to_eul(eul, mat); - else mat3_to_eulO(eul, order, mat); + if (order == 1) mat3_normalized_to_eul(eul, mat); + else mat3_normalized_to_eulO(eul, order, mat); } return Euler_CreatePyObject(eul, order, NULL); diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 1752be6e306..898a002cf09 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -115,8 +115,8 @@ static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args) quat_to_mat3(mat, tquat); - if (order == EULER_ORDER_XYZ) mat3_to_compatible_eul(eul, eul_compat->eul, mat); - else mat3_to_compatible_eulO(eul, eul_compat->eul, order, mat); + if (order == EULER_ORDER_XYZ) mat3_normalized_to_compatible_eul(eul, eul_compat->eul, mat); + else mat3_normalized_to_compatible_eulO(eul, eul_compat->eul, order, mat); } else { if (order == EULER_ORDER_XYZ) quat_to_eul(eul, tquat); -- cgit v1.2.3