how to make a high speed collision test?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

how to make a high speed collision test?

Post by saulotmalo2 »

hello i'm doing a game for psp using sdl. I want to know if there is a way to make a fast collision test between 2 sprites i need to not detect the colorkey... so i can't use squares.

I've been thinking in use a prod (i'm not sure of this word) first i will test if the two images get in touch if they did now i make a more intensive test for knowing if they are in a colorkey zone.

a better idea?
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Use the bounding squares first to get an idea whether they might be colliding. Then you're down to the hard yards of checking whether the box that's the intersection of the two squares has pixels from both sprites in it at the same location.

Jim
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

so as i was thinking... the only way of doing collision is with 2 collision test one using bounding box and one using pixel per pixel colorkey in the zone of collision.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Not the only one. Just the most appropriate to your cause (though you could still optimize with something like a smaller transparency map for each sprite and equal).
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

One way is to have a bitmask for each sprite. Basically have a bit set if there's sprite data, and clear if it's colourkey. Then you can just SHIFT and AND the two masks together to see if there's a collision.

<reminisce>Ah, the joys of Amiga programming :)

Jim
saulotmalo2
Posts: 43
Joined: Mon Sep 10, 2007 9:32 am

Post by saulotmalo2 »

but having a map for all the images would waste a lot of memory and also will need a preprocess i'll try the first one and if i need more speed here i'll improve it.

regards
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

It's only an extra 1 bit per pixel! But yep, try it the obvious way and if it's too slow, try something else :)

Jim
Post Reply