diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-03-28 08:02:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-03-28 08:02:57 +0400 |
commit | 5981567ec6afb3ae95f24c28b2c72bff0d8e01e6 (patch) | |
tree | 6de07252b408ae2f417dc751be550b40c2e856a1 | |
parent | 7199e2288f3df27ee2d21593da64ef4597fb86fd (diff) |
Code cleanup: use len_v2v2_int for view zoom-scale
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 9 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 33 |
3 files changed, 26 insertions, 17 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index aef06f77d72..9b73ca553d6 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -163,6 +163,7 @@ MINLINE int len_manhattan_v2_int(const int v[2]) ATTR_WARN_UNUSED_RESULT; MINLINE float len_manhattan_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT; MINLINE float len_v2(const float a[2]) ATTR_WARN_UNUSED_RESULT; MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; +MINLINE float len_v2v2_int(const int v1[2], const int v2[2]); MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT; MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 45a0cb3f8e2..59d5f7e7627 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -676,6 +676,15 @@ MINLINE float len_v2v2(const float v1[2], const float v2[2]) return sqrtf(x * x + y * y); } +MINLINE float len_v2v2_int(const int v1[2], const int v2[2]) +{ + float x, y; + + x = (float)(v1[0] - v2[0]); + y = (float)(v1[1] - v2[1]); + return sqrtf(x * x + y * y); +} + MINLINE float len_v3(const float a[3]) { return sqrtf(dot_v3v3(a, a)); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index fe84e3e79a0..6b08ae98677 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1962,7 +1962,7 @@ static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my) } -static void viewzoom_apply(ViewOpsData *vod, const int x, const int y, const short viewzoom, const short zoom_invert) +static void viewzoom_apply(ViewOpsData *vod, const int xy[2], const short viewzoom, const short zoom_invert) { float zfac = 1.0; bool use_cam_zoom; @@ -1971,7 +1971,7 @@ static void viewzoom_apply(ViewOpsData *vod, const int x, const int y, const sho if (use_cam_zoom) { float delta; - delta = (x - vod->origx + y - vod->origy) / 10.0f; + delta = (xy[0] - vod->origx + xy[1] - vod->origy) / 10.0f; vod->rv3d->camzoom = vod->camzoom_prev + (zoom_invert ? -delta : delta); CLAMP(vod->rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); @@ -1983,10 +1983,10 @@ static void viewzoom_apply(ViewOpsData *vod, const int x, const int y, const sho float fac; if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(vod->origx - x); + fac = (float)(vod->origx - xy[0]); } else { - fac = (float)(vod->origy - y); + fac = (float)(vod->origy - xy[1]); } if (zoom_invert) { @@ -1998,26 +1998,25 @@ static void viewzoom_apply(ViewOpsData *vod, const int x, const int y, const sho vod->timer_lastdraw = time; } else if (viewzoom == USER_ZOOM_SCALE) { - int ctr[2], len1, len2; /* method which zooms based on how far you move the mouse */ - ctr[0] = BLI_rcti_cent_x(&vod->ar->winrct); - ctr[1] = BLI_rcti_cent_y(&vod->ar->winrct); - - len1 = (int)sqrt((ctr[0] - x) * (ctr[0] - x) + (ctr[1] - y) * (ctr[1] - y)) + 5; - len2 = (int)sqrt((ctr[0] - vod->origx) * (ctr[0] - vod->origx) + (ctr[1] - vod->origy) * (ctr[1] - vod->origy)) + 5; - - zfac = vod->dist_prev * ((float)len2 / len1) / vod->rv3d->dist; + const int ctr[2] = { + BLI_rcti_cent_x(&vod->ar->winrct), + BLI_rcti_cent_y(&vod->ar->winrct), + }; + const float len_new = 5 + len_v2v2_int(ctr, xy); + const float len_old = 5 + len_v2v2_int(ctr, &vod->origx); + zfac = vod->dist_prev * ((len_old + 5) / (len_new + 5)) / vod->rv3d->dist; } else { /* USER_ZOOM_DOLLY */ float len1, len2; if (U.uiflag & USER_ZOOM_HORIZ) { - len1 = (vod->ar->winrct.xmax - x) + 5; + len1 = (vod->ar->winrct.xmax - xy[0]) + 5; len2 = (vod->ar->winrct.xmax - vod->origx) + 5; } else { - len1 = (vod->ar->winrct.ymax - y) + 5; + len1 = (vod->ar->winrct.ymax - xy[1]) + 5; len2 = (vod->ar->winrct.ymax - vod->origy) + 5; } if (zoom_invert) { @@ -2089,7 +2088,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) } if (event_code == VIEW_APPLY) { - viewzoom_apply(vod, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0); + viewzoom_apply(vod, &event->x, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0); } else if (event_code == VIEW_CONFIRM) { ED_view3d_depth_tag_update(vod->rv3d); @@ -2224,12 +2223,12 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) if (U.uiflag & USER_ZOOM_HORIZ) { vod->origx = vod->oldx = event->x; - viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0); + viewzoom_apply(vod, &event->prevx, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0); } else { /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ vod->origy = vod->oldy = vod->origy + event->x - event->prevx; - viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0); + viewzoom_apply(vod, &event->prevx, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0); } ED_view3d_depth_tag_update(vod->rv3d); |