Jump to content
  • Advertisement
Sign in to follow this  
CaptCanada

SDL Collision Library

This topic is 3761 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

Hi everyone, I am just wondering if there is a nice SDL collision library out there? I am coding a lunar lander game and need some help checking for collions with the mountains in the game. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I was mistaken, there are a few [smile]. One of them is this one. From what I have seen on google, it is the best for SDL. You can also look at some concepts that are used with Lesson 6 of Cone3D's, but that Bitmask Collision Library should be what you need.

- Drew

Share this post


Link to post
Share on other sites
There is SDL_Collide.h which provides a couple of functions to have bitmask collision detection. I would recommend using a different method of checking collisions though as checking through overlapping pixels can slow down the game. Try bounding box collision or bounding circle collision test. If you don't need that much precision with what you want to collide, those are very fast.

Share this post


Link to post
Share on other sites
Genjix's routines should be fast enough even on arcade shooters. Looking at his code, it does the pixel perfect collision with overlapping pixels. In my experience, even in sofware, it should be fast enough.

Share this post


Link to post
Share on other sites
It should also be mentioned that the code linked to above assumes each sprite has it's own surface as opposed to belonging o a sprite sheet (if I read it correctly). It shouldn't be difficult to modify to accept 2 extra SDL_Rect structures though. On another note, using the bounding box collision detection to find a collision and THEN using the pixel perfect collision to refine that collision if it occurs would probably be the more efficient way to get pixel perfect collision in your game as in most cases more than half of the checks do not return a collision. That way you only check the slower pixel perfect routines if you need to.

@Genjix
nice job :) I am sure that will help a lot of people.

Share this post


Link to post
Share on other sites
My spaceship is a seperate surface as well as the mountians. I was thinking of a bounding box collision test,but since the rect a mountian would be huge compared to the ship, it would result in a false collision detection right?

I am very newbie when it comes to collision detection beyond bounding boxes, so anything that allows me to simply test for collisions between two objects is great. Kinda like a "collision detection library for dummies" is ideal.

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by evillive2
On another note, using the bounding box collision detection to find a collision and THEN using the pixel perfect collision to refine that collision if it occurs would probably be the more efficient way to get pixel perfect collision in your game as in most cases more than half of the checks do not return a collision. That way you only check the slower pixel perfect routines if you need to.

pixel perfect test already does that (how can i compute overlaps, if it doesn't exist?) ;)

Quote:
Original post by evillive2
@Genjix
nice job :) I am sure that will help a lot of people.

thanks. I'm not sure why SDL doesn't have something similar (what with all the unnecessary libs like reading audio cds).

I might extend it, if anyone finds it useful(i.e a circle collision test and add skips - instead of reading every pixel, read every nth pixel using extra param
int skip = 0
).

Share this post


Link to post
Share on other sites
Quote:
Original post by Genjix
...
I wrote up a bounding circle collision test function a while ago if you're too lazy to write one yourself [smile].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!