private void GenerateCity() { //seed random if (!GenerationSettings.UseSeed) { GenerationSettings.Seed = DateTime.Now.GetHashCode(); } //Store Settings var width = GenerationSettings.Width; var length = GenerationSettings.Length; //Parent.transform.position = citypos; GenerationSettings.StartX = Parent.transform.position.x - width / 2.0; GenerationSettings.StartY = Parent.transform.position.z - length / 2.0; //Generate Points and diagram var points = PointGenerator.Generate(GenerationSettings); VoronoiDiagram = VoronoiGenerator.CreateVoronoi(points, GenerationSettings); //generate city districts and roads _cityData = CityBuilder.GenerateCity(CitySettings, VoronoiDiagram); }
/// <summary> /// Convert the Voronoi Diagram into a city with roads and building zones /// </summary> private void GenerateCity() { if (_voronoiDiagram == null) { //GenerateVoronoi(); return; } //Settings for generation _citySettings.DistrictSettings = DistrictSettings.ToList(); _citySettings.GenerateInnerRoads = GenerateInnerRoads; _citySettings.RoadSubdivision = RoadSubdivisions; _citySettings.DebugMode = DebugMode.Value; //generate city var timer = Stopwatch.StartNew(); _cityData = CityBuilder.GenerateCity(_citySettings, _voronoiDiagram); timer.Stop(); //update timer var time = timer.ElapsedMilliseconds / 1000.0; GenerationTimeText = $"City generated in {time} seconds."; //update canvas RefreshCanvas(); //InsetTesting var insetCells = new List <Cell>(); var points = new List <Point>(); foreach (var d in _cityData.Districts) { foreach (var c in d.Cells) { var cInset = c.Inset(20); insetCells.Add(cInset); //_drawService.DrawCell(c, Color.FromArgb(255, 120, 120, 120), true, true); points.AddRange(cInset.GenerateRandomPoints(9)); } } ////Draw foreach (var c in insetCells) { //_drawService.DrawCell(c, Color.FromArgb(255, 188, 188, 188), true, true); //Draw Triangulation var triangles = new BowyerWatsonGenerator().DelaunayTriangulation(c.Points); foreach (var t in triangles) { //_drawService.DrawTriangle(t, Colors.CornflowerBlue); } } foreach (var p in points) { _drawService.DrawPoint(p, 4, Colors.OrangeRed); } }