Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is there a way to force SFML to do exact selection?  (Read 1274 times)

0 Members and 1 Guest are viewing this topic.

lmorsino

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Is there a way to force SFML to do exact selection?
« 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: Is there a way to force SFML to do exact selection?
« Reply #1 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". :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Is there a way to force SFML to do exact selection?
« Reply #2 on: November 10, 2014, 07:55:52 pm »
Or use a library. I can recommend Boost.Geometry.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

lmorsino

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Is there a way to force SFML to do exact selection?
« Reply #3 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