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

Author Topic: Intersecting rectangles, help.  (Read 1664 times)

0 Members and 2 Guests are viewing this topic.

Haikarainen

  • Guest
Intersecting rectangles, help.
« on: April 23, 2011, 10:16:47 pm »
To begin with, sry if ive been posting a lot of threads here in a very short period of time, my head is just a mess atm :P cant think. I also have a little project coming up in a few days (tonight/tomorrow if youre lucky!) that will eliminate all dirty megaupload links on these forums ;)

To the point:
I'm working on a collision detection system, that checks a characters collisionrectangle to a pixel perfect image tile .

So say we have:
sf::Rect Body.CollisionBox;
sf::Image Tile; // using position and size as "rect"

Ive came so far to check IF theyre intersecting, but now i need a third sf::Rect from WHERE the 2 other "rects" are intersecting.

I need the third rect to begin checking pixels(have no problem with how to do that), so i need the intersecting rect -> rect on the imagepixels.

Please help me, as i wrote before my head  have been  a mess the past 2 days, been working on this function tooo long now :P

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Intersecting rectangles, help.
« Reply #1 on: April 23, 2011, 10:32:30 pm »
If you use SFML 2, the member function sf::Rect::Intersects() can help you finding the intersection.

Otherwise, this shouldn't be too hard to compute. Draw it on a paper and you will see which coordinates you have to take ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Intersecting rectangles, help.
« Reply #2 on: April 23, 2011, 10:37:53 pm »
sf::Rect::Intersect is in SFML 1.6 too ;)
Laurent Gomila - SFML developer