www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/07/00:33:42

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Collison detection fo Action game
Date: Thu, 6 Feb 1997 20:22:02 +0000
Organization: None
Distribution: world
Message-ID: <pdJZwBAq1j+yEwUI@talula.demon.co.uk>
References: <855142026 DOT 12716 AT dejanews DOT com>
<vgpI$hAr7O+yEwGt AT talula DOT demon DOT co DOT uk> <1GKh7AAUla+yEwGM AT flag DOT demon DOT co DOT uk>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 42
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019