SFML community forums
Help => General => Topic started by: lmorsino on November 10, 2014, 07:22:57 pm
-
I want to be able to select a sf::Shape by clicking with the mouse. I realize I can call sf::Shape::getGlobalBounds to get the bounding rectangle and use sf::FloatRect::contains to test against a point. But what if I need to know if the user clicked on the Shape itself, not just inside its bounding rectangle? Is there a way to do this in SFML?
-
SFML doesn't provide such a facility, but it certainly is possible to do so with some math. Try Google with keywords such as "point in polygon". :)
-
Or use a library. I can recommend Boost.Geometry.
-
Thanks for the suggestions. I found this solution that is quite simple:
http://stackoverflow.com/questions/11716268/point-in-polygon-algorithm