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

Author Topic: Easy method to check if a point is inside of a Rectangle shape  (Read 1790 times)

0 Members and 1 Guest are viewing this topic.

ankitpaudel20

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Easy method to check if a point is inside of a Rectangle shape
« on: February 08, 2020, 09:18:36 am »
i want to check for collision detection of rectangle but didn't find a way to check if the point is inside the rectangle so any ideas?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10841
    • View Profile
    • development blog
    • Email
Re: Easy method to check if a point is inside of a Rectangle shape
« Reply #1 on: February 08, 2020, 10:21:39 am »
sf::Rect<T>::contains()

Also you probably can find a few hundred responses by googling "rectangle point collision detection sfml" ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ankitpaudel20

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Easy method to check if a point is inside of a Rectangle shape
« Reply #2 on: February 08, 2020, 11:59:54 am »
Isn't that for rectangle whose sides are aligned with axes?

I meant to ask if it had rotations and other transformations applied ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Easy method to check if a point is inside of a Rectangle shape
« Reply #3 on: February 08, 2020, 05:52:58 pm »
Then you can apply the inverse transform of the rectangle to the point, so you're back into a coordinate system where the rectangle is aligned with axes.

Or you can use one of the algorithms which works with any convex shape (Google them).
Laurent Gomila - SFML developer