diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-18 16:51:11 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-18 16:55:58 +0400 |
commit | dcdb4eaf9cce1f3ff84bbe221ebafd20c2371541 (patch) | |
tree | 794f2700130434d78435166532f0b813e0a0b3f7 /source/blender/windowmanager | |
parent | 13553876ba3e18f49c2199d9c21f53ff2d8b2e41 (diff) |
NDOF: Fix for fly/walk mode ignoring axis invert options
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 7 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 46 |
3 files changed, 55 insertions, 8 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 8a13decea42..c88c5496ea6 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -65,6 +65,7 @@ struct wmDrag; struct ImBuf; struct ImageFormatData; struct ARegion; +struct wmNDOFMotionData; typedef struct wmJob wmJob; @@ -435,6 +436,12 @@ bool write_crash_blend(void); /* Lock the interface for any communication */ void WM_set_locked_interface(struct wmWindowManager *wm, bool lock); +void WM_event_ndof_pan_get(const struct wmNDOFMotionData *ndof, float r_pan[3], const bool use_zoom); +void WM_event_ndof_rotate_get(const struct wmNDOFMotionData *ndof, float r_rot[3]); + +float WM_event_ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3]); +void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4]); + #ifdef __cplusplus } #endif diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 8bbdd7bd736..c93ed89d78f 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -481,14 +481,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. */ - union { - float tvec[3]; /* translation */ - struct { float tx, ty, tz; }; - }; - union { - float rvec[3]; /* rotation: */ - struct { float rx, ry, rz; }; - }; + 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 47fdb37d403..5254bff99cd 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -3322,3 +3322,49 @@ void WM_set_locked_interface(wmWindowManager *wm, bool lock) */ BKE_spacedata_draw_locks(lock); } + + +/* -------------------------------------------------------------------- */ +/* NDOF */ + +/** \name NDOF Utility Functions + * \{ */ + + +void WM_event_ndof_pan_get(const wmNDOFMotionData *ndof, float r_pan[3], const bool use_zoom) +{ + int z_flag = use_zoom ? NDOF_ZOOM_INVERT : NDOF_PANZ_INVERT_AXIS; + r_pan[0] = ndof->tvec[0] * ((U.ndof_flag & NDOF_PANX_INVERT_AXIS) ? -1.0f : 1.0f); + r_pan[1] = ndof->tvec[1] * ((U.ndof_flag & NDOF_PANY_INVERT_AXIS) ? -1.0f : 1.0f); + r_pan[2] = ndof->tvec[2] * ((U.ndof_flag & z_flag) ? -1.0f : 1.0f); +} + +void WM_event_ndof_rotate_get(const wmNDOFMotionData *ndof, float r_rot[3]) +{ + r_rot[0] = ndof->rvec[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -1.0f : 1.0f); + r_rot[1] = ndof->rvec[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -1.0f : 1.0f); + r_rot[2] = ndof->rvec[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -1.0f : 1.0f); +} + +float WM_event_ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3]) +{ + float angle; + angle = normalize_v3_v3(axis, ndof->rvec); + + axis[0] = axis[0] * ((U.ndof_flag & NDOF_ROTX_INVERT_AXIS) ? -1.0f : 1.0f); + axis[1] = axis[1] * ((U.ndof_flag & NDOF_ROTY_INVERT_AXIS) ? -1.0f : 1.0f); + axis[2] = axis[2] * ((U.ndof_flag & NDOF_ROTZ_INVERT_AXIS) ? -1.0f : 1.0f); + + return ndof->dt * angle; +} + +void WM_event_ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4]) +{ + float axis[3]; + float angle; + + angle = WM_event_ndof_to_axis_angle(ndof, axis); + axis_angle_to_quat(q, axis, angle); +} + +/** \} */ |