From 566fd3485a9d463b03150a42124edac79c135180 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 6 Dec 2010 08:34:13 +0000 Subject: [PATCH] fixed a bug in the cube example where zero rotational values would destroy the rotation quaternion making the cube disappear git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/libspnav@113 ef983eb1-d774-4af8-acfd-baaf7b16a646 --- examples/cube/cube.c | 8 +++++--- spnav.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/cube/cube.c b/examples/cube/cube.c index b904393..a348369 100644 --- a/examples/cube/cube.c +++ b/examples/cube/cube.c @@ -258,9 +258,11 @@ int handle_event(XEvent *xev) /* if so deal with motion and button events */ if(spev.type == SPNAV_EVENT_MOTION) { /* apply axis/angle rotation to the quaternion */ - float axis_len = sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz)); - rot = quat_rotate(rot, axis_len * 0.001, -spev.motion.rx / axis_len, - -spev.motion.ry / axis_len, spev.motion.rz / axis_len); + if(spev.motion.rx || spev.motion.ry || spev.motion.rz) { + float axis_len = sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz)); + rot = quat_rotate(rot, axis_len * 0.001, -spev.motion.rx / axis_len, + -spev.motion.ry / axis_len, spev.motion.rz / axis_len); + } /* add translation */ pos.x += spev.motion.x * 0.001; diff --git a/spnav.c b/spnav.c index fcb0d4b..3d61c8b 100644 --- a/spnav.c +++ b/spnav.c @@ -36,7 +36,7 @@ OF SUCH DAMAGE. #include #include "spnav.h" -#define SPNAV_SOCK_PATH "/var/run/spnav.sock" +#define SPNAV_SOCK_PATH "/var/run/spnav.sock" #ifdef USE_X11 #include