Cleanup: move camera-view pan/zoom into utility functions
This commit is contained in:
parent
ae9dd0cbf9
commit
f33e6e0d8c
|
@ -1078,6 +1078,20 @@ bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph,
|
|||
struct View3D *v3d,
|
||||
struct ARegion *region);
|
||||
|
||||
/* Camera view functions. */
|
||||
|
||||
/**
|
||||
* Utility to scale zoom level when in camera-view #RegionView3D.camzoom and apply limits.
|
||||
* \return true a change was made.
|
||||
*/
|
||||
bool ED_view3d_camera_view_zoom_scale(struct RegionView3D *rv3d, const float scale);
|
||||
/**
|
||||
* Utility to pan when in camera view.
|
||||
* \param event_ofs: The offset the pan in screen (pixel) coordinates.
|
||||
* \return true when a change was made.
|
||||
*/
|
||||
bool ED_view3d_camera_view_pan(struct ARegion *region, const float event_ofs[2]);
|
||||
|
||||
/* Camera lock functions */
|
||||
|
||||
/**
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -509,6 +509,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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue