Public Group

#### Archived

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

# collision detection

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone know some good code for pixel to pixel collisions. I have used straight tile based and bounding boxes and got those up and running, but I am having trouble with finding a good example of pixel to pixel. I have all tiles that are 64 wide and 64 long, and my basic object struct is just float x; float y; char tile; bool active; If anyone could point me to some good examples or has some suggestions that would be great.

##### Share on other sites
I found this very helpful. It may take time to digest, but it''s pretty cool - he even includes a full working source.

##### Share on other sites

(Assuming you''re coding on an x86)

The ideal solution could be to use two bitmasks, and do some shuffles and ands, I guess.

That is, create bitmasks for the two bitmaps, such that whenever the pixel is non-transparent (or otherwise a "hit"), you put a ''1'' in there, otherwise a ''0''. Pseudo-code (actually, pure C++):

int BITMASK [(64 * 64) >> 5];

for (int yloop = 0; yloop < 64; yloop++) {
for (int xloop = 0; xloop < 64; xloop++) {
if (TILESARRAY [tile->tile][xloop][yloop] != ALPHA_COLOR) BITMASK [(xloop + (yloop << 6)) >> 5] |= (1 << xloop & 31);

}
}

Then, you first do the trivial intersection calculations. After you''ve done that (and they still look like they could intersect) you call the per-pixel routine. First, you calculate the intersection.

Then, you look up the values (with a 2-dimensional for loop) from the bitmasks, using (x >> 5) as the indexes and shuffling the bit mask values (remember, they''re dword, not bit aligned) right as many times as needed (value >> (x & 31). Then you and them.

Blargh, it''s 8:49 on a monday morning and I''m barely half awake. Maybe I should just shut up.

.bas

[sPiKie] mmorpg isnt hard in vb

##### Share on other sites
Thanks guys, any other suggestions?

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632942
• Total Posts
3009344
• ### Who's Online (See full list)

There are no registered users currently online

×