예제 #1
0
        public static bool RectanglesCollide(Polygon A, Polygon B, out Vector2 MTD)
        {
            MTD = Vector2.Zero;
            Rectangle rA = A.GetBoundingRect();
            Rectangle rB = B.GetBoundingRect();
            Rectangle rC = Rectangle.Intersect(rA, rB);

            if (rC == Rectangle.Empty)
            {
                return(false);
            }
            if (rC.Width > rC.Height)
            {
                //DO MTD.Y
                MTD.Y = rC.Height;
                if (rC.Y - rA.Y < 0)
                {
                    MTD.Y *= -1;
                }
            }
            else
            {
                //DO MTD.X
                MTD.X = rC.Width;
                if (rC.X - rA.X < 0)
                {
                    MTD.X *= -1;
                }
            }
            return(true);
        }
예제 #2
0
        public static bool RectanglesCollide(Polygon A, Polygon B)
        {
            Rectangle rA = A.GetBoundingRect();
            Rectangle rB = B.GetBoundingRect();
            Rectangle rC = Rectangle.Intersect(rA, rB);

            return(rC != Rectangle.Empty);
        }