Node vs Spatial LocalTranslation

Can anyone please explain if I am correct in thinking a Spatial attached to a Node should inherit its Local Translation

i.e…

Spatial = -1.5,0,1.5
Node = 18,0,18
Resulting Spatial = 16.5,0,19.5

Is that correct or wrong because its not working like that :slight_smile:

The localTranslation is not inherited. However, the Node’s worldTranslation is propagated to Spatial’s worldTranslation.
If you check Spatial.getWorldTranslation() I think you will see that it matches your expectations.

Ah OK Thanks, that would be why it was not working :frowning:

Might be helpful:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

Ok so now I’m confused that explains that it works the way I expected

More testing I think

@madmunky said: Ok so now I'm confused that explains that it works the way I expected

More testing I think

Hard to say… since everything is a Spatial and nothing is a Spatial and you didn’t provide the relationship between “Spatial” and “Node”… so we are left to guess. Is one a child of the other? Is it the same object?

In general, more information = better. Less information = having to go back and forth five times to get the right information and waste everyone’s time. So it’s always better to err on the side of too much info… usually to include ACTUAL CODE.

i think i try to explain how i see it:

  1. There are 2 types of Spatial - “Node extends Spatial” and “Geometry extends Spatial”. So when you talking about “Spatial” that contains other “Spatials”, its a “Node”. On the other hand, when you talking about “Spatial”, that is visible on the screen, its “Geometry”.
    Conclusion is, when you talking about spatial, you are talking about everything attached to “rootNode”.

  2. Spatials have their translation in world space.
    2a) One is local translation. It is simply an offset relative to Spatial’s direct parent only (which is everytime Node class). So when local translation is 0,0,0 then spatial is on the same position as parent spatial, which can be for example 5,0,0. So then both spatials have world translation 5,0,0, so they are on same place.
    2b) Second is world translation. It can also be interpreted simply as a “sum of spatial’s translation and all its parents’ translations”.
    So when you have hiearchy:


Node a = new Node();
a.setLocalTranslation(5, 0, 0);
rootNode.attachChild(a);

Node b = new Node();
b.setLocalTranslation(5, 0, 0);
a.attachChild(b);

Node c = new Node();
c.setLocalTranslation(5, 0, 0);
b.attachChild(c);
  • Then local translation of all nodes is 5,0,0
  • But world translation of node a is 5,0,0, b is 10,0,0 and c is 15,0,0

since you can not set world translation directly, i suggest you to have some node everytime at 0,0,0. For example:


// you should never change translation or rotation of root node
Node spaceShips = new Node();
rootNode.attachChild(spaceShips); // spaceShips has local translation 0,0,0 and it acts as a general container for one type of objects

Geometry spaceShip = new Geometry();
spaceShip.setLocalTranslation(15,20,30);
spaceShips.attachChild(spaceShip);
// space ship has local translation 15,20,30, but since it is only spatial in hiearchy which dont have translation 0,0,0,
// you can calculate with it as it was -world translation-