Alpha channel friendly collider
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2018 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user