SDL Collision Library

Started by
21 comments, last by somebodykulj 16 years ago
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
Better to try and fail than to fail by not trying.
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
Thanks!
Better to try and fail than to fail by not trying.
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.
Rob Loach [Website] [Projects] [Contact]
the above also does bounding box collisions.
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.
Hi.
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.

Evillive2
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
Better to try and fail than to fail by not trying.
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
).
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].
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement