quat.toEuler undocumented
Hi there,
I recently noticed a typo in my code where I'd used a function name "quat.toEuler" instead of the documented API function "quat.toEulerAngles".
When I 'fixed' it to the documented function, I found that my code didn't work correctly any more.
After some debugging I discovered results like this:
input quat {x: 0, y: 0.948568, z: 0, w: 0.317172}
toEuler {x: 0, y: 2.49623, z: 0}
toEulerAngles {x: 3.14159, y: 0.645365, z: 3.14159}
If I convert these values back into quaternions then angleBetween correctly says that they are the same angle... but the whole point of converting to Euler angles is to use the angular components individually - and rotation around Y = 2.49 is not the same as Y = 0.645.
Can I safely continue to use toEuler even though it is undocumented as it appears to maintain a concept of 'up' whereas toEulerAngles does not?
Here is the test code for the above case:
var qt = new quat(0.317172, 0, 0.948568, 0);
print("input quat " + qt);
print("toEuler " + qt.toEuler());
print("toEulerAngles " + qt.toEulerAngles());
And here is the code which fails using toEulerAngles but works with toEuler:
const p = objectT.getWorldPosition();
var diff = currentDestination.position.sub(p);
diff.y = 0; // set direction difference to 'flat'
diff = diff.normalize();
const quatToDest = quat.lookAt(diff, vec3.up());
const eulToDest = quatToDest.toEulerAngles();
const quatFlat = quat.fromEulerAngles(0, eulToDest.y, 0);
const quatCurrent = objectT.getWorldRotation();
objectT.setWorldRotation( quat.slerp(quatCurrent, quatFlat, turnSpeed) );
const between = quat.angleBetween(quatCurrent, quatFlat); // used to determine when we are facing the destination
Or maybe you can suggest a different approach to the code which will work using toEulerAngles?
I think Vincent Tang could help us with this