detection only
int CheckHit( F_RECT *prcRect1, F_CIRCLE *pcrCircle2 )
{
int nResult = false;
float ar;
if ( ( pcrCircle2->x > prcRect1->fLeft - pcrCircle2->r ) &&
( pcrCircle2->x < prcRect1->fRight + pcrCircle2->r ) &&
( pcrCircle2->y > prcRect1->fTop - pcrCircle2->r ) &&
( pcrCircle2->y < prcRect1->fBottom + pcrCircle2->r ) )
{
nResult = true;
ar = pcrCircle2->r;
if ( pcrCircle2->x < prcRect1->fLeft ) {
if ( ( pcrCircle2->y < prcRect1->fTop ) )
{
if ( ( DistanceSqr( prcRect1->fLeft, prcRect1->fTop,
pcrCircle2->x, pcrCircle2->y ) >= ar * ar ) ) {
nResult = false;
}
}
else {
if ( ( pcrCircle2->y > prcRect1->fBottom ) )
{
if ( ( DistanceSqr( prcRect1->fLeft, prcRect1->fBottom,
pcrCircle2->x, pcrCircle2->y ) >= ar * ar ) ) {
nResult = false;
}
}
}
}
else {
if ( pcrCircle2->x > prcRect1->fRight ) {
if ( ( pcrCircle2->y < prcRect1->fTop ) )
{
if ( ( DistanceSqr( prcRect1->fRight, prcRect1->fTop,
pcrCircle2->x, pcrCircle2->y ) >= ar * ar ) ) {
nResult = false;
}
}
else {
if ( ( pcrCircle2->y > prcRect1->fBottom ) )
{
if ( ( DistanceSqr( prcRect1->fRight, prcRect1->fBottom,
pcrCircle2->x, pcrCircle2->y ) >= ar * ar ) ) {
nResult = false;
}
}
}
}
}
}
return nResult;
}
No comments:
Post a Comment