Exemplo n.º 1
0
bool Map::isMultiRectCollision( SDL_Rect *A ){
    bool isCollision = false;
    
    for( auto it = walls.begin(); it != walls.end(); ++it ){
        if( isRectCollision( A, *it ) ){
            isCollision = true;
            break;
        }
    }
    
    for( auto it = foods.begin(); it != foods.end(); ++it ){
        if( isRectCollision( A, *it ) ){
            delete (*it);
            foods.erase( it );
            break;
        }
    }
    
    return isCollision;
}
///@brief 判断线段与线段是否相交
///
///
///@param[in] aa,bb--线段1两个端点, cc,dd--线段1两个端点
///@pre 
///@return true---在线段上, false---不在线段上
///@retval 
///@post
///@author DionysosLai,[email protected]等  
///@version 1.0  
///@data 2014-04-10 
bool LineMenu::segmentLineIsIntersect(CCPoint aa, CCPoint bb, CCPoint cc, CCPoint dd)  
{  
	/// 以两条线段形成的矩形不重合,说明两条线段必然不相交
	if (!isRectCollision(aa, bb, cc, dd))
	{
		return false;
	}
	
	/// 必须二者互相跨立 注意"="的情况。
	if (0 < determinant(aa.x-cc.x, aa.y-cc.y, dd.x-cc.x, dd.y-cc.y) * 
		determinant(dd.x-cc.x, dd.y-cc.y, bb.x-cc.x, bb.y-cc.y) &&
		0 < determinant(cc.x-aa.x, cc.y-aa.y, bb.x-aa.x, bb.y-aa.y) * 
		determinant(bb.x-aa.x, bb.y-aa.y, dd.x-aa.x, dd.y-aa.y))
	{
		return true;
	}
	return false;  
}  
///@brief 判断点是否在多边形(包括点在边上)