BLI_math: add mat3_normalized_to_* functions

Many uses of matrices for rotation keep them normalized,
so no need to normalize each time.
This commit is contained in:
2015-10-24 07:02:51 +11:00
parent 3a98426ed6
commit fbca69c69a
10 changed files with 204 additions and 107 deletions

View File

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