NDOF: fix for view3d ignoring lens values when panning
authorCampbell Barton <ideasman42@gmail.com>
Sat, 22 Feb 2014 05:19:02 +0000 (16:19 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 22 Feb 2014 05:30:48 +0000 (16:30 +1100)
image, mce, view2d and view3d now have matching pan speed.

source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/view2d_ops.c
source/blender/editors/space_clip/clip_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_fly.c
source/blender/editors/space_view3d/view3d_walk.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/windowmanager/intern/wm_event_system.c

index ce15188132db060ff0487104ec8ca34ac61a5863..05b31c016f8c93f6fc6896684e7560b1c7608f57 100644 (file)
@@ -4386,7 +4386,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
 }
 
 static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
-                                    wmNDOFMotionData *ndof,
+                                    const wmNDOFMotionData *ndof,
                                     const enum eSnapType snap, const bool shift)
 {
        float *hsv = ui_block_hsv_get(but->block);
@@ -4480,7 +4480,7 @@ static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
                        return WM_UI_HANDLER_BREAK;
                }
                else if (event->type == NDOF_MOTION) {
-                       wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+                       const wmNDOFMotionData *ndof = event->customdata;
                        const enum eSnapType snap = ui_event_to_snap(event);
                        
                        ui_ndofedit_but_HSVCUBE(but, data, ndof, snap, event->shift != 0);
@@ -4630,7 +4630,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 }
 
 static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
-                                      wmNDOFMotionData *ndof,
+                                      const wmNDOFMotionData *ndof,
                                       const enum eSnapType snap, const bool shift)
 {
        float *hsv = ui_block_hsv_get(but->block);
@@ -4712,7 +4712,7 @@ static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandle
                }
                else if (event->type == NDOF_MOTION) {
                        const enum eSnapType snap = ui_event_to_snap(event);
-                       wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+                       const wmNDOFMotionData *ndof = event->customdata;
                        
                        ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->shift != 0);
 
