示例#1
0
        public bool AABBTest(Geo2D other)
        {
            if (this.MaxX < other.MinX || this.MaxY < other.MinY || other.MaxX < this.MinX || other.MaxY < this.MinY)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public static bool IsIntersect(Poly poly, int x, int z)
        {
            Vector2 pA = new Vector2(left + tileSize * x, bottom + tileSize * z);
            Vector2 pB = new Vector2(left + tileSize * (x + 1), bottom + tileSize * z);
            Vector2 pC = new Vector2(left + tileSize * (x + 1), bottom + tileSize * (z + 1));
            Vector2 pD = new Vector2(left + tileSize * x, bottom + tileSize * (z + 1));

            Geo2D poly2d = poly.GetGeo2D();
            Geo2D rect2d = new Geo2D(pA, pB, pC, pD);

            return(GraphTester2D.IsIntersect(poly2d, rect2d));
        }
示例#3
0
        public Geo2D GetGeo2D()
        {
            if (geo2d == null)
            {
                geo2d = new Geo2D();
                foreach (int i in GetPoints())
                {
                    Vector3 p = Point(i);
                    geo2d.AddPoint(new Vector2(p.x, p.z));
                }

                foreach (GeoEdge e in outerEdges)
                {
                    Vector3 a = Point(e.A);
                    Vector3 b = Point(e.B);
                    geo2d.AddEdge(new Vector2(a.x, a.z), new Vector2(b.x, b.z));
                }
            }
            return(geo2d);
        }
示例#4
0
        public static NavAOI ProcessPolyAOI(SortedDictionary <int, Poly> polys, NavMesh mesh)
        {
            float l    = Mathf.Infinity;
            float r    = Mathf.NegativeInfinity;
            float b    = Mathf.Infinity;
            float t    = Mathf.NegativeInfinity;
            float area = 0f;

            SortedDictionary <int, Poly> .Enumerator polyIter = polys.GetEnumerator();
            while (polyIter.MoveNext())
            {//Poly 信息
                Poly poly = polyIter.Current.Value;

                foreach (int pIndex in poly.GetPoints())
                {
                    Vector3 point = mesh.Point(pIndex);
                    if (point.x < l)
                    {
                        l = point.x;
                    }
                    if (point.z < b)
                    {
                        b = point.z;
                    }
                    if (point.x > r)
                    {
                        r = point.x;
                    }
                    if (point.z > t)
                    {
                        t = point.z;
                    }
                }
                area += poly.GetGeo2D().GetArea();
            }
            polyIter.Dispose();
            area /= polys.Count;

            left     = l;
            bottom   = b;
            width    = r - l;
            height   = t - b;
            tileSize = Mathf.Sqrt(area);
            int w = Mathf.CeilToInt(width / tileSize);
            int h = Mathf.CeilToInt(height / tileSize);

            NavAOI navAOI = new NavAOI(left, bottom, width, height, tileSize);

            polyIter = polys.GetEnumerator();
            while (polyIter.MoveNext())
            {
                Poly poly = polyIter.Current.Value;

                Geo2D geo2D  = poly.GetGeo2D();
                int   xStart = Mathf.FloorToInt(geo2D.MinX / tileSize);
                int   xEnd   = Mathf.CeilToInt(geo2D.MaxX / tileSize);
                int   yStart = Mathf.FloorToInt(geo2D.MinY / tileSize);
                int   yEnd   = Mathf.CeilToInt(geo2D.MaxY / tileSize);

                for (int i = xStart; i < xEnd; i++)
                {
                    for (int j = yStart; j < yEnd; j++)
                    {
                        if (IsIntersect(poly, i, j))
                        {
                            navAOI.AddPolyToAOI(i, j, polyIter.Current.Key);
                        }
                    }
                }
            }
            polyIter.Dispose();

            return(navAOI);
        }