getWorldTranslation()?

I encountered a surprising problem with this function, so i did some testing.



Node A with localTranslation (10,5,0) attached to rootNode

Node B with localTranslation (0,5,10) attached to A



if i understand getWorldTranslation() right, the worldTranslation of B should be (10,10,10) now.

Because (10,5,0) + (0,5,10) = (10,10,10).



Now surprisingly (for me), this code:



Node A = new Node("A");
A.setModelBound(new BoundingBox());
A.setLocalTranslation(new Vector3f(10,5,0));
rootNode.attachChild(A);

Node B = new Node("B");
B.setModelBound(new BoundingBox());
B.setLocalTranslation(new Vector3f(0,5,10));
A.attachChild(B);

B.updateModelBound();
A.updateModelBound();

System.out.println("A local: "+A.getLocalTranslation());
System.out.println("A world: "+A.getWorldTranslation());
System.out.println("B local: "+B.getLocalTranslation());
System.out.println("B world: "+B.getWorldTranslation());


gives this result:
A local: com.jme.math.Vector3f [X=10.0, Y=5.0, Z=0.0]
A world: com.jme.math.Vector3f [X=10.0, Y=5.0, Z=0.0]
B local: com.jme.math.Vector3f [X=0.0, Y=5.0, Z=10.0]
B world: com.jme.math.Vector3f [X=0.0, Y=5.0, Z=10.0]


So.
Error on my side? Maybe in understanding of the function?
Or is this a bug in jME ?

World vectors are usually not updated automatically.



Your code works as expected if you call updateWorldVectors() on your B node:


    
     Node A = new Node("A");
     A.setModelBound(new BoundingBox());
     A.setLocalTranslation(new Vector3f(10,5,0));
     rootNode.attachChild(A);

     Node B = new Node("B");
     B.setModelBound(new BoundingBox());
     B.setLocalTranslation(new Vector3f(0,5,10));
     A.attachChild(B);

     B.updateWorldVectors();
    
     B.updateModelBound();
     A.updateModelBound();
    
     logger.info("A local: "+A.getLocalTranslation());
     logger.info("A world: "+A.getWorldTranslation());
     logger.info("B local: "+B.getLocalTranslation());
     logger.info("B world: "+B.getWorldTranslation());



Just be aware that world vectors have to be calculated based on their parent node world vectors. To avoid doing this for each calculation, graphic engines do it only when local vectors have changed. In this case all the world vectors in that branch have to be calculated (if you know they will not change you can lock the nodes in jME).

Take a look at the Spatial class source code for further info. Because I can't find where world vectors (locked or not) are updated by the engine :(.

Greetings,

J

Ahh. I must confess i never saw "updateWorldVectors()" so far.

That clears my problem. Thx very much.



Once again, i'm happy to see that the error was on my side and not on the jME side  :smiley:

You've probably typically seen updateGeometricState, which calls updateWorldVectors.