diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-13 08:26:00 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-13 08:28:18 +0300 |
commit | 0528c16b3ad1dc7391c68477a0ba4427071b3924 (patch) | |
tree | c45e9ff46b4852281ceac2a88215915559c4f80a | |
parent | 5e75acf81d57bd577abba0818ac98d221299181e (diff) |
Cleanup: simplify view3d trackball logic
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 2295986faf0..7f1083a7570 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -558,7 +558,7 @@ typedef struct ViewOpsData { } ViewOpsData; -#define TRACKBALLSIZE (1.1) +#define TRACKBALLSIZE (1.1f) static void calctrackballvec(const rcti *rect, int mx, int my, float vec[3]) { @@ -1028,31 +1028,25 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */ if (U.flag & USER_TRACKBALL) { - float phi, si, q1[4], dvec[3], newvec[3]; + float axis[3], q1[4], dvec[3], newvec[3]; + float angle; calctrackballvec(&vod->ar->winrct, x, y, newvec); sub_v3_v3v3(dvec, newvec, vod->trackvec); - si = len_v3(dvec); - si /= (float)(2.0 * TRACKBALLSIZE); - - cross_v3_v3v3(q1 + 1, vod->trackvec, newvec); - normalize_v3(q1 + 1); + angle = (len_v3(dvec) / (2.0f * TRACKBALLSIZE)) * M_PI; /* Allow for rotation beyond the interval [-pi, pi] */ - while (si > 1.0f) - si -= 2.0f; - - /* This relation is used instead of - * - phi = asin(si) so that the angle - * - of rotation is linearly proportional - * - to the distance that the mouse is - * - dragged. */ - phi = si * (float)M_PI_2; - - q1[0] = cosf(phi); - mul_v3_fl(q1 + 1, sinf(phi)); + angle = fmod(angle + (float)M_PI, M_PI * 2) - (float)M_PI; + + /* This relation is used instead of the actual angle between vectors + * so that the angle of rotation is linearly proportional to + * the distance that the mouse is dragged. */ + + cross_v3_v3v3(axis, vod->trackvec, newvec); + axis_angle_to_quat(q1, axis, angle); + mul_qt_qtqt(vod->viewquat, q1, vod->oldquat); viewrotate_apply_dyn_ofs(vod, vod->viewquat); @@ -1476,8 +1470,7 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, ScrArea *sa, /* Perform the up/down rotation */ angle = ndof->dt * rot[0]; - quat[0] = cosf(angle); - mul_v3_v3fl(quat + 1, xvec, sinf(angle)); + axis_angle_to_quat(quat, xvec, angle * 2); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); /* Perform the orbital rotation */ |