Rotation by Euler angles leads to information loss?


When fetching the Euler rotation angles with Quaternion.toAngles() and feeding them directly to Quaternion.fromAngles() I get some very strange results:

float[] angles = localRotation.toAngles(null);

This results in the node rotation suddenly "skipping" to a certain rotation and afterwards being unable to rotate back again. Why is this?

I've got a bicycle (the Node in question) which I want to follow the terrain. I do this by finding the triangle directly below it, creating a Plane from the three points and then using the utility function Spatial.rotateUpTo(). However, this rotates the bike also around the z-axis (leaning to the left/right) which isn't realistic for a bicycle. Thus I want to rotate it back up to 0 degrees rotation around the z-axis, but I'm not that familiar with representing rotations by quaternions or rotational matrices. So can anyone tell me how I can set the rotation around the z-axis to 0 without disturbing the rotation around the other axes, and without the use of Euler angles? :)

Thank you,

Actually, there are a million ways to rotate about three axis and end up at the same spot.

You could have a look at AbstractCamera.lookAt() which has an implementation of changing orientation maintaining an up-ward direction fixed. In this case, Y-axis would be your up, and thus, no rotation in the Z-axis would be done.