Fix T53850: Lock to Cursor breaks 3D manipulators
authorCampbell Barton <ideasman42@gmail.com>
Mon, 22 Jan 2018 09:11:34 +0000 (20:11 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 22 Jan 2018 09:14:12 +0000 (20:14 +1100)
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_view.c

index 694434d87e8dc60d9c98742f399549a14db2c200..1bf334411692f22df03ff8fa921858aa2aa7e2bc 100644 (file)
@@ -2751,10 +2751,17 @@ void ED_view3d_update_viewmat(
                view3d_winmatrix_set(ar, v3d, rect);
 
        /* setup view matrix */
-       if (viewmat)
+       if (viewmat) {
                copy_m4_m4(rv3d->viewmat, viewmat);
-       else
-               view3d_viewmatrix_set(scene, v3d, rv3d);  /* note: calls BKE_object_where_is_calc for camera... */
+       }
+       else {
+               float rect_scale[2];
+               if (rect) {
+                       rect_scale[0] = (float)BLI_rcti_size_x(rect) / (float)ar->winx;
+                       rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)ar->winy;
+               }
+               view3d_viewmatrix_set(scene, v3d, rv3d, rect ? rect_scale : NULL);  /* note: calls BKE_object_where_is_calc for camera... */
+       }
 
        /* update utility matrices */
        mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
index 7a106a2783367cd57e566e43c0cd27183bc817cb..b1ccb508e508ccc64044ac9a9132073c0129c9ce 100644 (file)
@@ -248,7 +248,7 @@ void ED_view3d_smooth_view_force_finish(
         struct View3D *v3d, struct ARegion *ar);
 
 void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rcti *rect);
-void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d);
+void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2]);
 
 void fly_modal_keymap(struct wmKeyConfig *keyconf);
 void walk_modal_keymap(struct wmKeyConfig *keyconf);
index 68680eee091e4af01af21af68a23810f0a69d21d..36ef4508058666c6966c0b17aaadc02dac0f74b2 100644 (file)
@@ -1117,8 +1117,18 @@ bool ED_view3d_lock(RegionView3D *rv3d)
        return ED_view3d_quat_from_axis_view(rv3d->view, rv3d->viewquat);
 }
 
-/* don't set windows active in here, is used by renderwin too */
-void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d)
+/**
+ * Sets #RegionView3D.viewmat
+ *
+ * \param scene: Scene for camera and cursor location.
+ * \param v3d: View 3D space data.
+ * \param rv3d: 3D region which stores the final matrices.
+ * \param rect_scale: Optional 2D scale argument,
+ * Use when displaying a sub-region, eg: when #view3d_winmatrix_set takes a 'rect' argument.
+ *
+ * \note don't set windows active in here, is used by renderwin too.
+ * */
+void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
 {
        if (rv3d->persp == RV3D_CAMOB) {      /* obs/camera */
                if (v3d->camera) {
@@ -1177,6 +1187,12 @@ void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d)
 
                        mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
                        vec[2] = 0.0f;
+
+                       if (rect_scale) {
+                               vec[0] /= rect_scale[0];
+                               vec[1] /= rect_scale[1];
+                       }
+
                        mul_mat3_m4_v3(persinv, vec);
                        translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]);
                }