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

Author Topic: [SOLVED] Are SFML shapes suitable for collision detection?  (Read 4046 times)

0 Members and 4 Guests are viewing this topic.

Kadoba

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Are SFML shapes suitable for collision detection?
« on: July 22, 2013, 07:30:12 pm »
Hello,

I want to use SFML shapes for collision detection to save me some work and for this purpose I won't be using them for rendering (except for maybe debugging). Since I don't know much about OpenGL or the underlying code I am just wondering if they are lightweight enough for this purpose.
« Last Edit: July 29, 2013, 04:57:05 pm by Kadoba »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Are SFML shapes suitable for collision detection?
« Reply #1 on: July 22, 2013, 07:33:33 pm »
Sure but if you don't need the rendering you could directly use the sf::Rect class (sf::IntRect or sf::FloatRect) and its intersects method.

Kadoba

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Are SFML shapes suitable for collision detection?
« Reply #2 on: July 22, 2013, 07:50:05 pm »
Oh yeah. Well I should have said I am thinking about non axis aligned stuff. So the rotation, transforms, and get-bounds functions of the sf::shapes would be super useful to have already done for me.

Actually I am probably worrying over nothing since the shapes wouldn't even have some of those functions if they weren't intended to be used for math.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10999
    • View Profile
    • development blog
    • Email
Re: Are SFML shapes suitable for collision detection?
« Reply #3 on: July 22, 2013, 08:14:19 pm »
Then you could derive your own class from sf::Transformable or maybe even better and use your own sf::Transform within your class.
It's never really a good idea to misuse classes for different purposes if you have the chance to change it. ;)
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: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Are SFML shapes suitable for collision detection?
« Reply #4 on: July 24, 2013, 02:59:24 pm »
I want to use SFML shapes for collision detection to save me some work and for this purpose I won't be using them for rendering
SFML shapes are not designed for collision detection. I wouldn't even try to workaround their limitations, they are simply the wrong approach here.

Actually I am probably worrying over nothing since the shapes wouldn't even have some of those functions if they weren't intended to be used for math.
Yes, they would. They only provide the bare minimum of math required for rendering.

Take a look at Boost.Geometry, which allows you to intersect arbitrary polygons.
« Last Edit: July 24, 2013, 03:01:25 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kadoba

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Are SFML shapes suitable for collision detection?
« Reply #5 on: July 29, 2013, 04:52:17 pm »
Sorry about the delayed response. I decided to take eXpl0it3r's approach and implement my own shapes with a sf:Transform and it's working out well. Thanks everyone for your input.