Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

theSeby

[SDL] Collision

This topic is 5524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m looking for a pixel-exact collision detection between 2 sprites (SDL_Surface) in SDL. I''ve got a box-box collision detection yet and i find the intersection rectangle. Thanks ! ------------------------ - Seby - www.dfhi-bomber.fr.st

Share this post


Link to post
Share on other sites
Advertisement
Loop through that intersection rectangle (2 nested loops), look up the appropriate pixel in each sprite (a multiply and an offset), compare them (if both are ''solid'', you have a collision). It''s easy when you break it down.

Share this post


Link to post
Share on other sites
Why does that seem extremely slow? Looping through every pixel in each sprite...

Maybe you should have a bounding box and when the boxes intersect, you should only do that pixel-pixel collision detection in that resulting rectangle. Hmmm, I'm stupid anyway.

[edited by - SuperRoy on August 7, 2003 7:08:04 AM]

Share this post


Link to post
Share on other sites
I''ve found there are extreamly few times when pixel perfect collision is 100% necessary especially in games.

If rectangles aren''t cutting it try using circles instead, or maybe capsules.

Just a thought.

Michael

Share this post


Link to post
Share on other sites
if your bounding box collision is giving you "fake" collisions. then make the bounding box for that sprite smaller, only containing the main part (ie body or fluesilage) so the arms and wings may not detect damage, but neither will the huge empty space above them.

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
Or, allow a sprite to use more than one bounding rectangle.

If you''re really going for gold (though possibly slowness as well) you could write code for a ''collection'' of arbitrary collision shapes - so you can use bounding rectangles, circles, and polygons in the same sprite.

Of course, it''s almost totally unnecessary.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
SuperRoy, there''s no reason why it has to be slow. Think about software 3D renderers that perform calculations for every single pixel on the screen. That is fast enough to get many frames per second, so performing a similar exercise on a tiny fraction of that many pixels when there has been a collision between the bounding boxes will be trivial.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try this:
http://www.ifm.liu.se/~ulfek/projects/2d_Collision_Detection.html
Its a fast pixel-perfect collision detection library for SDL

- Wyzfen

Share this post


Link to post
Share on other sites
Thank you very much for your feed back !
I think I can do a box-box collision detection, with box that are a little bit smaller than the entire sprite.

Please check the demo, that's with a box-box col. det., and the box are the same size of the picture (I have to reduce the box). Do you think the box collision with smaller box will be enough ?

my demo

------------------------
- Seby -
www.dfhi-bomber.fr.st

[edited by - theSeby on August 8, 2003 3:32:35 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!