Beispiel #1
0
 private bool IsIntersectOtherAABB(Vector2 v, Vector2 vm)
 {
     foreach (GeoAABB2 aabb in mLeftRectangle)
     {
         if (GeoAABBUtils.IsAABBInsectAABB2(v, vm, aabb.mMin, aabb.mMax))
         {
             return(true);
         }
     }
     return(mBvh.TestIntersection(new GeoAABB2(v, vm)));
 }
Beispiel #2
0
        private bool CheckRectangleValid(Vector2 min, Vector2 max, float w, float h)
        {
            Vector2 p4 = new Vector2(min[0], max[1]);
            Vector2 p2 = new Vector2(max[0], min[1]);

            // 点都在polygon 内部  // 使用 bvh 判断
            if (mIsConvex)
            {
                bool isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref max);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref min);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p2);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p4);
                if (!isInconvex)
                {
                    return(false);
                }
            }
            else
            {
                if (mSegmentsBvh != null)
                {
                    bool insect = mSegmentsBvh.TestIntersection(new GeoAABB2(min, max));
                    if (insect)
                    {
                        return(false);
                    }
                }
                else
                {
                    bool isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref max);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref min);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p2);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p4);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                }
            }
            // 矩形与矩形是否有交叉
            bool isInsectAABB = IsIntersectOtherAABB(min, max);

            if (isInsectAABB)
            {
                return(false);
            }
            return(true);
        }