toAngles() - z axis rotation in degrees

Is it possible to translate this “physicsNode.getLocalRotation().getZ()” to degree? Is it actuallly possible to get the angle for a rotation of a physicsObject in degree?


getLocalRotation returns a quaternion.

The z attribute of a quaternion is not related to rotation around z axis.

However if you look closely in the class, there is a toAngles method that returns a 3 components float array.

The values returned are in radians, to get them in degrees multiply them by FastMath.RAD_TO_DEG

1 Like

Thank you very much. A very helpful hint. But the values I receive seem to be weired. When the object rotates to the left on the z axis the degrees go from 0 to 90 in the first quarter rotation. Then back to 0 and in the third quarter rotation to -90. In the last quarter rotation back to 0.

I’m really sorry for double posting, but I’m completely stuck. Is my code the problem or is it the normal way toAngles returns the angle?

I don’t get what’s the problem here?

I expected an angle from 0-180 in the first half of the rotation and -180-0 in the second half. But i get this:

1.quarter: 0, 1, 2, … 89, 90

2.quarter: 90, 89, … 1, 0

3.quarter: 0, -1, … -89, -90

4.quarter: -90, -89, … -1, 0

For my prupose I need the angle from 0 to 360 degrees. What would be no problem with the angles i described in the first sentence.

I’ll post some code when I’m at home.

This is the normal way for pitch yes.

You should read the article linked in the method javadoc

Thanks, but I’m not a native speaker what makes it hard for me to understand everything. What I understood is that the attitude gets converted by asin and heading and bank by atan2. So I was just wondering if it’s possible to write a method that converts the heading by atan2?

Hot-Chip said:
So I was just wondering if it's possible to write a method that converts the heading by atan2?

Don't think so it wouldn't give you the right result.

I don't really know if there is a way of getting a 0 to 360 degrees pitch rotation from a quaternion, it's honestly over my math knowledge.
But maybe if you explain what you are trying to do on a more abstract level, i could help you find a way around this.
Why do you want the physicNode pitch in degrees in the first place?

I’m working on a game control which should feel like the control from the game spore in the cell phase. It’s top-down view and you can steer your player by clicking with the mouse where the player should go to. Then the playerobject rotates in the direction and gains speed. I’m using forces to do that. Through the fact that I need the current angle on the z axis I have an extra variable which stores the angle. Then I apply the rotation by “playerObject.setLocalRotation(Quaternion);”. But I know that’s bad style and unfortunately it makes the movement of the object less smooth, because while the rotation is beeing applied it doesn’t move in the direction the forces beeing applied. I actually want to rotate the object by using “playerObject.setAngularVelocity();” but therefor I need the current angle to make it stop rotating when it reached the destination angle.

Here some speudocode to make the problem more clear:


float difX = mouseVec.x - playerVec.x;

float difY = mouseVec.y - playerVec.y;

//The vectors are display coordinates.

destinationAngle = (int)(FastMath.atan2(difX, difY) * 180 / FastMath.PI);

playerNode.roateToDestinationAngle(); //playerNode is a PhysicsNode

forwardDirection = playerNode.getLocalRotation().getRotationColumn(1);



As you have found out yourself somehow already, you have to do everything by forces to get good results. This inevitably means something like a fly-by-wire system that actually gives counter forces to achieve the physics node movement rather than just setting a physics nodes location or rotation. Its as if you were “beaming” around in the real world, sure to yield funny results :wink: