From 6974efece77c1abe99172a4ef1c4b06b3ccc04ce Mon Sep 17 00:00:00 2001 From: avolkov Date: Mon, 28 Nov 2005 05:37:17 +0000 Subject: [PATCH] Alpha channel friendly collider git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2018 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c index d404768a9..b61b7cce1 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_funcs.c @@ -189,7 +189,8 @@ _image_intersect (PIMAGE_BOX box1, PIMAGE_BOX box2, PRECT rect) SDL_Surface *img1, *img2; int img1w, img1xpos, img1ypos, img2w, img2xpos, img2ypos; int x,y; - Uint32 img1colourkey, img2colourkey; + Uint32 img1key, img2key; + Uint32 img1mask, img2mask; GetPixelFn getpixel1, getpixel2; img1 = (SDL_Surface *)box1->FramePtr->image->NormalImg; @@ -201,19 +202,43 @@ _image_intersect (PIMAGE_BOX box1, PIMAGE_BOX box2, PRECT rect) img1w = img1->w; img1xpos = box1->Box.corner.x; img1ypos = box1->Box.corner.y; - img1colourkey = img1->format->colorkey; + if (img1->format->Amask) + { // use alpha transparency info + img1mask = img1->format->Amask; + // consider any not fully transparent pixel collidable + img1key = 0; + } + else + { // colorkey transparency + img1mask = ~img1->format->Amask; + img1key = img1->format->colorkey & img1mask; + } img2w = img2->w; img2xpos = box2->Box.corner.x; img2ypos = box2->Box.corner.y; - img2colourkey = img2->format->colorkey; + if (img2->format->Amask) + { // use alpha transparency info + img2mask = img2->format->Amask; + // consider any not fully transparent pixel collidable + img2key = 0; + } + else + { // colorkey transparency + img2mask = ~img2->format->Amask; + img2key = img2->format->colorkey & img2mask; + } for (y = rect->corner.y; y < rect->corner.y + rect->extent.height; ++y) { for (x = rect->corner.x; x < rect->corner.x + rect->extent.width; ++x) { - if ((getpixel1(img1, x - img1xpos, y - img1ypos) != img1colourkey) && - (getpixel2(img2, x - img2xpos, y - img2ypos) != img2colourkey)) + Uint32 p1 = getpixel1(img1, x - img1xpos, y - img1ypos) + & img1mask; + Uint32 p2 = getpixel2(img2, x - img2xpos, y - img2ypos) + & img2mask; + + if ((p1 != img1key) && (p2 != img2key)) { return TRUE; }