[SOLVED] Jme3 Beginner: Funky rotation bug

Hello, I have a bug in my rotation function that took me some time to realize it’s happening.

my rotation function rotates around the Z axis by passing a Quaternion to the function that initiates the rotation.

My rotation function goes likes this:


public void rotateSpatials(String id, float trigger_time, float theta, float duration)


final Spatial spatialToMove = rootNode.getChild( id);

float drive_rotation = theta; // theta rotation in degrees

float rot_duration = duration; // duration of the rotation

float rot_in_rad = FastMath.PI * drive_rotation / 180; // convert from rad to degrees

float[] rotation = {0,0, rot_in_rad};

// RotationTrack is a pre-existing Cinematic event that rotates the spatial

cinematic.addCinematicEvent(trigger_time, new RotationTrack(spatialToMove, rotation, rot_duration));


this works pretty well until I rotate from higher to lower angles like from {0,0, 155.147} to {0, 0, 91.12} where it rotates on a completely different access (weird huh?) and ends the the right final position (like a side flip) and continues just fine. If I replace the rotation from {0,0, 3.43} to {0,0,91.12} for example, it works just fine (without that funky flip).

So the question is. WHATS GOING ON ??? :stuck_out_tongue:

Note that all thetas passed are being normalized so that’s not the issue.

mhhh… that’s due to a bad design of the rotation track (that’s on me, I designed it :p), the interpolation is made linearly on the angles of the rotation instead of slerping the quaternions…

The side effect is that there might be some gimbal lock occurring at some point screwing the rotation.

My math skills really sucked back then…not that it’s really brilliant now but …well i’ll fix this and keep you informed.

Note to every students of this forum : Don’t skip math class if you expect to make video games later. :stuck_out_tongue:

Glad to hear! I was going crazy haha

Thanks Nehon

@nehon did you get a chance to fix that rotation bug?

it’s fixed in last SVN

the thing is…this gonna be deprecated very soon.

There is now SpatialAnimation implemented and for simple things like changing the transforms of a spatial over time it should be the prefered way.

You should maybe look into it.

1 Like


i’ll look at it since i’m not really doing anything complicated. I apologize in advance if this may sound silly but to be able to use the new code from the new SVN should I update the whole code?

you can wait for the nightly build, or use your own compiles JME3 see that doc → https://wiki.jmonkeyengine.org/legacy/doku.php/sdk:use_own_jme

also you now have to use quaternions with the rotation track :

Quaternion rotation = new Quaternion().fromAngleAxis(rot_in_rad, Vector3f.UNIT_Z);

// RotationTrack is a pre-existing Cinematic event that rotates the spatial

cinematic.addCinematicEvent(trigger_time, new RotationTrack(spatialToMove, rotation, rot_duration));

1 Like

Would it be possible to update the code on the wiki: http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/core/com/jme3/cinematic/events/RotationTrack.java?r=6681

so I could have it explicitly called form inside the code?

How often do you guys release a nightly build?

garnaout said:
How often do you guys release a nightly build?

Every time a night occur.


Yeah, you get these through the SDK updates too, no need to download or reference any jar files manually.

What if I am using Eclipse :s? I wish I had the option to use JMP but it’s not my option.

…then you need to download the libraries, as stated in the wiki.

so everytime I need to update I need to do this long process?

[java]Download jme3 project from svn

Make your changes

Compile jme3 project

Go to Tools → Libraries

Press "New Library"

Name it "jme3-modified"

Press "Add Jar/Folder"

Select jMonkeyEngine3.jar from the dist dir of the compiled jme3 version

Add the src folder of the jme3 project in the "sources" tab

Optionally javadoc in the "javadoc" tab

Press "OK"

Right-click your project and select "Properties"

Select "Libraries" to the left

Remove the "jme3" library

Press "Add Library" and select the "jme3-modified" library[/java]

Can I not use Subversion or something?

or maybe following the the tutorial: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:setting_up_jme3_in_eclipse - simply replace the new lib jar files with the old one?

would that work?

no if you use eclipse then just download the nightly build inside this zip file you have a jMonkeyEngine.jar file.

Put it in your lib folder and it should be ok.

Yup it’s definitely solved now!

Thanks guys