Archived

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

ncsu121978

collision

Recommended Posts

What is the best way to go about pixel perfect collision detection......I know I would use the bounding box test first, and if they intersect.......then what do i do ? Do i just find what part intersects then loop through the pixels in those portions of the surfaces and see if any are in the same spot ? Would I use the getPixel() function for this (dont remember if that is exact name but you know what i mean) ? Or how else.......would using a for loop to loop through all the pixels in the intersection take too long or is it fast enough ? any suedo-cod e you can provide would be helpful..... "Now go away or I shall taunt you a second time" - Monty Python and the Holy Grail themGames Productions

Share this post


Link to post
Share on other sites
bumping it on the recents one time before i let it go......
If you know where I can get my hands on some code it would help alot......I don''t want it inside of a library like CDX or anything though as I am creating my own library.......
All of DirectDraw except collision at the pixel level is finished and all of DirectInput is finished


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
Here''s something for you to think about. If you really want pixel perfect c/d then you do need to compare sprites pixel by pixel as you draw them. I''ll try and explain a way to do this, it may not be fast, but here goes....

For each sprite, create a 1 bit version of it''s image, a black and white version, (simply trace all the pixels that are drawn and ignore those that are not) do this at design time.

Supposing you want to test between 32 different sprites. We set up a ''virtual screen'' in memory 640x480x32bits (4 bytes, 2 words, 1 dword, whatever).

Now we have to duplicate DirectDraw''s actions and blit our sprites onto this imaginary screen (which will have to be in software, with your own routines). Now heres the important bit...

Instead of doing a direct blit, we do a bitwise operation (OR) to get our sprites ''ID number'' into our virtual screen. (I hope you know some binary for this )

Sprite no. 1''s ID: 000000000000000000000001
Sprite no. 2''s ID: 000000000000000000000010
etc etc

By OR''ing these together we get:
Virtual screen has:000000000000000000000011

One all the sprites are copied into the screen space, one pass through the screen data will tell us which sprites have collided.

I hope you can follow that. If you need some more clarification, just say so.

You see why everything was so much simpler when it was all black and white....

Cheers

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett

Share this post


Link to post
Share on other sites