mercredi 6 mai 2015

glMatrix quaternion rotation

Can anyone explain to me why this doesn't work as I would expect.

Using a quaternion to rotate a vec3 [5,0,0] 180degree/Math.PI radians around the z axis.

I would think the result would be [-5,0,0]; Rotating [5,5,0] gives [-5,-5,0] as expected.

http://ift.tt/1RdjjQS

var q = quat.create();
quat.rotateZ(q, q, Math.PI);
console.log(q);

var v = vec3.fromValues(5, 0, 0);
vec3.transformQuat(v, v, q);
console.log(v);

/*
[0, 0, 1, 6.123234262925839e-17]
[-5, 6.123233998228043e-16, 0]
*/

var q2 = quat.create();
quat.rotateZ(q2, q2, Math.PI);
console.log(q2);

var v2 = vec3.fromValues(5, 5, 0);
vec3.transformQuat(v2, v2, q2);
console.log(v2);

/*
[0, 0, 1, 6.123234262925839e-17]
[-5, -5, 0]
*/

Aucun commentaire :

Enregistrer un commentaire