public bool PolygonCollision(PolygonColliderObject collider)
        {
            ToTransform();
            collider.ToTransform();
            PolygonT polygonA = polygonT;
            PolygonT polygonB = collider.polygonT;

            var posA = polygonA.GetPosition() - polygonA.GetOrigin();
            var posB = polygonB.GetPosition() - polygonB.GetOrigin();

            //Debug.DrawPolygon(polygonA);
            //Debug.DrawPolygon(polygonB);

            int     edgeCountA = polygonA.GetEdges().Length;
            int     edgeCountB = polygonB.GetEdges().Length;
            Vector2 edge;

            for (int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++)
            {
                if (edgeIndex < edgeCountA)
                {
                    edge = polygonA.GetEdges()[edgeIndex];
                }
                else
                {
                    edge = polygonB.GetEdges()[edgeIndex - edgeCountA];
                }
                Vector2 axis = new Vector2(-edge.Y, edge.X);
                axis = Vector2.Normalize(axis);
                float minA = 0; float minB = 0; float maxA = 0; float maxB = 0;
                ProjectPolygon(axis, polygonA, ref minA, ref maxA);
                ProjectPolygon(axis, polygonB, ref minB, ref maxB);
                if (IntervalDistance(minA, maxA, minB, maxB) > 0)
                {
                    return(false);
                }
            }
            OnCollide(collider);
            collider.OnCollide(this);
            return(true);
        }
Esempio n. 2
0
        public void RemoveCollider(PolygonColliderObject collider, int layer)
        {
            int index = collidersLayered[layer].FindIndex(x => x == collider);

            RemoveCollider(index, layer);
        }
Esempio n. 3
0
 public int AddCollider(PolygonColliderObject collider, int layer)
 {
     collidersLayered[layer].Add(collider);
     return(collidersLayered[layer].Count - 1);
 }