[Bf-blender-cvs] [dcdb4ea] master: NDOF: Fix for fly/walk mode ignoring axis invert options

Campbell Barton noreply at git.blender.org
Tue Feb 18 13:56:58 CET 2014


Commit: dcdb4eaf9cce1f3ff84bbe221ebafd20c2371541
Author: Campbell Barton
Date:   Tue Feb 18 23:51:11 2014 +1100
https://developer.blender.org/rBdcdb4eaf9cce1f3ff84bbe221ebafd20c2371541

NDOF: Fix for fly/walk mode ignoring axis invert options

===================================================================

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/view2d_ops.c
M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_fly.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index fbaa06f..2f1c411 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -962,9 +962,9 @@ class USERPREF_MT_ndof_settings(Menu):
             layout.separator()
             layout.label(text="Orbit options")
             layout.row().prop(input_prefs, "ndof_view_rotate_method", text="")
-            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_rotx_invert_axis")
+            layout.prop(input_prefs, "ndof_roty_invert_axis")
+            layout.prop(input_prefs, "ndof_rotz_invert_axis")
 
 
         # view2d use pan/zoom
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index a7f1795..9df6b7b 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4648,14 +4648,14 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data,
 	v[1] = r * sinf(phi);
 	
 	/* Use ndof device y and x rotation to move the vector in 2d space */
-	v[0] += ndof->rz * sensitivity;
-	v[1] += ndof->rx * sensitivity;
+	v[0] += ndof->rvec[2] * sensitivity;
+	v[1] += ndof->rvec[0] * sensitivity;
 
 	/* convert back to polar coords on circle */
 	phi = atan2f(v[0], v[1]) / (2.0f * (float)M_PI) + 0.5f;
 	
-	/* use ndof z rotation to additionally rotate hue */
-	phi += ndof->ry * sensitivity * 0.5f;
+	/* use ndof Y rotation to additionally rotate hue */
+	phi += ndof->rvec[1] * sensitivity * 0.5f;
 	r = len_v2(v);
 
 	/* convert back to hsv values, in range [0,1] */
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index 95859be..a8f01b7 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -1274,10 +1274,9 @@ static int view2d_ndof_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 		if (has_translate) {
 			if (view_pan_init(C, op)) {
 				v2dViewPanData *vpd;
-				float pan_vec[2];
+				float pan_vec[3];
 
-				pan_vec[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f);
-				pan_vec[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f);
+				WM_event_ndof_pan_get(ndof, pan_vec, false);
 
 				pan_vec[0] *= pan_sensitivity;
 				pan_vec[1] *= pan_sensitivity;
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 64d9615..6767f92 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -1333,14 +1333,14 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
 	else {
 		SpaceClip *sc = CTX_wm_space_clip(C);
 		ARegion *ar = CTX_wm_region(C);
-		float pan_vec[2];
+		float pan_vec[3];
 
 		wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
 
 		float dt = ndof->dt;
 
 		/* tune these until it feels right */
-		const float pan_sensitivity = 300.0f; /* screen pixels per second */
+		const float pan_sensitivity = 300.0f;  /* screen pixels per second */
 
 		/* "mouse zoom" factor = 1 + (dx + dy) / 300
 		 * what about "ndof zoom" factor? should behave like this:
@@ -1348,17 +1348,13 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
 		 * move forward -> factor > 1
 		 * move backward -> factor < 1
 		 */
-		float zoom_factor = dt * - ndof->tvec[2];
 
-		pan_vec[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f);
-		pan_vec[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f);
+		WM_event_ndof_pan_get(ndof, pan_vec, true);
 
 		mul_v2_fl(pan_vec, (pan_sensitivity * dt) / sc->zoom);
+		pan_vec[2] *= -dt;
 
-		if (U.ndof_flag & NDOF_ZOOM_INVERT)
-			zoom_factor = -zoom_factor;
-
-		sclip_zoom_set_factor(C, 1.0f + zoom_factor, NULL);
+		sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL);
 		sc->xof += pan_vec[0];
 		sc->yof += pan_vec[1];
 
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index d815995..29448a2 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -599,13 +599,14 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
 	else {
 		SpaceImage *sima = CTX_wm_space_image(C);
 		ARegion *ar = CTX_wm_region(C);
-		float pan_vec[2];
+		float pan_vec[3];
 
 		wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
 
 		float dt = ndof->dt;
+
 		/* tune these until it feels right */
-		const float pan_sensitivity = 300.f; // screen pixels per second
+		const float pan_sensitivity = 300.0f;  /* screen pixels per second */
 
 		/* "mouse zoom" factor = 1 + (dx + dy) / 300
 		 * what about "ndof zoom" factor? should behave like this:
@@ -613,17 +614,13 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
 		 * move forward -> factor > 1
 		 * move backward -> factor < 1
 		 */
-		float zoom_factor = dt * -ndof->tvec[2];
 
-		pan_vec[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f);
-		pan_vec[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f);
+		WM_event_ndof_pan_get(ndof, pan_vec, true);
 
 		mul_v2_fl(pan_vec, (pan_sensitivity * dt) / sima->zoom);
+		pan_vec[2] *= -dt;
 
-		if (U.ndof_flag & NDOF_ZOOM_INVERT)
-			zoom_factor = -zoom_factor;
-
-		sima_zoom_set_factor(sima, ar, 1.0f + zoom_factor, NULL);
+		sima_zoom_set_factor(sima, ar, 1.0f + pan_vec[2], NULL);
 		sima->xof += pan_vec[0];
 		sima->yof += pan_vec[1];
 
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 0c4e2bd..bcf0962 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -1151,20 +1151,6 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
 #define NDOF_HAS_TRANSLATE ((!view3d_operator_offset_lock_check(C, op)) && !is_zero_v3(ndof->tvec))
 #define NDOF_HAS_ROTATE    (((rv3d->viewlock & RV3D_LOCKED) == 0) && !is_zero_v3(ndof->rvec))
 
-float ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3])
-{
-	return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
-}
-
-void ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4])
-{
-	float axis[3];
-	float angle;
-
-	angle = ndof_to_axis_angle(ndof, axis);
-	axis_angle_to_quat(q, axis, angle);
-}
-
 /**
  * Zoom and pan in the same function since sometimes zoom is interpreted as dolly (pan forward).
  *
@@ -1182,9 +1168,7 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s
 		return;
 	}
 
-	pan_vec[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f);
-	pan_vec[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f);
-	pan_vec[2] = ndof->tvec[2] * ((U.ndof_flag & NDOF_PANZ_INVERT_AXIS) ? -1.0f : 1.0f);
+	WM_event_ndof_pan_get(ndof, pan_vec, false);
 
 	if (has_zoom) {
 		/* zoom with Z */
