Beispiel #1
0
        static bool PolygonCollision(PolygonForCollision polygonA, PolygonForCollision polygonB)
        {
            bool Intersect = true;

            int edgeCountA = polygonA.Edges.Count;
            int edgeCountB = polygonB.Edges.Count;
            VectorForCollision edge;

            for (int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++)
            {
                if (edgeIndex < edgeCountA)
                {
                    edge = polygonA.Edges[edgeIndex];
                }
                else
                {
                    edge = polygonB.Edges[edgeIndex - edgeCountA];
                }

                VectorForCollision axis = new VectorForCollision(-edge.Y, edge.X);
                axis.Normalize();

                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)
                {
                    Intersect = false;
                }
            }

            return(Intersect);
        }
Beispiel #2
0
 public void Offset(float x, float y)
 {
     for (int i = 0; i < points.Count; i++)
     {
         VectorForCollision p = points[i];
         points[i] = new VectorForCollision(p.X + x, p.Y + y);
     }
 }
Beispiel #3
0
        static void ProjectPolygon(VectorForCollision axis, PolygonForCollision polygon, ref float min, ref float max)
        {
            float d = axis.DotProduct(polygon.Points[0]);

            min = d;
            max = d;
            for (int i = 0; i < polygon.Points.Count; i++)
            {
                d = polygon.Points[i].DotProduct(axis);
                if (d < min)
                {
                    min = d;
                }
                else
                {
                    if (d > max)
                    {
                        max = d;
                    }
                }
            }
        }
Beispiel #4
0
 public bool Equals(VectorForCollision v)
 {
     return(X == v.X && Y == v.Y);
 }
Beispiel #5
0
        public override bool Equals(object obj)
        {
            VectorForCollision v = (VectorForCollision)obj;

            return(X == v.X && Y == v.Y);
        }
Beispiel #6
0
 public float DistanceTo(VectorForCollision vector)
 {
     return((float)Math.Sqrt(Math.Pow(vector.X - this.X, 2) + Math.Pow(vector.Y - this.Y, 2)));
 }
Beispiel #7
0
 public float DotProduct(VectorForCollision vector)
 {
     return(this.X * vector.X + this.Y * vector.Y);
 }
Beispiel #8
0
 static public VectorForCollision FromPoint(Point p) => VectorForCollision.FromPoint(p.X, p.Y);
Beispiel #9
0
 public void Offset(VectorForCollision v)
 {
     Offset(v.X, v.Y);
 }