private void Clip(NavigationPolygon floor, NavigationPolygons staticObjects) { Clipper clipper = new Clipper(); if (!clipper.AddPath(floor, PolyType.ptSubject, true)) { throw new Exception("Can't add Paths (Subject)."); } if (staticObjects.Count > 0 && !clipper.AddPaths(staticObjects, PolyType.ptClip, true)) { throw new Exception("Can't add Paths (Clip)."); } // we do it twice (it's easier than deep copy the polygons), since this is loading screen time... We don't mind performance too much here if (!clipper.Execute(ClipType.ctDifference, floorWithStaticObjects, PolyFillType.pftNonZero)) { throw new Exception("Can't clip floorWithStaticObjects."); } if (!clipper.Execute(ClipType.ctDifference, FloorWithDynamicObjects, PolyFillType.pftNonZero)) { throw new Exception("Can't clip floorWithStaticObjects."); } clipper.Reset(); }
public Map(NavigationPolygon floor, NavigationPolygons staticObjects) { this.floor = floor; this.staticObjects = staticObjects; Initialize(); }
public NavigationPolygon BoundingBox() { var result = new NavigationPolygon(4); result.Add(new DeterministicVector2(A.X, A.Y)); result.Add(new DeterministicVector2(B.X, A.Y)); result.Add(new DeterministicVector2(B.X, B.Y)); result.Add(new DeterministicVector2(A.X, B.Y)); return(result); }
public NavigationPolygon DeepCopy() { NavigationPolygon copy = new NavigationPolygon(this.Count); for (var i = 0; i < this.Count; i++) { copy.Add(this[i].DeepCopy()); } return(copy); }
public void Initialize(NavigationPolygon floor) { Bounding = floor.GetBounding(); Cells.Clear(); for (DeterministicFloat y = Bounding.A.Y; y < Bounding.B.Y; y++) { for (DeterministicFloat x = Bounding.A.X; x < Bounding.B.X; x++) { Cells.Add(new GridCell(x, y) { Type = GridCellType.Free }); } } }