[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38916] trunk/blender: Made wmNDOFMotionData use a vector rather then xyz members, makes it nicer to use with math functions.

Campbell Barton ideasman42 at gmail.com
Tue Aug 2 09:08:23 CEST 2011


Revision: 38916
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38916
Author:   campbellbarton
Date:     2011-08-02 07:08:22 +0000 (Tue, 02 Aug 2011)
Log Message:
-----------
Made wmNDOFMotionData use a vector rather then xyz members, makes it nicer to use with math functions.

ndof_to_angle_axis and ndof_to_quat now use math functions.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_userpref_keymap.py
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_fly.c
    trunk/blender/source/blender/editors/transform/transform_ops.c
    trunk/blender/source/blender/windowmanager/WM_types.h
    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref_keymap.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref_keymap.py	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref_keymap.py	2011-08-02 07:08:22 UTC (rev 38916)
@@ -271,7 +271,7 @@
             row.prop(kmi, "type", text="", full_event=True)
         elif map_type == 'MOUSE':
             row.prop(kmi, "type", text="", full_event=True)
-        if map_type == 'NDOF':
+        elif map_type == 'NDOF':
             row.prop(kmi, "type", text="", full_event=True)
         elif map_type == 'TWEAK':
             subrow = row.row()
@@ -308,7 +308,7 @@
                 sub = split.column()
                 subrow = sub.row(align=True)
 
-                if map_type in ('KEYBOARD', 'NDOF'):
+                if map_type in {'KEYBOARD', 'NDOF'}:
                     subrow.prop(kmi, "type", text="", event=True)
                     subrow.prop(kmi, "value", text="")
                 elif map_type == 'MOUSE':

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2011-08-02 07:08:22 UTC (rev 38916)
@@ -461,8 +461,8 @@
 	const float zoom_sensitivity = 0.5f;
 	const float pan_sensitivity = 300.f;
 
-	float pan_x = pan_sensitivity * dt * ndof->tx / sima->zoom;
-	float pan_y = pan_sensitivity * dt * ndof->ty / sima->zoom;
+	float pan_x = pan_sensitivity * dt * ndof->tvec[0] / sima->zoom;
+	float pan_y = pan_sensitivity * dt * ndof->tvec[1] / sima->zoom;
 
 	/* "mouse zoom" factor = 1 + (dx + dy) / 300
 	 * what about "ndof zoom" factor? should behave like this:
@@ -470,7 +470,7 @@
 	 * move forward -> factor > 1
 	 * move backward -> factor < 1
 	 */
-	float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tz;
+	float zoom_factor = 1.f + zoom_sensitivity * dt * -ndof->tvec[2];
 
 	sima_zoom_set_factor(sima, ar, zoom_factor);
 	sima->xof += pan_x;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2011-08-02 07:08:22 UTC (rev 38916)
@@ -931,43 +931,19 @@
 // NDOF utility functions
 // (should these functions live in this file?)
 float ndof_to_angle_axis(struct wmNDOFMotionData* ndof, float axis[3])
-	{
-	const float x = ndof->rx;
-	const float y = ndof->ry;
-	const float z = ndof->rz;
+{
+	return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
+}
 
-	float angular_velocity = sqrtf(x*x + y*y + z*z);
-	float angle = ndof->dt * angular_velocity;
-
-	float scale = 1.f / angular_velocity;
-
-	// normalize 
-	axis[0] = scale * x;
-	axis[1] = scale * y;
-	axis[2] = scale * z;
-
-	return angle;
-	}
-
 void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
-	{
-	const float x = ndof->rx;
-	const float y = ndof->ry;
-	const float z = ndof->rz;
+{
+	float axis[3];
+	float angle;
 
-	float angular_velocity = sqrtf(x*x + y*y + z*z);
-	float angle = ndof->dt * angular_velocity;
+	angle= ndof_to_angle_axis(ndof, axis);
+	axis_angle_to_quat(q, axis, angle);
+}
 
-	// combined scaling factor -- normalize axis while converting to quaternion
-	float scale = sin(0.5f * angle) / angular_velocity;
-
-	// convert axis-angle to quaternion
-	q[0] = cos(0.5f * angle);
-	q[1] = scale * x;
-	q[2] = scale * y;
-	q[3] = scale * z;
-	}
-
 static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 // -- "orbit" navigation (trackball/turntable)
 // -- zooming
@@ -987,7 +963,7 @@
 		const float pan_sensitivity = 1.f;
 	
 		// rather have bool, but...
-		int has_rotation = rv3d->viewlock != RV3D_LOCKED && (ndof->rx || ndof->ry || ndof->rz);
+		int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
 	
 		float view_inv[4];
 		invert_qt_qt(view_inv, rv3d->viewquat);
@@ -998,19 +974,19 @@
 			ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
 		#endif
 	
