This should be an easy one - not easy for me
I am trying to compare two vector positions and they need to be EXACT to trigger a certain function:
Vector3f start = (0,0,0);
Vector3f updater = spatialThatMoves.setLocalTranslation();
How can I compare accurately if they are equal?
if(start .equals(updater) )
{
System.out.println(“DOES NOT WORK - not accurate enough”);
}
What do you mean “not accurate enough” in this case? start.equals(updater) will only return true if both vectors have exactly the same x,y,z basically. You can’t really get more accurate than that.
It even considers -0 and 0 to be different values.
Looking at my trace file:
start: (0.0, 0.0, 0.0)
updater: (0.0, 0.0, 0.0)
and still would not print out the System.out.println I have
Then you are actually complaining about it being TOO accurate. Println is rounding the values but they are slightly different.
If you want to more loosely compare two vectors the easiest way is to check for vector1.distanceSquared(vector2) being less than some really small value.
Interesting! Almost same concept as float. I compared them to epsilon value and that did it. Thanks!