[SOLVED] How can I get Y rotation of node?

I used this code to rotate a node for the test:
cubeNode.rotate(0, (3.1066813f), 0);

and I want to get the exact Y rotation from that node but not the same results:
cubeNode.getWorldRotation().getY();

the result is: 0.71934146

how can I solve it?

getWorldRotation() returns a quaternion, not a set of Euler angles.

To convert the Quaternion to Euler angles, use Quaternion.toAngles().

Note that if the rotation is around some axis other than Y, there are many possible ways to define the Y rotation.

Note that the angles are in radians and will “wrap around” at pi/2 or pi, depending on the axis.

1 Like

The only accurate way to do what you want is to keep track of the angle before you stuck it into rotate().

As sgold mentions, there are many ways that other approaches can go wrong.

1 Like

thank you, getWorldRotation().toAngleAxis(Vector3f.UNIT_Y); solved the problem.

getWorldRotation().toAngleAxis(Vector3f.UNIT_Y); has a high probability of modifying Vector3f.UNIT_Y .

but the result is the same as I set (3.1066813f). what is the better way?

But better still:

2 Likes

By the way, there is no way you got the same value back out using that approach. You must be mistaken.

You will never get better than +/- PI out of any of these methods.

1 Like