From 27aef8b551bd30817bac13cfe77d5a142ac0d037 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 4 Aug 2019 01:19:22 +1000 Subject: 3D View: aspect correct trackball rotation Hard coded aspect was used, doubling horizontal input however this caused sliding for views which didn't match this aspect. Calculate the aspect based on the view bounds instead. --- source/blender/editors/space_view3d/view3d_edit.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_view3d/view3d_edit.c') diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index af862345824..0d0cfce07d7 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -189,10 +189,15 @@ static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_di { const float radius = TRACKBALLSIZE; const float t = radius / (float)M_SQRT2; + const float size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}; + /* Aspect correct so dragging in a non-square view doesn't squash the, + * so diagonal motion rotates diagonally too. */ + const float size_min = min_ff(size[0], size[1]); + const float aspect[2] = {size_min / size[0], size_min / size[1]}; /* Normalize x and y. */ - r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((float)BLI_rcti_size_x(rect) / 4.0); - r_dir[1] = (event_xy[1] - BLI_rcti_cent_x(rect)) / ((float)BLI_rcti_size_y(rect) / 2.0); + r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0); + r_dir[1] = (event_xy[1] - BLI_rcti_cent_x(rect)) / ((size[1] * aspect[1]) / 2.0); const float d = len_v2(r_dir); if (d < t) { /* Inside sphere. */ -- cgit v1.2.3