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

Author Topic: Intersecting Rectangles Confusion  (Read 1047 times)

0 Members and 1 Guest are viewing this topic.

Cryonic

  • Newbie
  • *
  • Posts: 16
    • View Profile
Intersecting Rectangles Confusion
« on: October 17, 2015, 06:58:04 pm »
I have a bunch of side by side rectangles that make up a matrix that will be colored if they intersect with a specified rectangle.

The problem is that when I use the intersect function, I do not know how to specify that I just want the intersection between the matrix rectangles and just the specified rectangle shape bounds, not the whole bounding box (it has been rotated).

So, basically the black squares that touch the white rectangle are the only ones that should be colored yellow:

if (Tiles[r][c].getGlobalBounds().intersects(Environment_1_Barrier.getGlobalBounds()))
{
   Tiles[r][c].setFillColor(sf::Color::Yellow);
}
« Last Edit: October 17, 2015, 07:05:55 pm by Cryonic »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Intersecting Rectangles Confusion
« Reply #1 on: October 17, 2015, 09:38:23 pm »
sf::Rect:intersects() functions is for axis aligned rectangles only, i.e. you can't use it to check against a rotated rectangle. For that you'll have to use other collision detections that are not part of SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything