diff options
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 10b8cb238aa..ea8c7fc0cfa 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -437,6 +437,63 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) "Factor", "Zoom factor, values higher than 1.0 zoom in, lower values zoom out.", -FLT_MAX, FLT_MAX); } +/********************** 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 view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) +{ + if (event->type != NDOF_MOTION) + return OPERATOR_CANCELLED; + else { + SpaceImage *sima= CTX_wm_space_image(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.f; // screen pixels per second + + float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom; + float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->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.f + zoom_sensitivity * dt * -ndof->tvec[2]; + + if (U.ndof_flag & NDOF_ZOOM_INVERT) + zoom_factor = -zoom_factor; + + sima_zoom_set_factor(sima, ar, zoom_factor); + sima->xof += pan_x; + sima->yof += pan_y; + + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } +} + +void IMAGE_OT_view_ndof(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "NDOF Pan/Zoom"; + ot->idname= "IMAGE_OT_view_ndof"; + + /* api callbacks */ + ot->invoke= view_ndof_invoke; +} + /********************** view all operator *********************/ /* Updates the fields of the View2D member of the SpaceImage struct. @@ -500,7 +557,7 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene; Object *obedit; Image *ima; - float size, min[2], max[2], d[2]; + float size, min[2], max[2], d[2], aspx, aspy; int width, height; /* retrieve state */ @@ -511,6 +568,10 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) ima= ED_space_image(sima); ED_space_image_size(sima, &width, &height); + ED_image_aspect(ima, &aspx, &aspy); + + width= width*aspx; + height= height*aspy; /* get bounds */ if(!ED_uvedit_minmax(scene, ima, obedit, min, max)) |