Collision detection: a comparison.

Dar Scott dsc at
Sun Sep 29 13:26:00 EDT 2002

On Monday, January 18, 2038, at 08:14 PM, malte brill wrote:

> And checking
> the masked data is much too slow.

At most you need only check the pixels that overlap.  If the 
rectangles of two images do not overlap, there is no collision.  If 
they do, check only the overlapping part.  Perhaps a collision 
occurs when the product of the overlaping alphas are greater than 
some threshold.  If your physics prevents two objects being at the 
same place, you might not have a lot of overlap.  Keep your images 
tight; don't leave a lot of transparent space about a picture.

Depending on your physics, you might need only check the edges of 
the picture.

You might be able to check even less pixels with certain 
assumptions, such as the shape being convex.

If pixel by pixel checking is too slow, you might roughly model 
each object with a small list of rectangles in a custom property.  
An overlap occurs if any rectangle from one's list overlaps one 
from the other.  This is n**2, so...

How about limiting this to a few rectangles and then use the pixel 
method for within that?  Or, related, breaking up larger images 
into smaller.

Just a handful of wild ideas.

I'd try checking the alphas and seeing how slow that really is.

Dar Scott

More information about the Use-livecode mailing list