@@ -1195,14 +1179,11 @@ static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, ScrArea *s
 		 * proportional to arclength = radius * angle
 		 */
 
-		/* tune these until everything feels right */
-		const float zoom_sensitivity = 1.f;
-
 		pan_vec[2] = 0.0f;
 
 		/* "zoom in" or "translate"? depends on zoom mode in user settings? */
-		if (ndof->tz) {
-			float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
+		if (ndof->tvec[2]) {
+			float zoom_distance = rv3d->dist * dt * ndof->tvec[2];
 
 			if (U.ndof_flag & NDOF_ZOOM_INVERT)
 				zoom_distance = -zoom_distance;
@@ -1242,7 +1223,6 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, RegionView3D
                               /* optional, can be NULL*/
                               ViewOpsData *vod)
 {
-	const float rot_sensitivity = 1.0f;
 	float view_inv[4];
 
 	BLI_assert((rv3d->viewlock & RV3D_LOCKED) == 0);
@@ -1254,26 +1234,26 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, RegionView3D
 	invert_qt_qt(view_inv, rv3d->viewquat);
 
 	if (U.ndof_flag & NDOF_TURNTABLE) {
+		float rot[3];
 
 		/* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
-		float angle, rot[4];
+		float angle, quat[4];
 		float xvec[3] = {1, 0, 0};
 
+		/* only use XY, ignore Z */
+		WM_event_ndof_rotate_get(ndof, rot);
+
 		/* 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] = cosf(angle);
-		mul_v3_v3fl(rot + 1, xvec, sin(angle));
-		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+		angle = dt * rot[0];
+		quat[0] = cosf(angle);
+		mul_v3_v3fl(quat + 1, xvec, sin(angle));
+		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
 
 		/* Perform the orbital rotation */
-		angle = rot_sensitivity * dt * ndof->ry;
-		if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
-			angle = -angle;
+		angle = dt * rot[1];
 
 		/* update the onscreen doo-dad */
 		rv3d->rot_angle = angle;
@@ -1281,21 +1261,17 @@ static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, RegionView3D
 		rv3d->rot_axis[1] = 0;
 		rv3d->rot_axis[2] = 1;
 
-		rot[0] = cosf(angle);
-		rot[1] = rot[2] = 0.0;
-		rot[3] = sinf(angle);
-		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
+		quat[0] = cosf(angle);
+		quat[1] = 0.0f;
+		quat[2] = 0.0f;
+		quat[3] = sinf(angle);
+		mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat);
 
 	}
 	else {
-		float rot[4];
+		float quat[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_AX

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list