View3D: avoid jumping placing cursor /w lock on

The view would jump each time, now compensate by adjusting the cursor panning.
Less jarring and helps avoid problems when the cursor gets outside the view, see: T40353
This commit is contained in:
Campbell Barton 2015-06-07 02:45:26 +10:00
parent 60621940d0
commit c5748f3cc7
Notes: blender-bot 2023-02-14 10:35:25 +01:00
Referenced by issue #45313, Lock to Curser is not working
Referenced by issue #45301, Lock wiew to cursor not working
Referenced by issue #44979, Blender 2.75 test build crashes on render - Blender internal - 2.74 renders this scene ok
Referenced by issue #40353, Lock to Cursor
1 changed files with 23 additions and 4 deletions

View File

@ -4607,7 +4607,7 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
Scene *scene = CTX_data_scene(C);
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
RegionView3D *rv3d = ar->regiondata;
bool flip;
bool depth_used = false;
@ -4642,9 +4642,28 @@ void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
float *fp = ED_view3d_cursor3d_get(scene, v3d);
ED_view3d_cursor3d_position(C, fp, mval);
float *fp_curr = ED_view3d_cursor3d_get(scene, v3d);
float fp_prev[3];
copy_v3_v3(fp_prev, fp_curr);
ED_view3d_cursor3d_position(C, fp_curr, mval);
/* offset the cursor lock to avoid jumping to new offset */
if (v3d->ob_centre_cursor) {
ARegion *ar = CTX_wm_region(C);
RegionView3D *rv3d = ar->regiondata;
float co_curr[2], co_prev[2];
if ((ED_view3d_project_float_global(ar, fp_prev, co_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
(ED_view3d_project_float_global(ar, fp_curr, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
{
rv3d->ofs_lock[0] += (co_curr[0] - co_prev[0]) / (ar->winx * 0.5f);
rv3d->ofs_lock[1] += (co_curr[1] - co_prev[1]) / (ar->winy * 0.5f);
}
}
if (v3d && v3d->localvd)
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
@ -4670,7 +4689,7 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot)
/* api callbacks */
ot->invoke = view3d_cursor3d_invoke;
ot->poll = ED_operator_view3d_active;
ot->poll = ED_operator_region_view3d_active;
/* flags */
// ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;