| View previous topic :: View next topic |
| Author |
Message |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Wed Sep 12, 2007 8:44 am Post subject: how to make a high speed collision test? |
|
|
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? |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Sep 12, 2007 9:58 am Post subject: |
|
|
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 _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Wed Sep 12, 2007 11:35 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Wed Sep 12, 2007 11:59 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Wed Sep 12, 2007 6:41 pm Post subject: |
|
|
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 _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
saulotmalo2
Joined: 10 Sep 2007 Posts: 43
|
Posted: Wed Sep 12, 2007 9:41 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Thu Sep 13, 2007 9:06 am Post subject: |
|
|
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 _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
|