[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50015] trunk/blender: Patch #32326: NDOF support of rotation and panning the view at the same time
Sergey Sharybin
sergey.vfx at gmail.com
Sun Aug 19 15:52:37 CEST 2012
Revision: 50015
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50015
Author: nazgul
Date: 2012-08-19 13:52:36 +0000 (Sun, 19 Aug 2012)
Log Message:
-----------
Patch #32326: NDOF support of rotation and panning the view at the same time
Additional changes:
- Option to the ndof menu letting you pick turntable/trackball independently
of the mouse viewport navigation style
- Option to change the rotation sensitivity separate from the panning
Holding shift + moving the ndof does just as before locking it to panning
Holding ctrl + moving will lock it to only rotation
Patch by Fredrik Hansson, thanks!
Reviewed by self and Mike Erwin.
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
trunk/blender/source/blender/editors/interface/resources.c
trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
trunk/blender/source/blender/makesdna/DNA_userdef_types.h
trunk/blender/source/blender/makesrna/intern/rna_userdef.c
trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py 2012-08-19 13:13:45 UTC (rev 50014)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py 2012-08-19 13:52:36 UTC (rev 50015)
@@ -858,6 +858,7 @@
layout.separator()
layout.prop(input_prefs, "ndof_sensitivity")
+ layout.prop(input_prefs, "ndof_orbit_sensitivity")
if context.space_data.type == 'VIEW_3D':
layout.separator()
@@ -865,11 +866,10 @@
layout.separator()
layout.label(text="Orbit options")
- if input_prefs.view_rotate_method == 'TRACKBALL':
- layout.prop(input_prefs, "ndof_roll_invert_axis")
+ layout.prop(input_prefs, "ndof_turntable")
+ layout.prop(input_prefs, "ndof_roll_invert_axis")
layout.prop(input_prefs, "ndof_tilt_invert_axis")
layout.prop(input_prefs, "ndof_rotate_invert_axis")
- layout.prop(input_prefs, "ndof_zoom_invert")
layout.separator()
layout.label(text="Pan options")
@@ -878,6 +878,7 @@
layout.prop(input_prefs, "ndof_panz_invert_axis")
layout.label(text="Zoom options")
+ layout.prop(input_prefs, "ndof_zoom_invert")
layout.prop(input_prefs, "ndof_zoom_updown")
layout.separator()
Modified: trunk/blender/source/blender/editors/interface/resources.c
===================================================================
--- trunk/blender/source/blender/editors/interface/resources.c 2012-08-19 13:13:45 UTC (rev 50014)
+++ trunk/blender/source/blender/editors/interface/resources.c 2012-08-19 13:52:36 UTC (rev 50015)
@@ -1967,6 +1967,10 @@
U.ndof_flag = NDOF_LOCK_HORIZON |
NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE;
}
+
+ if (U.ndof_orbit_sensitivity == 0.0f) {
+ U.ndof_orbit_sensitivity = 1.0f;
+ }
if (U.tweak_threshold == 0)
U.tweak_threshold = 10;
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c 2012-08-19 13:13:45 UTC (rev 50014)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c 2012-08-19 13:52:36 UTC (rev 50015)
@@ -1036,20 +1036,6 @@
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;
-
- if (U.ndof_flag & NDOF_ZOOM_INVERT)
- zoom_distance = -zoom_distance;
-
- 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.0f};
@@ -1067,35 +1053,8 @@
rv3d->view = RV3D_VIEW_USER;
- if (U.flag & USER_TRACKBALL) {
- float rot[4];
- float axis[3];
- float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
+ if (U.ndof_flag & NDOF_TURNTABLE) {
- if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
- axis[2] = -axis[2];
-
- if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
- axis[0] = -axis[0];
-
- if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
- axis[1] = -axis[1];
-
- /* transform rotation axis from view to world coordinates */
- mul_qt_v3(view_inv, axis);
-
- /* update the onscreen doo-dad */
- rv3d->rot_angle = angle;
- copy_v3_v3(rv3d->rot_axis, axis);
-
- axis_angle_to_quat(rot, axis, angle);
-
- /* 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};
@@ -1127,6 +1086,33 @@
rot[3] = sin(angle);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
}
+ else {
+ float rot[4];
+ float axis[3];
+ float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
+
+ if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
+ axis[2] = -axis[2];
+
+ if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
+ axis[0] = -axis[0];
+
+ if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
+ axis[1] = -axis[1];
+
+ /* transform rotation axis from view to world coordinates */
+ mul_qt_v3(view_inv, axis);
+
+ /* update the onscreen doo-dad */
+ rv3d->rot_angle = angle;
+ copy_v3_v3(rv3d->rot_axis, axis);
+
+ axis_angle_to_quat(rot, axis, angle);
+
+ /* apply rotation */
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+
+ }
}
}
@@ -1247,6 +1233,159 @@
ot->flag = 0;
}
+
+/*
+* this is basically just the pan only code + the rotate only code crammed into one function that does both
+*/
+static int ndof_all_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ if (event->type != NDOF_MOTION)
+ return OPERATOR_CANCELLED;
+ else {
+
+ ViewOpsData *vod;
+ RegionView3D *rv3d;
+
+ View3D *v3d = CTX_wm_view3d(C);
+ wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
+
+ ED_view3d_camera_lock_init(v3d, rv3d);
+
+ viewops_data_create(C, op, event);
+ vod = op->customdata;
+ rv3d = vod->rv3d;
+
+
+ if (ndof->progress != P_FINISHING) {
+
+ const float dt = ndof->dt;
+ float view_inv[4];
+
+ float speed = 10.f; /* blender units per second */
+ /* ^^ this is ok for default cube scene, but should scale with.. something */
+
+ /* tune these until everything feels right */
+ const float forward_sensitivity = 1.f;
+ const float vertical_sensitivity = 0.4f;
+ const float lateral_sensitivity = 0.6f;
+
+ float pan_vec[3];
+ const float rot_sensitivity = 1.f;
+ const float zoom_sensitivity = 1.f;
+ const float pan_sensitivity = 1.f;
+ float rot[4];
+ float axis[3];
+ float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
+
+ if (U.ndof_flag & NDOF_PANX_INVERT_AXIS)
+ pan_vec[0] = -lateral_sensitivity * ndof->tvec[0];
+ else
+ pan_vec[0] = lateral_sensitivity * ndof->tvec[0];
+
+ if (U.ndof_flag & NDOF_PANZ_INVERT_AXIS)
+ pan_vec[1] = -vertical_sensitivity * ndof->tvec[1];
+ else
+ pan_vec[1] = vertical_sensitivity * ndof->tvec[1];
+
+ if (U.ndof_flag & NDOF_PANY_INVERT_AXIS)
+ pan_vec[2] = -forward_sensitivity * ndof->tvec[2];
+ else
+ pan_vec[2] = forward_sensitivity * ndof->tvec[2];
+
+ mul_v3_fl(pan_vec, speed * 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 (U.ndof_flag & NDOF_TURNTABLE) {
+ /* 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 (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
+ 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 (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
+ 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);
+
+ }
+ else {
+
+ float rot[4];
+ float axis[3];
+ float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
+
+ if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
+ axis[2] = -axis[2];
+
+ if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
+ axis[0] = -axis[0];
+
+ if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
+ axis[1] = -axis[1];
+
+ /* transform rotation axis from view to world coordinates */
+ mul_qt_v3(view_inv, axis);
+
+ /* update the onscreen doo-dad */
+ rv3d->rot_angle = angle;
+ copy_v3_v3(rv3d->rot_axis, axis);
+
+ axis_angle_to_quat(rot, axis, angle);
+
+ /* apply rotation */
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+
+ }
+ }
+ ED_view3d_camera_lock_sync(v3d, rv3d);
+
+ ED_region_tag_redraw(CTX_wm_region(C));
+ viewops_data_free(C, op);
+ return OPERATOR_FINISHED;
+ }
+}
+
+void VIEW3D_OT_ndof_all(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "NDOF move View";
+ ot->description = "Position your viewpoint with the 3D mouse";
+ ot->idname = "VIEW3D_OT_ndof_all";
+
+ /* api callbacks */
+ ot->invoke = ndof_all_invoke;
+ ot->poll = ED_operator_view3d_active;
+
+ /* flags */
+ ot->flag = 0;
+}
+
/* ************************ viewmove ******************************** */
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_intern.h 2012-08-19 13:13:45 UTC (rev 50014)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_intern.h 2012-08-19 13:52:36 UTC (rev 50015)
@@ -79,6 +79,7 @@
void VIEW3D_OT_rotate(struct wmOperatorType *ot);
void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot);
void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot);
+void VIEW3D_OT_ndof_all(struct wmOperatorType *ot);
void VIEW3D_OT_view_all(struct wmOperatorType *ot);
void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot);
void VIEW3D_OT_view_selected(struct wmOperatorType *ot);
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2012-08-19 13:13:45 UTC (rev 50014)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2012-08-19 13:52:36 UTC (rev 50015)
@@ -64,6 +64,7 @@
WM_operatortype_append(VIEW3D_OT_dolly);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list