Exemple #1
0
        private void GenerateTerrain(int gx, int gy)
        {
            FP x  = gx * this.CellSize;
            FP fP = gy * this.CellSize;
            List <Vertices> list = MarchingSquares.DetectSquares(new AABB(new TSVector2(x, fP), new TSVector2(x + this.CellSize, fP + this.CellSize)), this.SubCellSize, this.SubCellSize, this._terrainMap, this.Iterations, true);
            bool            flag = list.Count == 0;

            if (!flag)
            {
                this._bodyMap[gx, gy] = new List <Body>();
                TSVector2 tSVector = new TSVector2(1f / (float)this.PointsPerUnit, 1f / (float)(-(float)this.PointsPerUnit));
                foreach (Vertices current in list)
                {
                    current.Scale(ref tSVector);
                    current.Translate(ref this._topLeft);
                    Vertices        vertices = SimplifyTools.CollinearSimplify(current, FP.Zero);
                    List <Vertices> list2    = Triangulate.ConvexPartition(vertices, this.Decomposer, true, FP.EN3);
                    foreach (Vertices current2 in list2)
                    {
                        bool flag2 = current2.Count > 2;
                        if (flag2)
                        {
                            this._bodyMap[gx, gy].Add(BodyFactory.CreatePolygon(this.World, current2, 1, null));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void GenerateTerrain(int gx, int gy)
        {
            FP ax = gx * CellSize;
            FP ay = gy * CellSize;

            List <Vertices> polys = MarchingSquares.DetectSquares(new AABB(new TSVector2(ax, ay), new TSVector2(ax + CellSize, ay + CellSize)), SubCellSize, SubCellSize, _terrainMap, Iterations, true);

            if (polys.Count == 0)
            {
                return;
            }

            _bodyMap[gx, gy] = new List <Body>();

            // create the scale vector
            TSVector2 scale = new TSVector2(1f / PointsPerUnit, 1f / -PointsPerUnit);

            // create physics object for this grid cell
            foreach (Vertices item in polys)
            {
                // does this need to be negative?
                item.Scale(ref scale);
                item.Translate(ref _topLeft);
                Vertices simplified = SimplifyTools.CollinearSimplify(item, FP.Zero);

                List <Vertices> decompPolys = Triangulate.ConvexPartition(simplified, Decomposer, true, FP.EN3);

                foreach (Vertices poly in decompPolys)
                {
                    if (poly.Count > 2)
                    {
                        _bodyMap[gx, gy].Add(BodyFactory.CreatePolygon(World, poly, 1, null));
                    }
                }
            }
        }