index a8f01b7aa5a46b563ba97aa57cd615eee6f74585..1f63ad87b372cb2a9d51228155c0e79abdadfe6c 100644 (file)
@@ -1262,12 +1262,11 @@ static int view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                return OPERATOR_CANCELLED;
        }
        else {
-               wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+               const wmNDOFMotionData *ndof = event->customdata;
 
-               float dt = ndof->dt;
                /* tune these until it feels right */
                const float zoom_sensitivity = 0.5f;
-               const float pan_sensitivity = 10.0f; /* match view3d ortho */
+               const float speed = 10.0f;  /* match view3d ortho */
                const bool has_translate = (ndof->tvec[0] && ndof->tvec[1]) && view_pan_poll(C);
                const bool has_zoom = (ndof->tvec[2] != 0.0f) && view_zoom_poll(C);
 
@@ -1278,8 +1277,8 @@ static int view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
                                WM_event_ndof_pan_get(ndof, pan_vec, false);
 
-                               pan_vec[0] *= pan_sensitivity;
-                               pan_vec[1] *= pan_sensitivity;
+                               pan_vec[0] *= speed;
+                               pan_vec[1] *= speed;
 
                                vpd = op->customdata;
 
@@ -1292,7 +1291,7 @@ static int view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                if (has_zoom) {
                        if (view_zoomdrag_init(C, op)) {
                                v2dViewZoomData *vzd;
-                               float zoom_factor = zoom_sensitivity * dt * -ndof->tvec[2];
+                               float zoom_factor = zoom_sensitivity * ndof->dt * -ndof->tvec[2];
 
                                bool do_zoom_xy[2];
 
index 6767f92d338d7a74f9dba6781d0bded9710d5a7d..7ee94fe92fce1c99e0868b96e5d1dad9ae8f5150 100644 (file)
@@ -1335,24 +1335,13 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
                ARegion *ar = CTX_wm_region(C);
                float pan_vec[3];
 
-               wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
-
-               float dt = ndof->dt;
-
-               /* tune these until it feels right */
-               const float pan_sensitivity = 300.0f;  /* screen pixels per second */
-
-               /* "mouse zoom" factor = 1 + (dx + dy) / 300
-                * what about "ndof zoom" factor? should behave like this:
-                * at rest -> factor = 1
-                * move forward -> factor > 1
-                * move backward -> factor < 1
-                */
+               const wmNDOFMotionData *ndof = event->customdata;
+               const float speed = NDOF_PIXELS_PER_SECOND;
 
                WM_event_ndof_pan_get(ndof, pan_vec, true);
 
-               mul_v2_fl(pan_vec, (pan_sensitivity * dt) / sc->zoom);
-               pan_vec[2] *= -dt;
+               mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom);
+               pan_vec[2] *= -ndof->dt;
 
                sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL);
                sc->xof += pan_vec[0];
index 29448a2c5cdea097337800eb38c0f9c7e9d21480..bb7a9b9a4baca5da57e9160192e2309a40252c01 100644 (file)
@@ -601,24 +601,13 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
                ARegion *ar = CTX_wm_region(C);
                float pan_vec[3];
 
-               wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
-
-               float dt = ndof->dt;
-
-               /* tune these until it feels right */
-               const float pan_sensitivity = 300.0f;  /* screen pixels per second */
-
-               /* "mouse zoom" factor = 1 + (dx + dy) / 300
-                * what about "ndof zoom" factor? should behave like this:
-                * at rest -> factor = 1
-                * move forward -> factor > 1
-                * move backward -> factor < 1
-                */
+               const wmNDOFMotionData *ndof = event->customdata;
+               const float speed = NDOF_PIXELS_PER_SECOND;
 
                WM_event_ndof_pan_get(ndof, pan_vec, true);
 
-               mul_v2_fl(pan_vec, (pan_sensitivity * dt) / sima->zoom);
-               pan_vec[2] *= -dt;
+               mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom);
+               pan_vec[2] *= -ndof->dt;
 
                sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL);
                sima->xof += pan_vec[0];
index faee6514616ab60fbaaf3a53f81fc9cd22512f87..77b0e945c9cdc755704f207d8bd9b36e2e88cfd8 100644 (file)
@@ -1151,6 +1151,17 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
 #define NDOF_HAS_TRANSLATE ((!ED_view3d_offset_lock_check(v3d, rv3d)) && !is_zero_v3(ndof->tvec))
 #define NDOF_HAS_ROTATE    (((rv3d->viewlock & RV3D_LOCKED) == 0) && !is_zero_v3(ndof->rvec))
 
