diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-07-19 14:54:02 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-07-19 14:54:02 +0400 |
commit | e2b7c138f6cd5e410b22acb4af96d4df6cb9c316 (patch) | |
tree | 37c2c00d168d0b6c1b40d5943a475215a6669dff /source/blender | |
parent | 2dc6b22382279deef21df3e36ae04019e3581ef8 (diff) |
patch [#36000] View lock offset (allow panning when the view is locked)
own patch
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 42 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 22 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view3d_types.h | 1 |
5 files changed, 65 insertions, 3 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index e4aa44d7d78..44eea6b138b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1009,6 +1009,14 @@ static int view3d_camera_user_poll(bContext *C) return 0; } +static int view3d_lock_poll(bContext *C) +{ + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + + return ED_view3d_offset_lock_check(v3d, rv3d); +} + static int viewrotate_cancel(bContext *C, wmOperator *op) { viewops_data_free(C, op); @@ -1537,7 +1545,11 @@ void viewmove_modal_keymap(wmKeyConfig *keyconf) static void viewmove_apply(ViewOpsData *vod, int x, int y) { - if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) { + if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) { + vod->rv3d->ofs_lock[0] -= ((vod->oldx - x) * 2.0f) / (float)vod->ar->winx; + vod->rv3d->ofs_lock[1] -= ((vod->oldy - y) * 2.0f) / (float)vod->ar->winy; + } + else if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) { const float zoomfac = BKE_screen_view3d_zoom_to_fac((float)vod->rv3d->camzoom) * 2.0f; vod->rv3d->camdx += (vod->oldx - x) / (vod->ar->winx * zoomfac); vod->rv3d->camdy += (vod->oldy - y) / (vod->ar->winy * zoomfac); @@ -1614,8 +1626,6 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod; - VIEW3D_OP_OFS_LOCK_TEST(C, op); - /* makes op->customdata */ viewops_data_create(C, op, event); vod = op->customdata; @@ -2792,6 +2802,32 @@ void VIEW3D_OT_view_center_camera(wmOperatorType *ot) ot->flag = 0; } +static int view3d_center_lock_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */ +{ + RegionView3D *rv3d = CTX_wm_region_view3d(C); + + zero_v2(rv3d->ofs_lock); + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C)); + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_center_lock(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "View Lock Center"; + ot->description = "Center the view lock offset"; + ot->idname = "VIEW3D_OT_view_center_lock"; + + /* api callbacks */ + ot->exec = view3d_center_lock_exec; + ot->poll = view3d_lock_poll; + + /* flags */ + ot->flag = 0; +} + /* ********************* Set render border operator ****************** */ static int render_border_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 44c85799896..085af4e5c18 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -89,6 +89,7 @@ void VIEW3D_OT_view_lock_to_active(struct wmOperatorType *ot); void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot); void VIEW3D_OT_view_center_pick(struct wmOperatorType *ot); void VIEW3D_OT_view_center_camera(struct wmOperatorType *ot); +void VIEW3D_OT_view_center_lock(struct wmOperatorType *ot); void VIEW3D_OT_view_pan(struct wmOperatorType *ot); void VIEW3D_OT_view_persportho(struct wmOperatorType *ot); void VIEW3D_OT_background_image_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index c46ae36a3a5..bf5b54dbdfc 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -148,6 +148,7 @@ void view3d_operatortypes(void) WM_operatortype_append(VIEW3D_OT_view_center_cursor); WM_operatortype_append(VIEW3D_OT_view_center_pick); WM_operatortype_append(VIEW3D_OT_view_center_camera); + WM_operatortype_append(VIEW3D_OT_view_center_lock); WM_operatortype_append(VIEW3D_OT_select); WM_operatortype_append(VIEW3D_OT_select_border); WM_operatortype_append(VIEW3D_OT_clip_border); @@ -244,6 +245,7 @@ void view3d_keymap(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */ + WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_lock", HOMEKEY, KM_PRESS, 0, 0); /* only with lock view */ WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_cursor", HOMEKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_pick", FKEY, KM_PRESS, KM_ALT, 0); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index a3421295464..3638690a0a5 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -847,6 +847,9 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) } } else { + bool use_lock_ofs = false; + + /* should be moved to better initialize later on XXX */ if (rv3d->viewlock) ED_view3d_lock(rv3d); @@ -866,15 +869,34 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) } } translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]); + use_lock_ofs = true; } else if (v3d->ob_centre_cursor) { float vec[3]; copy_v3_v3(vec, give_cursor(scene, v3d)); translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]); + use_lock_ofs = true; } else { translate_m4(rv3d->viewmat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]); } + + /* lock offset */ + if (use_lock_ofs) { + float persmat[4][4], persinv[4][4]; + float vec[3]; + + /* we could calculate the real persmat/persinv here + * but it would be unreliable so better to later */ + mul_m4_m4m4(persmat, rv3d->winmat, rv3d->viewmat); + invert_m4_m4(persinv, persmat); + + mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f); + vec[2] = 0.0f; + mul_mat3_m4_v3(persinv, vec); + translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]); + } + /* end lock offset */ } } diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 499598d2df5..fc67d2ddd7e 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -131,6 +131,7 @@ typedef struct RegionView3D { char viewlock; char viewlock_quad; /* options for quadview (store while out of quad view) */ char pad[3]; + float ofs_lock[2]; /* normalized offset for locked view: (-1, -1) bottom left, (1, 1) upper right */ short twdrawflag; short rflag; |