Instead of Euler angles I moved to Quaternions to represent and process the rotation of a cube in 3D. Although it would solve gimbal lock, I'm still experiencing this issue.
My code is:
// p is the point to be rotated
// angles is a Vector3D representing the rotation angles
var xaxis = new Vector3D(1, 0, 0);
var yaxis = new Vector3D(0, 1, 0);
var zaxis = new Vector3D(0, 0, 1);
p = rotate(p, xaxis, angles.x);
p = rotate(p, yaxis, angles.y);
p = rotate(p, zaxis, angles.z);
The rotate
functions comes from http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Pseudo-code_for_rotating_using_a_quaternion_in_3D_space (translated into JavaScript).
I guess the problem is due to the fact that I still use an order of axes (x y z
) which is the main problem of gimbal lock.
How would one implement quaternion rotation in such a way that gimbal lock is solved?
Thanks in advance.