+static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d)
+{
+       float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND;
+
+       if (rv3d->is_persp) {
+               speed *= ED_view3d_calc_zfac(rv3d, rv3d->ofs, NULL);
+       }
+
+       return speed;
+}
+
 /**
  * Zoom and pan in the same function since sometimes zoom is interpreted as dolly (pan forward).
  *
@@ -1160,7 +1171,6 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s
                                  const bool has_translate, const bool has_zoom)
 {
        RegionView3D *rv3d = ar->regiondata;
-       const float dt = ndof->dt;
        float view_inv[4];
        float pan_vec[3];
 
@@ -1183,7 +1193,7 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s
 
                /* "zoom in" or "translate"? depends on zoom mode in user settings? */
                if (ndof->tvec[2]) {
-                       float zoom_distance = rv3d->dist * dt * ndof->tvec[2];
+                       float zoom_distance = rv3d->dist * ndof->dt * ndof->tvec[2];
 
                        if (U.ndof_flag & NDOF_ZOOM_INVERT)
                                zoom_distance = -zoom_distance;
@@ -1201,9 +1211,9 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s
        }
 
        if (has_translate) {
-               const float speed = rv3d->dist; /* uses distance from pivot to define dolly */
+               const float speed = view3d_ndof_pan_speed_calc(rv3d);
 
-               mul_v3_fl(pan_vec, speed * dt);
+               mul_v3_fl(pan_vec, speed * ndof->dt);
 
                /* transform motion from view to world coordinates */
                invert_qt_qt(view_inv, rv3d->viewquat);
@@ -1314,9 +1324,6 @@ void view3d_ndof_fly(
         const bool use_precision, const short protectflag,
         bool *r_has_translate, bool *r_has_rotate)
 {
-       /* shorthand for oft-used variables */
-       const float dt = ndof->dt;
-
        bool has_translate = NDOF_HAS_TRANSLATE;
        bool has_rotate = NDOF_HAS_ROTATE;
 
@@ -1326,14 +1333,14 @@ void view3d_ndof_fly(
        rv3d->rot_angle = 0.0f;  /* disable onscreen rotation doo-dad */
 
        if (has_translate) {
-               float speed = 10.0f;  /* blender units per second */
+               float speed = view3d_ndof_pan_speed_calc(rv3d);
                float trans[3], trans_orig_y;
-               /* ^^ this is ok for default cube scene, but should scale with.. something */
+
                if (use_precision)
                        speed *= 0.2f;
 
                WM_event_ndof_pan_get(ndof, trans, false);
-               mul_v3_fl(trans, speed * dt);
+               mul_v3_fl(trans, speed * ndof->dt);
                trans_orig_y = trans[1];
 
                if (U.ndof_flag & NDOF_FLY_HELICOPTER) {
index 42e74be0460013e386880478c2ccc03db284a358..c8c0111d5d497699df84685e9c63b01295175cb2 100644 (file)
@@ -460,7 +460,7 @@ static void flyEvent(bContext *C, FlyInfo *fly, const wmEvent *event)
                // puts("ndof motion detected in fly mode!");
                // static const char *tag_name = "3D mouse position";
 
-               wmNDOFMotionData *incoming_ndof = (wmNDOFMotionData *)event->customdata;
+               const wmNDOFMotionData *incoming_ndof = event->customdata;
                switch (incoming_ndof->progress) {
                        case P_STARTING:
                                /* start keeping track of 3D mouse position */
index c6d0999d07769b90b4d2072a4edefe7e8f723795..7d387332174a9f89b49f6966d8c74d8ef3981680 100644 (file)
@@ -645,7 +645,7 @@ static void walkEvent(bContext *C, wmOperator *UNUSED(op), WalkInfo *walk, const
                // puts("ndof motion detected in walk mode!");
                // static const char *tag_name = "3D mouse position";
 
-               wmNDOFMotionData *incoming_ndof = (wmNDOFMotionData *)event->customdata;
+               const wmNDOFMotionData *incoming_ndof = event->customdata;
                switch (incoming_ndof->progress) {
                        case P_STARTING:
                                /* start keeping track of 3D mouse position */
index 4248efd09194241bb04e6a0b6e1079aab0578581..6faba7ccd2fcbad5538848642ee9f3a6b1b236f0 100644 (file)
@@ -801,6 +801,8 @@ typedef enum eNdof_Flag {
        NDOF_TURNTABLE          = (1 << 15),
 } eNdof_Flag;
 
+#define NDOF_PIXELS_PER_SECOND 600.0f
+
 /* compute_device_type */
 typedef enum eCompute_Device_Type {
        USER_COMPUTE_DEVICE_NONE        = 0,
index 5254bff99cd4257b5ceed664fe7eee02d93b4dc0..3298a786abcb8f008fd7ed5d060445c16559adcf 100644 (file)
@@ -540,7 +540,7 @@ void WM_event_print(const wmEvent *event)
                       event->keymap_idname, (void *)event);
 
                if (ISNDOF(event->type)) {
-                       const wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+                       const wmNDOFMotionData *ndof = event->customdata;
                        if (event->type == NDOF_MOTION) {
                                printf("   ndof: rot: (%.4f %.4f %.4f),\n"
                                       "          tx: (%.4f %.4f %.4f),\n"