Skip to content

Commit a51f7fc

Browse files
committed
fixed the cube example
git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/libspnav@81 ef983eb1-d774-4af8-acfd-baaf7b16a646
1 parent f250cf1 commit a51f7fc

3 files changed

Lines changed: 3 additions & 14 deletions

File tree

examples/cube/cube.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ int handle_event(XEvent *xev)
258258
/* if so deal with motion and button events */
259259
if(spev.type == SPNAV_EVENT_MOTION) {
260260
/* apply axis/angle rotation to the quaternion */
261-
float angle = 0.000005 * sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz));
262-
rot = quat_rotate(rot, angle, -spev.motion.rx, -spev.motion.ry, spev.motion.rz);
263-
rot = quat_normalize(rot);
261+
float axis_len = sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz));
262+
rot = quat_rotate(rot, axis_len * 0.001, -spev.motion.rx / axis_len,
263+
-spev.motion.ry / axis_len, spev.motion.rz / axis_len);
264264

265265
/* add translation */
266266
pos.x += spev.motion.x * 0.001;

examples/cube/vmath.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static inline float v3_dot(vec3_t v1, vec3_t v2);
1616
static inline quat_t quat_cons(float s, float x, float y, float z);
1717
static inline vec3_t quat_vec(quat_t q);
1818
static inline quat_t quat_mul(quat_t q1, quat_t q2);
19-
static inline quat_t quat_normalize(quat_t q);
2019
static inline void quat_to_mat(mat4_t res, quat_t q);
2120
quat_t quat_rotate(quat_t q, float angle, float x, float y, float z);
2221

examples/cube/vmath.inl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ static inline quat_t quat_mul(quat_t q1, quat_t q2)
4646
return res;
4747
}
4848

49-
static inline quat_t quat_normalize(quat_t q)
50-
{
51-
float len = sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
52-
q.x /= len;
53-
q.y /= len;
54-
q.z /= len;
55-
q.w /= len;
56-
return q;
57-
}
58-
5949
static inline void quat_to_mat(mat4_t res, quat_t q)
6050
{
6151
m4_cons(res, 1.0 - 2.0 * q.y*q.y - 2.0 * q.z*q.z, 2.0 * q.x * q.y + 2.0 * q.w * q.z, 2.0 * q.z * q.x - 2.0 * q.w * q.y, 0,

0 commit comments

Comments
 (0)