View3D: Add ED_view3d_dist_range_get
remove hard coded limits
This commit is contained in:
@@ -219,7 +219,8 @@ void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, cons
|
||||
/* end */
|
||||
|
||||
|
||||
|
||||
void ED_view3d_dist_range_get(struct View3D *v3d,
|
||||
float r_dist_range[2]);
|
||||
bool ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d,
|
||||
float *r_clipsta, float *r_clipend, const bool use_ortho_factor);
|
||||
bool ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi,
|
||||
@@ -349,6 +350,7 @@ void ED_view3D_background_image_clear(struct View3D *v3d);
|
||||
|
||||
#define VIEW3D_MARGIN 1.4f
|
||||
#define VIEW3D_DIST_FALLBACK 1.0f
|
||||
|
||||
float ED_view3d_offset_distance(float mat[4][4], const float ofs[3], const float dist_fallback);
|
||||
void ED_view3d_distance_set(struct RegionView3D *rv3d, const float dist);
|
||||
|
||||
|
||||
@@ -2115,9 +2115,12 @@ static void viewzoom_apply(ViewOpsData *vod, const int xy[2], const short viewzo
|
||||
{
|
||||
float zfac = 1.0;
|
||||
bool use_cam_zoom;
|
||||
float dist_range[2];
|
||||
|
||||
use_cam_zoom = (vod->rv3d->persp == RV3D_CAMOB) && !(vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d));
|
||||
|
||||
ED_view3d_dist_range_get(vod->v3d, dist_range);
|
||||
|
||||
if (use_cam_zoom) {
|
||||
float delta;
|
||||
delta = (xy[0] - vod->origx + xy[1] - vod->origy) / 10.0f;
|
||||
@@ -2192,8 +2195,7 @@ static void viewzoom_apply(ViewOpsData *vod, const int xy[2], const short viewzo
|
||||
}
|
||||
|
||||
/* these limits were in old code too */
|
||||
if (vod->rv3d->dist < 0.001f * vod->grid) vod->rv3d->dist = 0.001f * vod->grid;
|
||||
if (vod->rv3d->dist > 10.0f * vod->far) vod->rv3d->dist = 10.0f * vod->far;
|
||||
CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]);
|
||||
|
||||
if (vod->rv3d->viewlock & RV3D_BOXVIEW)
|
||||
view3d_boxview_sync(vod->sa, vod->ar);
|
||||
@@ -2257,6 +2259,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
|
||||
ScrArea *sa;
|
||||
ARegion *ar;
|
||||
bool use_cam_zoom;
|
||||
float dist_range[2];
|
||||
|
||||
const int delta = RNA_int_get(op->ptr, "delta");
|
||||
int mx, my;
|
||||
@@ -2280,13 +2283,15 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
|
||||
|
||||
use_cam_zoom = (rv3d->persp == RV3D_CAMOB) && !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d));
|
||||
|
||||
ED_view3d_dist_range_get(v3d, dist_range);
|
||||
|
||||
if (delta < 0) {
|
||||
/* this min and max is also in viewmove() */
|
||||
if (use_cam_zoom) {
|
||||
rv3d->camzoom -= 10.0f;
|
||||
if (rv3d->camzoom < RV3D_CAMZOOM_MIN) rv3d->camzoom = RV3D_CAMZOOM_MIN;
|
||||
}
|
||||
else if (rv3d->dist < 10.0f * v3d->far) {
|
||||
else if (rv3d->dist < dist_range[1]) {
|
||||
view_zoom_mouseloc(ar, 1.2f, mx, my);
|
||||
}
|
||||
}
|
||||
@@ -2295,7 +2300,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
|
||||
rv3d->camzoom += 10.0f;
|
||||
if (rv3d->camzoom > RV3D_CAMZOOM_MAX) rv3d->camzoom = RV3D_CAMZOOM_MAX;
|
||||
}
|
||||
else if (rv3d->dist > 0.001f * v3d->grid) {
|
||||
else if (rv3d->dist > dist_range[0]) {
|
||||
view_zoom_mouseloc(ar, 0.83333f, mx, my);
|
||||
}
|
||||
}
|
||||
@@ -3374,7 +3379,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
||||
/* Zooms in on a border drawn by the user */
|
||||
rcti rect;
|
||||
float dvec[3], vb[2], xscale, yscale;
|
||||
float dist_range_min;
|
||||
float dist_range[2];
|
||||
|
||||
/* SMOOTHVIEW */
|
||||
float new_dist;
|
||||
@@ -3394,6 +3399,8 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
||||
/* check if zooming in/out view */
|
||||
gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
|
||||
|
||||
ED_view3d_dist_range_get(v3d, dist_range);
|
||||
|
||||
/* Get Z Depths, needed for perspective, nice for ortho */
|
||||
bgl_get_mats(&mats);
|
||||
ED_view3d_draw_depth(scene, ar, v3d, true);
|
||||
@@ -3442,8 +3449,9 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
||||
new_ofs[2] = -p[2];
|
||||
|
||||
new_dist = len_v3(dvec);
|
||||
dist_range_min = v3d->near * 1.5f;
|
||||
|
||||
/* ignore dist_range min */
|
||||
dist_range[0] = v3d->near * 1.5f;
|
||||
}
|
||||
else { /* othographic */
|
||||
/* find the current window width and height */
|
||||
@@ -3485,9 +3493,6 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
||||
xscale = (BLI_rcti_size_x(&rect) / vb[0]);
|
||||
yscale = (BLI_rcti_size_y(&rect) / vb[1]);
|
||||
new_dist *= max_ff(xscale, yscale);
|
||||
|
||||
/* zoom in as required, or as far as we can go */
|
||||
dist_range_min = 0.001f * v3d->grid;
|
||||
}
|
||||
|
||||
if (gesture_mode == GESTURE_MODAL_OUT) {
|
||||
@@ -3497,9 +3502,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
/* clamp after because we may have been zooming out */
|
||||
if (new_dist < dist_range_min) {
|
||||
new_dist = dist_range_min;
|
||||
}
|
||||
CLAMP(new_dist, dist_range[0], dist_range[1]);
|
||||
|
||||
ED_view3d_smooth_view(C, v3d, ar, NULL, NULL,
|
||||
new_ofs, NULL, &new_dist, NULL,
|
||||
|
||||
@@ -724,6 +724,13 @@ void ED_view3d_depth_tag_update(RegionView3D *rv3d)
|
||||
rv3d->depths->damaged = true;
|
||||
}
|
||||
|
||||
void ED_view3d_dist_range_get(struct View3D *v3d,
|
||||
float r_dist_range[2])
|
||||
{
|
||||
r_dist_range[0] = v3d->grid * 0.001f;
|
||||
r_dist_range[1] = v3d->far * 10.0f;
|
||||
}
|
||||
|
||||
/* copies logic of get_view3d_viewplane(), keep in sync */
|
||||
bool ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *r_clipsta, float *r_clipend,
|
||||
const bool use_ortho_factor)
|
||||
|
||||
Reference in New Issue
Block a user