Mail Archives: djgpp/1997/02/07/00:33:42
Moo-Juice writes:
>>If true pixel-perfect testing is needed, one of the fastest approaches
>>is to pregenerate a monochrome mask for each sprite, containing one bits
>>for the pixels that are set and zeros for the ones that aren't. To test
[snip]
>
>Any chance you post some example code for this Shawn?
I can't seem to find the routine I had for doing this: it was a long
time ago, and I think in 68000 asm in any case :-) Sorry...
It's a tricky thing to implement in a truly generic way, but becomes a
lot simpler if you can restrict the width of the sprites. For example,
if you make all your sprites be 64 pixels wide, the mask will fit into
two 32 bit integers. The code would then look something like:
Given two objects a and b, sort them so x is the leftmost.
for i = max(atop, btop) to min(abottom, bbottom) do
aline = line[i - atop] of sprite a
bline = line[i - btop] of sprite b
load aline (64 bits) into %eax : %edx
shift left by bxpos-axpos (using shld)
or %eax with the first 32 bits of bline
if non-zero, they collided
or %edx with the next 32 bits of bline
if non-zero, they collided
end for
Sorry for the pseudocode, but I don't have time to implement this
properly just now. Hope that helps, and that I haven't made any silly
mistakes :-)
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
*/
- Raw text -