Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-02-18 08:43:30 +0300
committerCampbell Barton <campbell@blender.org>2022-02-18 09:09:49 +0300
commit51975b89edfcc02131f1f8248e1b3442ea2778fa (patch)
treecb14d6f0ba68908e171af38eb81671ecb4561a00 /source
parentf33e6e0d8c607eb33b1eb0c587b4e43cde30d5e1 (diff)
3D View: Add camera view pan/zoom support for NDOF
NDOF navigation in a camera view now behaves like orthographic pan/zoom. Note that NDOF orbiting out of the camera view has been disabled, see code comment for details. Resolves T93666.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_ndof.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index ced8eca710b..67b48154e8c 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -347,6 +347,70 @@ void view3d_ndof_fly(const wmNDOFMotionData *ndof,
/** \} */
/* -------------------------------------------------------------------- */
+/** \name NDOF Camera View Support
+ * \{ */
+
+/**
+ * 2D orthographic style NDOF navigation within the camera view.
+ * Support navigating the camera view instead of leaving the camera-view and navigating in 3D.
+ */
+static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
+{
+ const wmNDOFMotionData *ndof = event->customdata;
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *region = CTX_wm_region(C);
+ RegionView3D *rv3d = region->regiondata;
+
+ ED_view3d_smooth_view_force_finish(C, v3d, region);
+
+ if ((v3d->camera && (rv3d->persp == RV3D_CAMOB) && (v3d->flag2 & V3D_LOCK_CAMERA) == 0)) {
+ /* pass */
+ }
+ else {
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ const bool has_translate = !is_zero_v2(ndof->tvec);
+ const bool has_zoom = ndof->tvec[2] != 0.0f;
+
+ /* NOTE(@campbellbarton): In principle rotating could pass through to regular
+ * non-camera NDOF behavior (exiting the camera-view and rotating).
+ * Disabled this block since in practice it's difficult to control NDOF devices
+ * to perform some rotation with absolutely no translation. Causing rotation to
+ * randomly exit from the user perspective. Adjusting the dead-zone could avoid
+ * the motion feeling *glitchy* although in my own tests even then it didn't work reliably.
+ * Leave rotating out of camera-view disabled unless it can be made to work reliably. */
+ if (!(has_translate || has_zoom)) {
+ // return OPERATOR_PASS_THROUGH;
+ }
+
+ bool changed = false;
+
+ if (has_translate) {
+ const float speed = ndof->dt * NDOF_PIXELS_PER_SECOND;
+ float event_ofs[2] = {ndof->tvec[0] * speed, ndof->tvec[1] * speed};
+ if (ED_view3d_camera_view_pan(region, event_ofs)) {
+ changed = true;
+ }
+ }
+
+ if (has_zoom) {
+ const float scale = 1.0f + (ndof->dt * ndof->tvec[2]);
+ if (ED_view3d_camera_view_zoom_scale(rv3d, scale)) {
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ ED_region_tag_redraw(region);
+ return OPERATOR_FINISHED;
+ }
+ return OPERATOR_CANCELLED;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name NDOF Orbit/Translate Operator
* \{ */
@@ -436,6 +500,11 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
return OPERATOR_CANCELLED;
}
+ const int camera_retval = view3d_ndof_cameraview_pan_zoom(C, event);
+ if (camera_retval != OPERATOR_PASS_THROUGH) {
+ return camera_retval;
+ }
+
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewOpsData *vod;
View3D *v3d;
@@ -550,6 +619,11 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *e
return OPERATOR_CANCELLED;
}
+ const int camera_retval = view3d_ndof_cameraview_pan_zoom(C, event);
+ if (camera_retval != OPERATOR_PASS_THROUGH) {
+ return camera_retval;
+ }
+
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);