Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2011-07-26 06:35:46 +0400
committerMike Erwin <significant.bit@gmail.com>2011-07-26 06:35:46 +0400
commit72f70874bb3477a0861735d612e0c15c931ff7e5 (patch)
treee02ac19b1049c741c213a526f3393650a2257ca2 /source/blender/editors/space_view3d/view3d_edit.c
parent4b8233423bea092d5af4affe14290095dbd701ef (diff)
experimental onscreen rotation guide
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_edit.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c206
1 files changed, 115 insertions, 91 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 0aceb3bc1ca..75e20ad565e 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -977,101 +977,125 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event)
RegionView3D* rv3d = CTX_wm_region_view3d(C);
wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata;
- const float dt = ndof->dt;
+ rv3d->rot_angle = 0.f; // off by default, until changed later this function
- // tune these until everything feels right
- const float rot_sensitivity = 1.f;
- const float zoom_sensitivity = 1.f;
- const float pan_sensitivity = 1.f;
-
- // rather have bool, but...
- int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz);
-
- //#define DEBUG_NDOF_MOTION
- #ifdef DEBUG_NDOF_MOTION
- printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
- ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
- #endif
-
- if (ndof->tz) {
- // Zoom!
- // velocity should be proportional to the linear velocity attained by rotational motion of same strength
- // [got that?]
- // proportional to arclength = radius * angle
-
- float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
- rv3d->dist += zoom_distance;
- }
-
- if (rv3d->viewlock == RV3D_LOCKED) {
- /* rotation not allowed -- explore panning options instead */
+ if (ndof->progress != P_FINISHING) {
+ const float dt = ndof->dt;
+
+ // tune these until everything feels right
+ const float rot_sensitivity = 1.f;
+ const float zoom_sensitivity = 1.f;
+ const float pan_sensitivity = 1.f;
+
+ // rather have bool, but...
+ int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz);
+
float view_inv[4];
- float pan_vec[3] = {ndof->tx, ndof->ty, 0};
- mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
-
- /* transform motion from view to world coordinates */
invert_qt_qt(view_inv, rv3d->viewquat);
- mul_qt_v3(view_inv, pan_vec);
-
- /* move center of view opposite of hand motion (this is camera mode, not object mode) */
- sub_v3_v3(rv3d->ofs, pan_vec);
- }
-
- if (has_rotation) {
-
- const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES;
-
- rv3d->view = RV3D_VIEW_USER;
-
- if (U.flag & USER_TRACKBALL) {
-
- float rot[4];
- float view_inv[4], view_inv_conj[4];
-
- ndof_to_quat(ndof, rot);
- // mul_qt_fl(rot, rot_sensitivity);
- // ^^ no apparent effect
-
- if (invert)
- invert_qt(rot);
-
- invert_qt_qt(view_inv, rv3d->viewquat);
- copy_qt_qt(view_inv_conj, view_inv);
- conjugate_qt(view_inv_conj);
-
- // transform rotation from view to world coordinates
- mul_qt_qtqt(rot, view_inv, rot);
- mul_qt_qtqt(rot, rot, view_inv_conj);
-
- // apply rotation
- mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
-
- } else {
- /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
- float angle, rot[4];
- float xvec[3] = {1,0,0};
-
- /* Determine the direction of the x vector (for rotating up and down) */
- float view_inv[4];
+
+ //#define DEBUG_NDOF_MOTION
+ #ifdef DEBUG_NDOF_MOTION
+ printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
+ ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
+ #endif
+
+ if (ndof->tz) {
+ // Zoom!
+ // velocity should be proportional to the linear velocity attained by rotational motion of same strength
+ // [got that?]
+ // proportional to arclength = radius * angle
+
+ float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
+ rv3d->dist += zoom_distance;
+ }
+
+ if (rv3d->viewlock == RV3D_LOCKED) {
+ /* rotation not allowed -- explore panning options instead */
+ float pan_vec[3] = {ndof->tx, ndof->ty, 0};
+ mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
+
+ /* transform motion from view to world coordinates */
invert_qt_qt(view_inv, rv3d->viewquat);
- mul_qt_v3(view_inv, xvec);
-
- /* Perform the up/down rotation */
- angle = rot_sensitivity * dt * ndof->rx;
- if (invert)
- angle = -angle;
- rot[0] = cos(angle);
- mul_v3_v3fl(rot+1, xvec, sin(angle));
- mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
-
- /* Perform the orbital rotation */
- angle = rot_sensitivity * dt * ndof->ry;
- if (invert)
- angle = -angle;
- rot[0] = cos(angle);
- rot[1] = rot[2] = 0.0;
- rot[3] = sin(angle);
- mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+ mul_qt_v3(view_inv, pan_vec);
+
+ /* move center of view opposite of hand motion (this is camera mode, not object mode) */
+ sub_v3_v3(rv3d->ofs, pan_vec);
+ }
+
+ if (has_rotation) {
+
+ const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES;
+
+ rv3d->view = RV3D_VIEW_USER;
+
+ if (U.flag & USER_TRACKBALL) {
+ float rot[4];
+ #if 0 // -------------------------- Mike's nifty original version
+ float view_inv_conj[4];
+
+ ndof_to_quat(ndof, rot);
+ // mul_qt_fl(rot, rot_sensitivity);
+ // ^^ no apparent effect
+
+ if (invert)
+ invert_qt(rot);
+
+ copy_qt_qt(view_inv_conj, view_inv);
+ conjugate_qt(view_inv_conj);
+
+ // transform rotation from view to world coordinates
+ mul_qt_qtqt(rot, view_inv, rot);
+ mul_qt_qtqt(rot, rot, view_inv_conj);
+ #else // ---------------------------------------- Mike's revised version
+ float axis[3];
+ float angle = rot_sensitivity * ndof_to_angle_axis(ndof, axis);
+
+ if (invert)
+ angle = -angle;
+
+ // update the onscreen doo-dad
+ rv3d->rot_angle = angle;
+ copy_v3_v3(rv3d->rot_axis, axis);
+
+ // transform rotation axis from view to world coordinates
+ mul_qt_v3(view_inv, axis);
+
+ axis_angle_to_quat(rot, axis, angle);
+ #endif // --------------------------------------------
+ // apply rotation
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+ } else {
+ /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
+ float angle, rot[4];
+ float xvec[3] = {1,0,0};
+
+ /* Determine the direction of the x vector (for rotating up and down) */
+ mul_qt_v3(view_inv, xvec);
+
+ /* Perform the up/down rotation */
+ angle = rot_sensitivity * dt * ndof->rx;
+ if (invert)
+ angle = -angle;
+ rot[0] = cos(angle);
+ mul_v3_v3fl(rot+1, xvec, sin(angle));
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+
+ /* Perform the orbital rotation */
+ angle = rot_sensitivity * dt * ndof->ry;
+ if (invert)
+ angle = -angle;
+
+ // update the onscreen doo-dad
+ rv3d->rot_angle = angle;
+ rv3d->rot_axis[0] = 0;
+ rv3d->rot_axis[1] = 0;
+ rv3d->rot_axis[2] = 1;
+
+ rot[0] = cos(angle);
+ rot[1] = rot[2] = 0.0;
+ rot[3] = sin(angle);
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+ }
}
}