setLocalTranslation() or getLocalTranslation().set()

I read on the below guide not to use setLocal… and rather getLocal…set(x, y, z).



"Make sure you use thing.getLocalTranslation().set() to move the thing to a position, thing.getLocalScale().set() to change its size, and thing.getLocalRotation().set() to turn or tilt it. Not getWorldTranslation().set() and neither setLocalTranslation()."



http://jmonkeyengine.com/wiki/doku.php?id=zathrasbeginnersfaq#how_can_the_player_turn_and_look_at_something



What are the differences between the two, given I dont create a new Vector object, i.e. setLocalTranslation(x, y, z) rather than setLocalTranslation(new Vec…

they r the same if u do it the right way.



getlocalranslation.set() first retrieve the object's current localtranslation then set it.

but setlocaltranslation sets it directly which might cause some problems if u r trying to move the object.



what u can do is create a new vector3f which calculate the new position the object needs to be at in the current frame then call setlocaltranslation.



normally if u wanna move something, just calculate the change then do getlicaltranslation.addlocal(change); :wink:

neakor said:

getlocalranslation.set() first retrieve the object's current localtranslation then set it.
but setlocaltranslation sets it directly which might cause some problems if u r trying to move the object.


Surely it would be the other way around, since getLocalTranslation.set() is directly accessing the Vector3f object. So what you're trying to say is, one method doesnt require me to updateGeometricState()?

neakor said:

what u can do is create a new vector3f which calculate the new position the object needs to be at in the current frame then call setlocaltranslation.


I'm avoiding creating new Vectors in my main update loop to position objects, which is why I found getLocalTranslation.set() interesting.

The only reason I can think why that person would have said: "and neither setLocalTranslation()."
.. is because thats the only method (mentioned) which would take a Vector3f object parameter rather than individual floats (x, y, & z).

Currently you have to call updateGeometricState either way (SimpleGame and most others do that for you).



Consistently using getLocalTransation().set() is currently the preferred way for two reason:

  1. In most cases there is no need to create a new vector. (as you already pointed out)
  2. It can't happen to have two spatials using the same vector as their translation (which might sometimes get you in trouble). This is possible with setLocalTranslation, only.



    OTOH having mutable vectors (and quaternions, matrices etc.) like we have them currently does not allow for automatic change detection and thus does not allow automatic update (e.g. updateGeometricState only when needed).

Thanks for clearing that up.

So really theres no advantage to using one way or the other - as long as you dont do something stupid like pass reference to another spatials Vector by accident.



Thought as much.