From 70b4758ff8756a55a1c88156a852b80a0d3c2ef9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 2 Aug 2011 07:08:22 +0000 Subject: 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. --- source/blender/editors/space_image/image_ops.c | 6 +-- source/blender/editors/space_view3d/view3d_edit.c | 63 +++++++--------------- source/blender/editors/space_view3d/view3d_fly.c | 8 +-- source/blender/editors/transform/transform_ops.c | 6 +-- source/blender/windowmanager/WM_types.h | 4 +- .../blender/windowmanager/intern/wm_event_system.c | 12 ++--- 6 files changed, 37 insertions(+), 62 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index a7c90bb0aed..6e84c1a7f0c 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -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; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 09e703d6ce0..8d77aeaea1b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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 diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 38d93ab59f3..5c53faf96a6 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -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) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index a779982099e..0efd25c4faa 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -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; diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 7476410ec19..7fd52e89a5f 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -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 diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 322cd3b5642..0abae2e06b7 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -2323,13 +2323,13 @@ static void attach_ndof_data(wmEvent* event, const GHOST_TEventNDOFMotionData* g 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; -- cgit v1.2.3