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:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-08-12 16:15:23 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-08-12 16:15:23 +0400
commited564d7cb7f39853b2c79ac09cc9e010bd371576 (patch)
tree7e6d8c58e0abbc71b663caef0770d3780a0fbedc /source
parenta39329be5c8d4f0b293a98bb67a4720401c81e8d (diff)
NDOF navigation support for clip editor
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_clip/clip_intern.h2
-rw-r--r--source/blender/editors/space_clip/clip_ops.c59
-rw-r--r--source/blender/editors/space_clip/space_clip.c4
3 files changed, 65 insertions, 0 deletions
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 392367f9071..d33f77c1064 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -102,6 +102,8 @@ void CLIP_OT_change_frame(wmOperatorType *ot);
void CLIP_OT_rebuild_proxy(struct wmOperatorType *ot);
void CLIP_OT_mode_set(struct wmOperatorType *ot);
+void CLIP_OT_view_ndof(struct wmOperatorType *ot);
+
/* clip_toolbar.c */
struct ARegion *ED_clip_has_properties_region(struct ScrArea *sa);
void CLIP_OT_tools(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index b8657f9e688..9b4f3fcdd68 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -1111,6 +1111,65 @@ void CLIP_OT_mode_set(wmOperatorType *ot)
RNA_def_enum(ot->srna, "mode", clip_editor_mode_items, SC_MODE_TRACKING, "Mode", "");
}
+/********************** NDOF operator *********************/
+
+/* Combined pan/zoom from a 3D mouse device.
+ * Z zooms, XY pans
+ * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed
+ * that explains the negative signs in the code below
+ */
+
+static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
+{
+ if (event->type != NDOF_MOTION)
+ return OPERATOR_CANCELLED;
+ else {
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+
+ float dt = ndof->dt;
+
+ /* tune these until it feels right */
+ const float zoom_sensitivity = 0.5f; /* 50% per second (I think) */
+ const float pan_sensitivity = 300.0f; /* screen pixels per second */
+
+ float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sc->zoom;
+ float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sc->zoom;
+
+ /* "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
+ */
+ float zoom_factor = 1.0f + zoom_sensitivity * dt * - ndof->tvec[2];
+
+ if (U.ndof_flag & NDOF_ZOOM_INVERT)
+ zoom_factor = -zoom_factor;
+
+ sclip_zoom_set_factor(C, zoom_factor, NULL);
+ sc->xof += pan_x;
+ sc->yof += pan_y;
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+ }
+}
+
+void CLIP_OT_view_ndof(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "NDOF Pan/Zoom";
+ ot->idname = "CLIP_OT_view_ndof";
+ ot->description = "Use a 3D mouse device to pan/zoom the view";
+
+ /* api callbacks */
+ ot->invoke = clip_view_ndof_invoke;
+}
+
/********************** macroses *********************/
void ED_operatormacros_clip(void)
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 3428c47ff43..bf65429b9f4 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -438,6 +438,7 @@ static void clip_operatortypes(void)
WM_operatortype_append(CLIP_OT_change_frame);
WM_operatortype_append(CLIP_OT_rebuild_proxy);
WM_operatortype_append(CLIP_OT_mode_set);
+ WM_operatortype_append(CLIP_OT_view_ndof);
/* ** clip_toolbar.c ** */
WM_operatortype_append(CLIP_OT_tools);
@@ -602,6 +603,9 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "CLIP_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "CLIP_OT_view_ndof", NDOF_MOTION, 0, 0, 0);
+
/* jump to special frame */
kmi = WM_keymap_add_item(keymap, "CLIP_OT_frame_jump", LEFTARROWKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
RNA_enum_set(kmi->ptr, "position", 0);