Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-02-18 08:43:10 +0300
committerCampbell Barton <campbell@blender.org>2022-02-18 08:48:27 +0300
commitf33e6e0d8c607eb33b1eb0c587b4e43cde30d5e1 (patch)
tree07cfc1e5610853f9370010da428023fc0d7eea4b /source/blender/editors/space_view3d
parentae9dd0cbf911662798e7dfb3120721d949f6cd40 (diff)
Cleanup: move camera-view pan/zoom into utility functions
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c33
2 files changed, 38 insertions, 5 deletions
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 0305989d142..d1e7b5891e9 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -549,11 +549,11 @@ void viewmove_apply(ViewOpsData *vod, int x, int y)
vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->region->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(vod->rv3d->camzoom) * 2.0f;
- vod->rv3d->camdx += (vod->prev.event_xy[0] - x) / (vod->region->winx * zoomfac);
- vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->region->winy * zoomfac);
- CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
- CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
+ const float event_ofs[2] = {
+ vod->prev.event_xy[0] - x,
+ vod->prev.event_xy[1] - y,
+ };
+ ED_view3d_camera_view_pan(vod->region, event_ofs);
}
else {
float dvec[3];
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 8a219cd96d1..3e788f2d643 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -510,6 +510,39 @@ bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *re
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Camera View Utilities
+ *
+ * Utilities for manipulating the camera-view.
+ * \{ */
+
+bool ED_view3d_camera_view_zoom_scale(RegionView3D *rv3d, const float scale)
+{
+ const float camzoom_init = rv3d->camzoom;
+ float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
+ /* Clamp both before and after conversion to prevent NAN on negative values. */
+
+ zoomfac = zoomfac * scale;
+ CLAMP(zoomfac, RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR);
+ rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(zoomfac);
+ CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
+ return (rv3d->camzoom != camzoom_init);
+}
+
+bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
+{
+ RegionView3D *rv3d = region->regiondata;
+ const float camdxy_init[2] = {rv3d->camdx, rv3d->camdy};
+ const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f;
+ rv3d->camdx += event_ofs[0] / (region->winx * zoomfac);
+ rv3d->camdy += event_ofs[1] / (region->winy * zoomfac);
+ CLAMP(rv3d->camdx, -1.0f, 1.0f);
+ CLAMP(rv3d->camdy, -1.0f, 1.0f);
+ return (camdxy_init[0] != rv3d->camdx) || (camdxy_init[1] != rv3d->camdy);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Camera Lock API
*
* Lock the camera to the 3D Viewport, allowing view manipulation to transform the camera.