-		if (ndof->tz) {
+		if (ndof->tvec[2]) {
 			// 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;
+			float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2];
 			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};
+			float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f};
 			mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
 	
 			/* transform motion from view to world coordinates */
@@ -1072,7 +1048,7 @@
 				mul_qt_v3(view_inv, xvec);
 	
 				/* Perform the up/down rotation */
-				angle = rot_sensitivity * dt * ndof->rx;
+				angle = rot_sensitivity * dt * ndof->rvec[0];
 				if (invert)
 					angle = -angle;
 				rot[0] = cos(angle);
@@ -1080,7 +1056,7 @@
 				mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
 	
 				/* Perform the orbital rotation */
-				angle = rot_sensitivity * dt * ndof->ry;
+				angle = rot_sensitivity * dt * ndof->rvec[1];
 				if (invert)
 					angle = -angle;
 	
@@ -1155,11 +1131,10 @@
 		const float vertical_sensitivity = 0.4f;
 		const float lateral_sensitivity = 0.6f;
 
-		float pan_vec[3] = {
-			lateral_sensitivity * ndof->tx,
-			vertical_sensitivity * ndof->ty,
-			forward_sensitivity * ndof->tz
-			};
+		float pan_vec[3] = {lateral_sensitivity * ndof->tvec[0],
+		                    vertical_sensitivity * ndof->tvec[1],
+		                    forward_sensitivity * ndof->tvec[2]
+		                   };
 
 		mul_v3_fl(pan_vec, speed * dt);
 #endif

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_fly.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	2011-08-02 07:08:22 UTC (rev 38916)
@@ -953,9 +953,9 @@
 		// ^^ this is ok for default cube scene, but should scale with.. something
 
 		float trans[3] = {
-			lateral_sensitivity * ndof->tx,
-			vertical_sensitivity * ndof->ty,
-			forward_sensitivity * ndof->tz
+			lateral_sensitivity * ndof->tvec[0],
+			vertical_sensitivity * ndof->tvec[1],
+			forward_sensitivity * ndof->tvec[2]
 			};
 
 		if (fly->use_precision)
@@ -969,7 +969,7 @@
 		if (flag & NDOF_FLY_HELICOPTER)
 			{
 			// replace world z component with device y (yes it makes sense)
-			trans[2] = speed * dt * vertical_sensitivity * ndof->ty;
+			trans[2] = speed * dt * vertical_sensitivity * ndof->tvec[1];
 			}
 
 		if (rv3d->persp==RV3D_CAMOB) {

Modified: trunk/blender/source/blender/editors/transform/transform_ops.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_ops.c	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/editors/transform/transform_ops.c	2011-08-02 07:08:22 UTC (rev 38916)
@@ -361,10 +361,10 @@
 	TransInfo *t = op->customdata;
 
 	if (event->type == NDOF_MOTION)
-		{
-		// puts("transform_modal: passing through NDOF_MOTION");
+	{
+		/* puts("transform_modal: passing through NDOF_MOTION"); */
 		return OPERATOR_PASS_THROUGH;
-		}
+	}
 
 	/* XXX insert keys are called here, and require context */
 	t->context= C;

Modified: trunk/blender/source/blender/windowmanager/WM_types.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_types.h	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/windowmanager/WM_types.h	2011-08-02 07:08:22 UTC (rev 38916)
@@ -389,8 +389,8 @@
 	/* awfully similar to GHOST_TEventNDOFMotionData... */
 	// Each component normally ranges from -1 to +1, but can exceed that.
 	// These use blender standard view coordinates, with positive rotations being CCW about the axis.
-	float tx, ty, tz; // translation
-	float rx, ry, rz; // rotation:
+	float tvec[3]; // translation
+	float rvec[3]; // rotation:
 		// axis = (rx,ry,rz).normalized
 		// amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg]
 	float dt; // time since previous NDOF Motion event

Modified: trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2011-08-02 07:02:40 UTC (rev 38915)
+++ trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2011-08-02 07:08:22 UTC (rev 38916)
@@ -2323,13 +2323,13 @@
 
 	const float s = U.ndof_sensitivity;
 
-	data->tx = s * ghost->tx;
-	data->ty = s * ghost->ty;
-	data->tz = s * ghost->tz;
+	data->tvec[0]= s * ghost->tx;
+	data->tvec[1]= s * ghost->ty;
+	data->tvec[2]= s * ghost->tz;
 
-	data->rx = s * ghost->rx;
-	data->ry = s * ghost->ry;
-	data->rz = s * ghost->rz;
+	data->rvec[0]= s * ghost->rx;
+	data->rvec[1]= s * ghost->ry;
+	data->rvec[2]= s * ghost->rz;
 
 	data->dt = ghost->dt;
 




More information about the Bf-blender-cvs mailing list