[Bf-blender-cvs] [9f1c05d5cba] master: Fix matrix/quaternion conversion with negative scaled cameras

Campbell Barton noreply at git.blender.org
Thu Aug 25 04:39:16 CEST 2022


Commit: 9f1c05d5cbaaebcd6254d99cd59a78d3a2f99a04
Author: Campbell Barton
Date:   Thu Aug 25 12:38:04 2022 +1000
Branches: master
https://developer.blender.org/rB9f1c05d5cbaaebcd6254d99cd59a78d3a2f99a04

Fix matrix/quaternion conversion with negative scaled cameras

===================================================================

M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/editors/space_view3d/view3d_view.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index cb716391fb2..5154c2d4f52 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -1485,15 +1485,18 @@ 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 b8042a9f215..05922ba7a95 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -369,7 +369,11 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
   invert_m4_m4(rv3d->viewmat, bmat);
 
   /* view quat calculation, needed for add object */
-  mat4_normalized_to_quat(rv3d->viewquat, rv3d->viewmat);
+  copy_m4_m4(bmat, rv3d->viewmat);
+  if (is_negative_m4(bmat)) {
+    negate_m4(bmat);
+  }
+  mat4_normalized_to_quat(rv3d->viewquat, bmat);
 }
 
 void view3d_viewmatrix_set(Depsgraph *depsgraph,



More information about the Bf-blender-cvs mailing list