Made wmNDOFMotionData use a vector rather then xyz members, makes it nicer to use...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 2 Aug 2011 07:08:22 +0000 (07:08 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 2 Aug 2011 07:08:22 +0000 (07:08 +0000)
ndof_to_angle_axis and ndof_to_quat now use math functions.

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

index 8faf1af..8fed3a9 100644 (file)
@@ -271,7 +271,7 @@ class InputKeyMapPanel:
             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 @@ class InputKeyMapPanel:
                 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':
index a7c90bb..6e84c1a 100644 (file)
@@ -461,8 +461,8 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
        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 @@ static int view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
         * 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;
index 09e703d..8d77aea 100644 (file)
@@ -931,42 +931,18 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
 // 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;
-
-       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;
-       }
+{
+       return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
+}
 
 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 angular_velocity = sqrtf(x*x + y*y + z*z);
-       float angle = ndof->dt * angular_velocity;
-
-       // combined scaling factor -- normalize axis while converting to quaternion
-       float scale = sin(0.5f * angle) / angular_velocity;
+{
+       float axis[3];
+       float angle;
 
-       // convert axis-angle to quaternion
-       q[0] = cos(0.5f * angle);
-       q[1] = scale * x;
-       q[2] = scale * y;
-       q[3] = scale * z;
-       }
+       angle= ndof_to_angle_axis(ndof, axis);
+       axis_angle_to_quat(q, axis, angle);
+}
 
 static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 // -- "orbit" navigation (trackball/turntable)
@@ -987,7 +963,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
                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 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
                        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 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
                                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 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event
                                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 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
                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
index 38d93ab..5c53faf 100644 (file)
@@ -953,9 +953,9 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
                // ^^ 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 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
                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) {
index a779982..0efd25c 100644 (file)
@@ -361,10 +361,10 @@ static int transform_modal(bContext *C, wmOperator *op, wmEvent *event)
        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;
index 7476410..7fd52e8 100644 (file)
@@ -389,8 +389,8 @@ typedef struct wmNDOFMotionData {
        /* 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
index 322cd3b..0abae2e 100644 (file)
@@ -2323,13 +2323,13 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g
 
        const float s = U.ndof_sensitivity;
 
-       data->t= s * ghost->tx;
-       data->t= s * ghost->ty;
-       data->t= s * ghost->tz;
+       data->tvec[0]= s * ghost->tx;
+       data->tvec[1]= s * ghost->ty;
+       data->tvec[2]= s * ghost->tz;
 
-       data->r= s * ghost->rx;
-       data->r= s * ghost->ry;
-       data->r= 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;