Is .rotate() in radians? Because I can't get it to work

Hey everyone,

I’m trying to rotate a planet. I’m using the rotate(float, float, float) function to rotate a spatial.
I want it to rotate -90 degrees (-0.5 radians) on the x-axis and 23.5 degrees (0.41 radians) on the y-axis.
Thus, I write:


pc is a planet control, don’t worry about that. It doesn’t rotate anything.

This is the result:

What am I doing wrong?

BTW, I don’t really understand Quaternions, but I’d like to use them. Can someone please send a link or explain it or give an example?

O yeah,

when I dont rotate, I get the following:

Don’t worry few us us really understand Quaternions, if it’s even possible. They’re easy enough to use in JME though.

Someone can jump in and correct me if I’m wrong here, but I think when constructing a Quaternion from Euler angles as in that tutorial (quat.fromAngles(x,y,z)) you need to remember they are applied in a specific order, in JME’s case that is YZX.

So if it were me to get your rotation I would do

Quaternion r1 = new Quaternion();
r1.fromAngleAxis(xAmount, Vector3f.UNIT_X);//xAmount around X

Quaternion r2 = new Quaternion();
r2.fromAngleAxis(yAmount, Vector3f.UNIT_Y);//yAmount around Y

r1 = r1.mult(r2);

The order in the mult step matters, so in this case its the X rotation, then the result is rotated around Y.

Annnnnd as I typed this I realised your -90 degrees value in radians is wrong

The rotate mehtod does use angles in radian, like the documentation of this method says:
Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians), (aka pitch, yaw, roll) in the local coordinate space.

You can directly insert you angles in degrees if you multiply it with pi/180 like that:
spatial.rotate(0, 90 * FastMath.DEG_TO_RAD, 0);

Here is a link to a tutorial which explains vectors and quaternions in JME:

If you still have questions feel free to ask!

90 degrees is not 0.5 radians. 90 degrees is PI/2 radians.

Just a note in case you meant something else… it would be clearer to say “around the X-axis”. Rotating a planet around the x-axis is strange so I thought I’d clarify that point. For example, if you wanted to simulate time of day then you’d rotate around the y axis.

Yes that’s π0.5
With “0.5” I meant 0.5

I understand what you mean by this, and yes, I want to rotate it on (around) the X axis. As you can see in the non-rotated picture, the north pole points towards the sun. It should point kind of upwards.

Then your code is wrong.

It’s really tough to help people who don’t post the ACTUAL code.

Yes, but the actual code is like a huzzled combination of spaghetti, tomatoes, meatballs, and weird back and fro references. It’s supposed to be neatly organised, but I haven’t put enough time into it. Thus I checked my code and gave the lines I thought were important to save some of your time.

I solved the problem by multiplying Math.PI. I forgot that. :upside_down:

So basically this:

1 Like

More like:

1 Like