Esempio n. 1
0
    //returns a most most extreme on the Minkowski Difference along direction
    //created by this shape and other
    Vector3 MinkowskiDiffSupport(GJKCollider other, Vector3 direction)
    {
        Vector3 my_support    = support.Support(direction);
        Vector3 other_support = other.support.Support(-direction);
        Vector3 result        = my_support - other_support;

        return(result);
    }
    public override void OnInspectorGUI()
    {
        GJKCollider gjkCollider = (GJKCollider)target;

        if (DrawDefaultInspector())
        {
            gjkCollider.EditorStart();
        }
    }
Esempio n. 3
0
    //returns true if this chape is colliding with other
    public bool CollidesWithOther(GJKCollider other)
    {
        Vector3 newest_point;

        //get point in arbitrary direction
        Vector3 direction = Vector3.right;
        Vector3 C         = MinkowskiDiffSupport(other, direction);

        //if that point is in the opposite direction from the origin,
        //no collision
        if (Vector3.Dot(C, direction) < 0)
        {
            return(false);
        }

        //get point in other direction
        direction = -C;
        Vector3 B = MinkowskiDiffSupport(other, direction);

        //if that point is in the opposite direction from the origin,
        //no collision
        if (Vector3.Dot(B, direction) < 0)
        {
            return(false);
        }

        //set next direction to check as perpendicular to that line
        direction = Cross_ABA(C - B, -B);
        List <Vector3> simplex = new List <Vector3>
        {
            B, C
        };

        for (int i = 0; i < MAX_ITERATIONS; i++)
        {
            //get the support point in newest direction
            newest_point = MinkowskiDiffSupport(other, direction);

            //if that point is not closer to the origin,
            //there is no collision
            if (Vector3.Dot(newest_point, direction) < 0)
            {
                return(false);
            }

            //operate on the simplex,
            //return true if the simplex is a tetrahedron
            //that contains the origin
            if (DoSimplex(newest_point, ref simplex, ref direction))
            {
                return(true);
            }
        }

        //don't iterate too much to avoid slowdown
        return(false);
    }