SFML community forums
Help => General => Topic started by: N1ghtly on January 25, 2012, 09:34:57 pm
-
Hey all, I recently updated to the latest snapshot and converted my code to use the new GetGlobalBounds method. However: it broke my collision code. I narrowed the problem down to arithmetic precision. I set the sprite for example at pos (20, 252).
When I subsequently call GetGlobalBounds, it becomes (20, 252.000004).
So when I call rect1.intersects(rect2) it will claim they intersect (by a suuuuuper small margin) while they shouldn't.
Anyone else has this error?
-
When I subsequently call GetGlobalBounds, it becomes (20, 252.000004).
Can you try to find exactly which operation adds this small error on the result?
-
That would be sprite.Move :)
-
And before, with Sprite::GetSize(), the result was always correct?
-
Yes.
-
This is the kind of problems that happen with floats. You should rather add a small epsilon to your collision tests rather than relying on SFML to provide exact values anyway.
-
What do you mean by a small epsilon?
And I just don't understand why this suddenly stopped working ^^
-
What do you mean by a small epsilon?
Instead of testing a < b (for example), test a < b +/- e, with "e" a very small value which represents the error margin.
And I just don't understand why this suddenly stopped working
The implementation has changed, things are computed differently.