static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { if (event->type != NDOF_MOTION) return OPERATOR_CANCELLED; else { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); float pan_vec[3]; 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, (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]; sc->yof += pan_vec[1]; ED_region_tag_redraw(ar); return OPERATOR_FINISHED; } }
static int view_zoom_exec(bContext *C, wmOperator *op) { sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static int view_zoom_out_exec(bContext *C, wmOperator *op) { float location[2]; RNA_float_get_array(op->ptr, "location", location); sclip_zoom_set_factor(C, 0.8f, location); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static void sclip_zoom_set_factor_exec(bContext *C, const wmEvent *event, float factor) { ARegion *ar = CTX_wm_region(C); float location[2], *mpos = NULL; if (event) { SpaceClip *sc = CTX_wm_space_clip(C); ED_clip_mouse_pos(sc, ar, event->mval, location); mpos = location; } sclip_zoom_set_factor(C, factor, mpos); ED_region_tag_redraw(ar); }
static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const 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; } }