NDOF navigation support for clip editor

This commit is contained in:
Sergey Sharybin 2012-08-12 12:15:23 +00:00
parent a39329be5c
commit ed564d7cb7
3 changed files with 65 additions and 0 deletions

@ -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);

@ -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)

@ -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);