getLocalTranslation() returns actuall translation vector

I’m a noob in Java, but I’m studying it in parallel with JMonkey.



Recently I’ve realised that I have some serious flaw in my coding rooting. Please, take a look at this simple example:

[Java]

System.out.println(“Left Local:”+engineL.getLocalTranslation());

Vector3f engPoint = engineL.getLocalTranslation();

engPoint = ship.localToWorld(engPoint, engPoint);

[/Java]

After first update, while body rotated, local translation will be different. It completely makes sense as engPoint is now refers to actual translation vector of engineL. So any operations on it will actually change original vector.



But I’m not sure how I can avoid such situation in future. What is your usual approach on this?

What is it you’re trying to achieve exactly?

Well, in this particular case I should have done it in a different way, like this:

Vector3f engPoint = ship.localToWorld(engineL.getLocalTranslation(), engPoint);

so that original translation vector won’t be affected. Didn’t paid enough attention to referencing.

just clone the vector

that’s what she said

@wezrule said:
that's what she said

That's easy with yours, it's already normalized to unit length.
@Sploreg said:
That's easy with yours, it's already normalized to unit length.


And that's where she laughed.