|
|
发表于 2006-2-17 16:07:00
|
显示全部楼层
Re: 请教个碰撞检测问题!
2D自己想想就出来了了嘛,这个是两个矩形碰撞检测
至于点是否在矩形不用说了吧
struct MYRECT
{
long x; //X坐标
long y; //Y坐标
long width; //宽度
long height; //高度
}
bool Collision(MYRECT &r1, MYRECT &r2)
{
long compareWidth = 0, compareHeight = 0;
bool bool1, bool2;
bool bImpact = false;
if (r1.x > r2.x)
compareWidth = r2.width;
else
compareWidth = r1.width;
if (r1.y > r2.y)
compareHeight = r2.height;
else
compareHeight = r1.height;
bool1 = abs(r1.x - r2.x) <= compareWidth;
bool2 = abs(r1.y - r2.y) <= compareHeight;
if (bool1 && bool2)
bImpact = true;
return bImpact;
} |
|