diff options
author | Campbell Barton <campbell@blender.org> | 2022-08-25 05:45:43 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-08-25 06:48:31 +0300 |
commit | a7650c6206908a8865d6140a310809ec5ab0c770 (patch) | |
tree | 63137fb4cb772daafe5683a86b5496361e83deae /source/blender/editors/space_view3d | |
parent | 8593228a13d38057a5d849f46d5cc0ab23fb1405 (diff) |
BLI_math: ensure non-negative matrices for mat3_to_quat calculations
Making the callers responsible for this isn't practical as matrices are
often passed indirectly to a functions such as mat3_to_axis_angle,
BKE_object_mat3_to_rot & BKE_pchan_mat3_to_rot.
Or the matrix is combined from other matrices which could be negative.
Given quaternions calculated from negative matrices are completely
invalid and checking only needs to negate matrices with a negative
determinant, move the check into mat3_to_quat and related functions.
Add mat3_normalized_to_quat_fast for cases no error checking on the
input matrix is needed such as blending rotations.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_utils.c | 11 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 6 |
2 files changed, 5 insertions, 12 deletions
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 5154c2d4f52..cb716391fb2 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -1485,18 +1485,15 @@ void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], const negate_v3_v3(ofs, mat[3]); } - if (ofs && dist) { - madd_v3_v3fl(ofs, nmat[2], *dist); - } - /* Quat */ if (quat) { - if (is_negative_m3(nmat)) { - negate_m3(nmat); - } mat3_normalized_to_quat(quat, nmat); invert_qt_normalized(quat); } + + if (ofs && dist) { + madd_v3_v3fl(ofs, nmat[2], *dist); + } } void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], const float dist) diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 05922ba7a95..b8042a9f215 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -369,11 +369,7 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob) invert_m4_m4(rv3d->viewmat, bmat); /* view quat calculation, needed for add object */ - copy_m4_m4(bmat, rv3d->viewmat); - if (is_negative_m4(bmat)) { - negate_m4(bmat); - } - mat4_normalized_to_quat(rv3d->viewquat, bmat); + mat4_normalized_to_quat(rv3d->viewquat, rv3d->viewmat); } void view3d_viewmatrix_set(Depsgraph *depsgraph, |