Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Tue, 23 Jan 2018 00:24:44 +0000 (11:24 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 23 Jan 2018 00:24:44 +0000 (11:24 +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 cf43d65b44a01c64e9a367bb48cc27945d53f6b3..f734bb085d035dabbcae3f89e4e5347139198067 100644 (file)
@@ -133,11 +133,18 @@ void ED_view3d_update_viewmat(
                view3d_winmatrix_set(depsgraph, ar, v3d, rect);
 
        /* setup view matrix */
-       if (viewmat)
+       if (viewmat) {
                copy_m4_m4(rv3d->viewmat, viewmat);
-       else
-               view3d_viewmatrix_set(eval_ctx, 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;
+               }
+               /* note: calls BKE_object_where_is_calc for camera... */
+               view3d_viewmatrix_set(eval_ctx, scene, v3d, rv3d, rect ? rect_scale : NULL);
+       }
        /* update utility matrices */
        mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
        invert_m4_m4(rv3d->persinv, rv3d->persmat);
index df2e5315c3952c8189bf3bc56c66601348ea0300..1e4e4dbc177ea722282d3b4a7316faaee75a3133 100644 (file)
@@ -276,8 +276,12 @@ void ED_view3d_smooth_view_force_finish(
         struct bContext *C,
         struct View3D *v3d, struct ARegion *ar);
 
-void view3d_winmatrix_set(const struct Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect);
-void view3d_viewmatrix_set(const struct EvaluationContext *eval_ctx, Scene *scene, const View3D *v3d, RegionView3D *rv3d);
+void view3d_winmatrix_set(
+        const struct Depsgraph *depsgraph,
+        ARegion *ar, const View3D *v3d, const rcti *rect);
+void view3d_viewmatrix_set(
+        const struct EvaluationContext *eval_ctx, 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 1d984ad9f4b3172fc3cbaaf1dcc0db8f9275f931..c555358f4c30e0441e796a804f33fbe42f89ebc7 100644 (file)
@@ -1113,8 +1113,21 @@ 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(const EvaluationContext *eval_ctx, Scene *scene, const View3D *v3d, RegionView3D *rv3d)
+/**
+ * Sets #RegionView3D.viewmat
+ *
+ * \param eval_ctx: Context.
+ * \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(
+        const EvaluationContext *eval_ctx, Scene *scene,
+        const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
 {
        if (rv3d->persp == RV3D_CAMOB) {      /* obs/camera */
                if (v3d->camera) {
@@ -1175,6 +1188,12 @@ void view3d_viewmatrix_set(const EvaluationContext *eval_ctx, Scene *scene, cons
 
                        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]);
                }