float  Vector2IsLeft(FVector v, FVector vStart, FVector vEnd)
{
    return (vStart.X - v.X)*(vEnd.Y - v.Y) - (vEnd.X - v.X)*(vStart.Y - v.Y);
}

bool CheckCollision1(FVector vStart1, FVector vEnd1, FVector vStart2, FVector vEnd2)
{
    static const float YD_EPS_REAL32 = 0.00000001f;
    float leftS, leftE;
    leftS = Vector2IsLeft(vStart1, vStart2, vEnd2);
    leftE = Vector2IsLeft(vEnd1, vStart2, vEnd2);
    if (leftS * leftE > YD_EPS_REAL32)
    {
        return false;       // vStart1, vEnd1在另一条直线的同侧
    }

    leftS = Vector2IsLeft(vStart2, vStart1, vEnd1);
    leftE = Vector2IsLeft(vEnd2, vStart1, vEnd1);
    if (leftS * leftE > YD_EPS_REAL32)
    {
        return false;       // vStart2, vEnd2在另一条直线的同侧
    }

    return true;
}

 

posted on 2020-04-16 17:25  jackdesk  阅读(323)  评论(0编辑  收藏  举报