예제 #1
0
        public static List <PolygonCollider> CheckCollisionsAt(Vector2 position, Polygon subject)
        {
            Polygon fake = PolygonManager.Create2D(subject);

            fake.Center = position;
            return(CheckCollisions(fake));
        }
예제 #2
0
        protected bool CheckSolution(Polygon obstacle, Vector2 offset)
        {
            Polygon fakeSolution = PolygonManager.Create2D(this);

            fakeSolution.Translate(offset);

            List <Vector2> p_remaining = fakeSolution.VerticesInside(obstacle);
            List <Vector2> o_remaining = obstacle.VerticesInside(fakeSolution);

            if (p_remaining.Count > 1 || o_remaining.Count > 1)
            {
                return(false);
            }

            if (p_remaining.Count > 0 && !obstacle.ContainsInEdge(p_remaining[0]) || (o_remaining.Count > 0 && !fakeSolution.ContainsInEdge(o_remaining[0])))
            {
                return(false);
            }

            List <Vector2> intersections = obstacle.IntersectionPoints(fakeSolution, 3);

            Debug.Log("Remaining.Count = " + p_remaining.Count + " | Obstacle.IntersectionPoints " + intersections.Count);

            if (intersections.Count > 2)
            {
                return(false);
            }

            if (p_remaining.Count == 0)
            {
                return(intersections.Count < 2 || EqualVertices(intersections[0], intersections[1], 2) || Vector2.Distance(intersections[0], intersections[1]) <= EPSILON);
            }

            if (intersections.Count == 2)
            {
                if (EqualVertices(intersections[0], intersections[1], 3))
                {
                    return(true);
                }

                Vector2 vertex = p_remaining[0];
                return(Vector2.Distance(vertex, intersections[0]) <= EPSILON && Vector2.Distance(vertex, intersections[1]) <= EPSILON);
            }

            if (p_remaining.Count == 1)
            {
                float remainingDistance = Vector2.Distance(p_remaining[0], obstacle.ClosestPerpendicularPointTo(p_remaining[0]));
                return(remainingDistance <= EPSILON || obstacle.ContainsInEdge(p_remaining[0]));
            }

            return(true);
        }