Why does geom.setLocalTranslation(0, 0, 0) move the geom?

(FYI I came across this issue because I’m computing the translation and sometimes the translation is not needed.)

propably becouse Geometry is not locally in 0,0,0

there is no other way. check it in SceneComposer.

propably becouse Geometry is not locally in 0,0,0

I'm not sure what this means.

The box was created with center in (0,0,0). How do I know what the Geometry is locally in?

[java]Box topLeftCornerBox = new Box(Vector3f.ZERO, 5, 5, 5); // create cube shape at the origin

Geometry topLeftCornerGeom = new Geometry("Box", topLeftCornerBox); // create cube geometry from the shape

Material topLeftCornerMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material

topLeftCornerMat.setColor("Color", ColorRGBA.Blue); // set color of material to blue

topLeftCornerGeom.setMaterial(topLeftCornerMat); // set the cube's material

topLeftCornerGeom.setLocalTranslation(5, 5, 5);

topLeftCornerGeom.setLocalTranslation(0, 0, 0);

rootNode.attachChild(topLeftCornerGeom);[/java]

there is no other way. check it in SceneComposer.

How do I do this? I haven't needed to use it yet, everything is generated.

@kotoko said:

Why does geom.setLocalTranslation(0, 0, 0) move the geom?

(FYI I came across this issue because I'm computing the translation and sometimes the translation is not needed.)

How do you know it moved? Where did you expect it to be?

I was trying to simplify but I guess it’s best to show the whole code:

[java]Box topLeftCornerBox = new Box(Vector3f.ZERO, 5, 5, 5); // create cube shape at the origin

Geometry topLeftCornerGeom = new Geometry(“Box”, topLeftCornerBox); // create cube geometry from the shape

Material topLeftCornerMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material

topLeftCornerMat.setColor(“Color”, ColorRGBA.Blue); // set color of material to blue

topLeftCornerGeom.setMaterial(topLeftCornerMat); // set the cube’s material

topLeftCornerGeom.setLocalTranslation(5, 5, 5);

topLeftCornerGeom.setLocalTranslation(0, 0, 0);

Box topLeftCornerBox2 = new Box(Vector3f.ZERO, 5, 5, 5); // create cube shape at the origin

Geometry topLeftCornerGeom2 = new Geometry(“Box”, topLeftCornerBox2); // create cube geometry from the shape

Material topLeftCornerMat2 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // create a simple

// material

topLeftCornerMat2.setColor(“Color”, ColorRGBA.Yellow); // set color of material to blue

topLeftCornerGeom2.setMaterial(topLeftCornerMat2); // set the cube’s material

topLeftCornerGeom2.setLocalTranslation(5, 5, 5);

topLeftCornerGeom2.setLocalTranslation(1, 1, 1);

Box topLeftCornerBox3 = new Box(Vector3f.ZERO, 5, 5, 5); // create cube shape at the origin

Geometry topLeftCornerGeom3 = new Geometry(“Box”, topLeftCornerBox3); // create cube geometry from the shape

Material topLeftCornerMat3 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // create a simple

// material

topLeftCornerMat3.setColor(“Color”, ColorRGBA.Red); // set color of material to blue

topLeftCornerGeom3.setMaterial(topLeftCornerMat3); // set the cube’s material

topLeftCornerGeom3.setLocalTranslation(5, 5, 5);

rootNode.attachChild(topLeftCornerGeom);

rootNode.attachChild(topLeftCornerGeom2);

rootNode.attachChild(topLeftCornerGeom3);[/java]

I was expecting the and the red cubes to match but they don’t. here is a screenshot:

[java]

topLeftCornerGeom.setLocalTranslation(5, 5, 5);

topLeftCornerGeom.setLocalTranslation(0, 0, 0);

[/java]

What’s the point of this?

I think you misunderstand how it works. setLocalTranslation sets the local translation (position of the spatial relative to its parent). then in the next update loop, the worldTranslation (position in the world) of the spatial will be computed by combining local translations of the nodes from the root to this spatial.

So setting it twice in the same method makes no sense.

Also it does not behave like the move() method. move adds a translation, setLocalTranslation sets it.

Thanks for all the info.

I’m obviously using the wrong method, what I want is move.

@nehon

What’s the point of this?

The point is to simulate a more complicated code where there are two reasons for moving an object.

As I am not sure if just adding the value would be correct (maybe some matrix operation would make this incorrect?) I did it two times so it would do the proper operation two times.

Now I see that the correct way is to use move and add the two values.

Generally throughout all computer code everywhere “set” sets something irrespective of it’s previous condition…