예제 #1
0
        /// <summary>
        /// A fairly fast but not totally accurate collision system for rect 4 structures
        /// Simply checks that the corner points in one are inside the outline of the other
        /// </summary>
        /// <returns></returns>
        public static bool collisionRect4Rect4Points(Rect4 r0, Rect4 r1)
        {
            // bool rc = false;
            Rectangle rr0 = r0.getAABoundingRect();
            Rectangle rr1 = r1.getAABoundingRect();

            if (!rr0.Intersects(rr1))
            {
                return(false);                      // they cant colide the aa's dont collide
            }
            // if (rr0.Intersects(rr1)) return true; // they cant colide the aa's dont collide

            if (insidePoly(r1.point[0], r0.point, 4))
            {
                return(true);
            }
            if (insidePoly(r1.point[1], r0.point, 4))
            {
                return(true);
            }
            if (insidePoly(r1.point[2], r0.point, 4))
            {
                return(true);
            }
            if (insidePoly(r1.point[3], r0.point, 4))
            {
                return(true);
            }

            if (insidePoly(r0.point[0], r1.point, 4))
            {
                return(true);
            }
            if (insidePoly(r0.point[1], r1.point, 4))
            {
                return(true);
            }
            if (insidePoly(r0.point[2], r1.point, 4))
            {
                return(true);
            }
            if (insidePoly(r0.point[3], r1.point, 4))
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// A Slower accurate collision system for rect 4 structures
        /// checks for line intersections and point containment which i think is totally accurate
        /// </summary>
        /// <returns></returns>
        public static bool collisionRect4Rect4Lines(Rect4 r0, Rect4 r1)
        {
            // bool rc = false;
            Rectangle rr0 = r0.getAABoundingRect();
            Rectangle rr1 = r1.getAABoundingRect();

            if (!rr0.Intersects(rr1))
            {
                return(false);                      // they cant colide the aa's dont collide
            }
            if (insidePoly(r1.point[0], r0.point, 4))
            {
                return(true);
            }
            if (insidePoly(r0.point[0], r1.point, 4))
            {
                return(true);
            }

            for (int i = 0; i < 3; i++)
            {
                // construct a line for r0 point i to j
                int j = i + 1;
                if (j > 3)
                {
                    j = 0;
                }
                Vector2 cp  = new Vector2(0, 0);
                int     rc0 = intersect2D(ref cp, r0.point[i], r0.point[j], r1.point[0], r1.point[1]); if (rc0 != 3)
                {
                    return(true);
                }
                int rc1 = intersect2D(ref cp, r0.point[i], r0.point[j], r1.point[1], r1.point[2]); if (rc1 != 3)
                {
                    return(true);
                }
                int rc2 = intersect2D(ref cp, r0.point[i], r0.point[j], r1.point[2], r1.point[3]); if (rc2 != 3)
                {
                    return(true);
                }
                int rc3 = intersect2D(ref cp, r0.point[i], r0.point[j], r1.point[3], r1.point[0]); if (rc3 != 3)
                {
                    return(true);
                }
            }
            return(false);
        }