[Bf-blender-cvs] [e4e80058c8d] master: Cleanup: simplify calculation of NDOF pan/zoom in 2D views

Campbell Barton noreply at git.blender.org
Fri Oct 14 07:42:49 CEST 2022


Commit: e4e80058c8d8a8c00bcb767b8be3689918c9201f
Author: Campbell Barton
Date:   Fri Oct 14 16:32:29 2022 +1100
Branches: master
https://developer.blender.org/rBe4e80058c8d8a8c00bcb767b8be3689918c9201f

Cleanup: simplify calculation of NDOF pan/zoom in 2D views

Make the logic for converting NDOF Z-motion to a scale value more
straightforward. Flipping the Z axis was scaling by negative-time,
now the entire pan vector is scaled by time and the zoom value is
calculated as `scale = 1 - (z * time)` instead of `1 + (z * -time)`.
Although they're equivalent, confusion here caused T100953.

Also clamp the scale (while unlikely, negative scale wasn't prevented).

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

M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_view3d/view3d_navigate_ndof.c

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

diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 2b107b423e5..a625c124dd3 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -1641,14 +1641,14 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
   float pan_vec[3];
 
   const wmNDOFMotionData *ndof = event->customdata;
-  const float speed = NDOF_PIXELS_PER_SECOND;
+  const float pan_speed = NDOF_PIXELS_PER_SECOND;
 
   WM_event_ndof_pan_get(ndof, pan_vec, true);
 
-  mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom);
-  pan_vec[2] *= -ndof->dt;
+  mul_v3_fl(pan_vec, ndof->dt);
+  mul_v2_fl(pan_vec, pan_speed / sc->zoom);
 
-  sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL, false);
+  sclip_zoom_set_factor(C, max_ff(0.0f, 1.0f - pan_vec[2]), NULL, false);
   sc->xof += pan_vec[0];
   sc->yof += pan_vec[1];
 
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index bb47ad5c6c0..3503c4c8168 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -762,14 +762,14 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
   float pan_vec[3];
 
   const wmNDOFMotionData *ndof = event->customdata;
-  const float speed = NDOF_PIXELS_PER_SECOND;
+  const float pan_speed = NDOF_PIXELS_PER_SECOND;
 
   WM_event_ndof_pan_get(ndof, pan_vec, true);
 
-  mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom);
-  pan_vec[2] *= -ndof->dt;
+  mul_v3_fl(pan_vec, ndof->dt);
+  mul_v2_fl(pan_vec, pan_speed / sima->zoom);
 
-  sima_zoom_set_factor(sima, region, 1.0f + pan_vec[2], NULL, false);
+  sima_zoom_set_factor(sima, region, max_ff(0.0f, 1.0f - pan_vec[2]), NULL, false);
   sima->xof += pan_vec[0];
   sima->yof += pan_vec[1];
 
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index 29e63a72daf..9fb33013c4e 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -370,14 +370,17 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
     return OPERATOR_PASS_THROUGH;
   }
 
+  const float pan_speed = NDOF_PIXELS_PER_SECOND;
   const bool has_translate = !is_zero_v2(ndof->tvec);
   const bool has_zoom = ndof->tvec[2] != 0.0f;
 
   float pan_vec[3];
   WM_event_ndof_pan_get(ndof, pan_vec, true);
 
-  mul_v2_fl(pan_vec, ndof->dt);
-  pan_vec[2] *= -ndof->dt;
+  mul_v3_fl(pan_vec, ndof->dt);
+  /* NOTE: unlike image and clip views, the 2D pan doesn't have to be scaled by the zoom level.
+   * #ED_view3d_camera_view_pan already takes the zoom level into account. */
+  mul_v2_fl(pan_vec, pan_speed);
 
   /* NOTE(@campbellbarton): In principle rotating could pass through to regular
    * non-camera NDOF behavior (exiting the camera-view and rotating).
@@ -393,16 +396,14 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
   bool changed = false;
 
   if (has_translate) {
-    const float speed = NDOF_PIXELS_PER_SECOND;
-    float event_ofs[2] = {pan_vec[0] * speed, pan_vec[1] * speed};
-    if (ED_view3d_camera_view_pan(region, event_ofs)) {
+    /* Use the X & Y of `pan_vec`. */
+    if (ED_view3d_camera_view_pan(region, pan_vec)) {
       changed = true;
     }
   }
 
   if (has_zoom) {
-    const float scale = 1.0f + pan_vec[2];
-    if (ED_view3d_camera_view_zoom_scale(rv3d, scale)) {
+    if (ED_view3d_camera_view_zoom_scale(rv3d, max_ff(0.0f, 1.0f - pan_vec[2]))) {
       changed = true;
     }
   }



More information about the Bf-blender-cvs mailing list