Collision detection for irregular shaped objects.
Dar Scott
dsc at swcp.com
Fri Apr 12 00:41:01 EDT 2002
On Thursday, April 11, 2002, at 05:32 AM, malte brill wrote:
> I want to check if objects on my stack collide.
> I got two PNG Images including Alpha Channels on my stack, the
> second one
> placed in a distance of 100 pixels or so under the first one.
Consider this. It might be a little naive and slow, so if this is
for a game you may need to come up with a way to speed this up.
This is for images only.
******
If they don't overlap, they don't collide.
Otherwise, calculate the overlap rectangle.
For pixels in the overlap check to see if the opacity of the pixel
in one image and that of the corresponding pixel in the other image
indicate collision. (Say, add to over 100% opacity.) If all
pixels are checked and none collide, then the images do not collide.
If any pixel collides, quit the check; the images collide.
********
Use the alphaData property of the images to get the alphaData
info. It is a string of bytes, so you have to do some math to pull
out the right byte for each pixel.
Alternately, if the images are of circles or perhaps some other
simple regular shape, then a simple model of the shape can be used
to check collision.
Dar Scott
More information about the use-livecode
mailing list