fixed the cube example

git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/libspnav@81 ef983eb1-d774-4af8-acfd-baaf7b16a646
pull/2/head
John Tsiombikas 2009-02-11 05:23:34 +00:00
rodzic f250cf1598
commit a51f7fca58
3 zmienionych plików z 3 dodań i 14 usunięć

Wyświetl plik

@ -258,9 +258,9 @@ int handle_event(XEvent *xev)
/* if so deal with motion and button events */ /* if so deal with motion and button events */
if(spev.type == SPNAV_EVENT_MOTION) { if(spev.type == SPNAV_EVENT_MOTION) {
/* apply axis/angle rotation to the quaternion */ /* apply axis/angle rotation to the quaternion */
float angle = 0.000005 * sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz)); float axis_len = sqrt(SQ(spev.motion.rx) + SQ(spev.motion.ry) + SQ(spev.motion.rz));
rot = quat_rotate(rot, angle, -spev.motion.rx, -spev.motion.ry, spev.motion.rz); rot = quat_rotate(rot, axis_len * 0.001, -spev.motion.rx / axis_len,
rot = quat_normalize(rot); -spev.motion.ry / axis_len, spev.motion.rz / axis_len);
/* add translation */ /* add translation */
pos.x += spev.motion.x * 0.001; pos.x += spev.motion.x * 0.001;

Wyświetl plik

@ -16,7 +16,6 @@ static inline float v3_dot(vec3_t v1, vec3_t v2);
static inline quat_t quat_cons(float s, float x, float y, float z); static inline quat_t quat_cons(float s, float x, float y, float z);
static inline vec3_t quat_vec(quat_t q); static inline vec3_t quat_vec(quat_t q);
static inline quat_t quat_mul(quat_t q1, quat_t q2); static inline quat_t quat_mul(quat_t q1, quat_t q2);
static inline quat_t quat_normalize(quat_t q);
static inline void quat_to_mat(mat4_t res, quat_t q); static inline void quat_to_mat(mat4_t res, quat_t q);
quat_t quat_rotate(quat_t q, float angle, float x, float y, float z); quat_t quat_rotate(quat_t q, float angle, float x, float y, float z);

Wyświetl plik

@ -46,16 +46,6 @@ static inline quat_t quat_mul(quat_t q1, quat_t q2)
return res; return res;
} }
static inline quat_t quat_normalize(quat_t q)
{
float len = sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
q.x /= len;
q.y /= len;
q.z /= len;
q.w /= len;
return q;
}
static inline void quat_to_mat(mat4_t res, quat_t q) static inline void quat_to_mat(mat4_t res, quat_t q)
{ {
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, 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,