Restore spatial axis to absolute position

hi all

suppose i rotate a spatial, i’d like to restore spatial x y z axis ,but not the spatial, to initial location

if someone help me how to include an image i can show you what i mean

What do you mean? You are rotating the spatial a few times and after that you want to restore its original (local) rotation?

For that you could do


Quaternion orig = spatial.getLocalRotation().clone();

//rotate the spatial

//reset the rotation



but with spatial.setLocalRotation(orig) the spatial rotate with its axis.

I just want to bring spatial axis x y z to origin position.

I mean i rotate the spatial and after that I want that the spatial remain in that position but axis x y z return to origin position.

What I want is to rotate the spatial not on its axis but on world axis

Hmm i think i understand now:

You want the local rotation to be set to (0,0,0), so you have to adjust the world rotation accordingly (NOT POSSIBLE), so that the spatial retains its rotation.

I really really hope that works, if not, someone more expirienced on this forums will have to help us :frowning:


ArrayList<Quaternion> rotations = new ArrayList<Quaternion>();

Spatial originalSpatial = null;

Quaternion worldRotation = originalSpatial.getWorldRotation().clone();

Spatial sp = originalSpatial;

while (sp.getParent() != null) {

rotations.add(0, sp.getLocalRotation());



for (Iterator<Quaternion> iter = rotations.iterator(); iter.hasNext(); ) {

Quaternion rotation =;






EDIT: removed originalSpatial.updateGeometricState();

ummm a real thanks for your reply but…

suppose you rotate the spatial pi/2 on the right and then pi/2 up.The spatial does not follow mouse drag direction.

The axis xyz have to return to origin position but not the spatial

i found that


bring the spatial to original position but i want that just spatial axis x y z move to original position not the spatial

i want to reset x y z spatial axis.


does not work as well.

If I try to detach the spatial from the rootnode and attach it again ,could not exist a smart work around?

If you modify the spatials local transforms, you have to update its geometric state first, before you can alter its world transforms in the same update loop




i hope this works

In my RawInputListener implementation I’ve done

[java] public void onMouseMotionEvent(MouseMotionEvent evt) {

if (buttonPressed) {

Quaternion qy = new Quaternion();

Quaternion qx = new Quaternion();

qx.fromAngleAxis(x0.01f, Vector3f.UNIT_Y);

0.01f, Vector3f.UNIT_X);




public void onMouseButtonEvent(MouseButtonEvent evt) {

buttonPressed = evt.isPressed();

if (evt.isReleased()) {






So if I rotate the spatial down 90° and then rotate spatial right 90°, it rotate not in mouse drag direction but on screen normal axis!

I really need to reset world rotation axis without touch spatial axis

I dont get it :frowning:

But im pretty sure you can not modify the world rotation directly (sry for posting wrong code): the world rotation is calculated after every update, based on ALL local rotations in the rootNode tree.


public void onMouseMotionEvent(MouseMotionEvent evt) {

if (buttonPressed) {

Quaternion q=new Quaternion();

q.fromAngles(-y0.01f, x0.01f, 0f);





Would this rotate the spatial correctly?

Oh-my-god!!! Dilembo, delete that code now!!!

getXXX().set() = NO GO!

updateXXX() = NO GO!

normen sorry?

I prefer


and a sort of spatial axis reset when mouse is released


public void onMouseButtonEvent(MouseButtonEvent evt) {

buttonPressed = evt.isPressed();

if (evt.isReleased()) {

// here the unknown spatial axis reset …???



Dont do things like getLocalTranslation().set() and dont call updateGeometricState, updateLogicState or any of the updateXXX methods.

Wouldnt you need updateGeometricState() if you modified the local transforms in order to get the “fresh” world transform in the same update method?


so normen please suggest us a solution

oh my god oh my god

Oh sorry my bad, i read an old issue

It was node.updateWorldVectors() back then!!

dilembo said:
so normen please suggest us a solution

already studied it’s not enough for my problem

nego said:
Oh sorry my bad, i read an old issue
It was node.updateWorldVectors() back then!!

does not exist in jme3
what do u mean nego?

You can find out the “local world location” between an a spatial and an arbitrary parent like this:


private static Transform getTransform(Spatial spat, Spatial parent) {

Transform shapeTransform = new Transform();

Node parentNode = spat.getParent();

Spatial currentSpatial = spat;

while (parentNode != null && parentNode != parent) {


currentSpatial = parentNode;

parentNode = currentSpatial.getParent();


return shapeTransform;



Is that enough? :stuck_out_tongue: