WorldTranslation vs LocalTranslation?

Hey,

yep this is another newbie question, can anyone please explain the difference between WorldTranslation and LocalTranslation?

LocalTranslation (as are the other transforms) are the transformations for an object in model (or local) coordinates, centered at the origin. So if lets say you move 5 units along the +X axis from the origin, your local translation is (5,0,0) - and the model would appear much like how it would in your modeling tool.



WorldTranslation on the other hand is the absolute transformation values for an object in the "world". If say the object mentioned before is attached to a Node, and we move that node another 5 units along the +X axis, it'll also moves the child object. So the child object's world translation will be (10,0,0).



At least that's how it's in jmonkey, since it has to do with the scenegraph. Usually in graphics you may hear about a world matrix - which is used to transform vertices to their desired position in the world (usually not anywhere near the origin). That's essentially the composition of the world scale, rotation, translation values from jmonkey, to give some perspective.



Having local/world transform values is also usually helpful if lets say you wanted to use scenegraph nodes as pivot points for meshes. E.g. A turret on a tank. You only want to rotate it (about the origin), you leave it's local translation alone and attach it to a node. The node you attached it, is then what you move around the world, so that way when you rotate the turret you're always rotating it about the origin, even though it may not be near the origin.

1 Like

But be careful: if you want to use worldvector right after creation or attachment of a node

you have to use


n.updateWorldVectors();



Actually I don't know if this is done in before/after-update-cycle.

To test the behaviour:

import com.jme.app.SimpleGame;
import com.jme.scene.Node;

public class Test extends SimpleGame{

   Node n,n2;
   
   @Override
   protected void simpleInitGame() {
      n = new Node("n");
      n.getLocalTranslation().set(1,1,1);
      n2 = new Node("n2");
      n2.getLocalTranslation().set(2,2,2);
      n.attachChild(n2);
      System.out.println("BEFORE:");
      System.out.println(n.getWorldTranslation());
      System.out.println(n2.getWorldTranslation());
      n.updateWorldVectors();
      n2.updateWorldVectors();
      System.out.println("AFTER:");
      System.out.println(n.getWorldTranslation());
      System.out.println(n2.getWorldTranslation());

   }


   public static void main(String[] args)
   {
      new Test().start();
   }
   
}



This is really not a cool behaviour...

thank you guys, this is very helpful :smiley:

ttrocha said:

But be careful: if you want to use worldvector right after creation or attachment of a node
you have to use

n.updateWorldVectors();



Actually I don't know if this is done in before/after-update-cycle.



During the geometric update cycle right after the spatial's controllers. The same goes with the world bound, if you need to get any world data right away (like maybe even during the update, before your changes take effect in the next update cycle), it usually does some good making sure the data's up to date and available. In the past I've had some cases where I'd end up getting back a world bound that didn't exist which messed me up, so it's always good to understand what's going under the hood, so you can know how to use the scenegraph.