yn97
1
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?
1 Like
sgold
2
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
pspeed
3
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
yn97
4
thank you, getWorldRotation().toAngleAxis(Vector3f.UNIT_Y);
solved the problem.
sgold
5
getWorldRotation().toAngleAxis(Vector3f.UNIT_Y);
has a high probability of modifying Vector3f.UNIT_Y
.
yn97
6
but the result is the same as I set (3.1066813f)
. what is the better way?
pspeed
8
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