SFML community forums

Help => General => Topic started by: lmorsino on November 10, 2014, 07:22:57 pm

Title: Is there a way to force SFML to do exact selection?
Post 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?
Title: Re: Is there a way to force SFML to do exact selection?
Post by: eXpl0it3r on November 10, 2014, 07:48:00 pm
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". :)
Title: Re: Is there a way to force SFML to do exact selection?
Post by: Nexus on November 10, 2014, 07:55:52 pm
Or use a library. I can recommend Boost.Geometry.
Title: Re: Is there a way to force SFML to do exact selection?
Post by: lmorsino on November 10, 2014, 09:52:02 pm
Thanks for the suggestions. I found this solution that is quite simple:

http://stackoverflow.com/questions/11716268/point-in-polygon-algorithm