예제 #1
0
bool GJKCollisionDetector::detect(const Convex& convex1, const Transform2& transform1, const Convex& convex2,
                                  const Transform2& transform2, Penetration& penetration)
{
    if (convex1.getType() == ConvexType::CIRCLE && convex2.getType() == ConvexType::CIRCLE)
    {
        return CircleDetector::detect(
                reinterpret_cast<const Circle&>(convex1),
                transform1,
                reinterpret_cast<const Circle&>(convex2),
                transform2,
                penetration);
    }

    vector<fvec2> simplex;
    MinkowskiSum minkowskiSum(convex1, transform1, convex2, transform2);
    fvec2 direction = calcInitialDirection(convex1, transform1, convex2, transform2);

    if (detect(minkowskiSum, simplex, direction))
    {
        penetrationSolver->findPenetration(simplex, minkowskiSum, penetration);
        return true;
    }

    return false;
}
예제 #2
0
bool GJKCollisionDetector::detect(
        const Convex& convex1,
        const Transform2& transform1,
        const Convex& convex2,
        const Transform2& transform2)
{
    if (convex1.getType() == ConvexType::CIRCLE && convex2.getType() == ConvexType::CIRCLE)
    {
        return CircleDetector::detect(
                reinterpret_cast<const Circle&>(convex1),
                transform1,
                reinterpret_cast<const Circle&>(convex2),
                transform2);
    }

    vector<fvec2> simplex;
    MinkowskiSum minkowskiSum(convex1, transform1, convex2, transform2);
    fvec2 direction = calcInitialDirection(convex1, transform1, convex2, transform2);

    return detect(minkowskiSum, simplex, direction);
}