private void SetRegions() { Dictionary <Vector2Int, Vertex> posToVertex = new Dictionary <Vector2Int, Vertex>(); List <Region> regions = new List <Region>(); foreach (Vector2 sitePos in voronoi.SiteCoords()) { List <Vertex> vertices = new List <Vertex>(); foreach (Vector2Int vertPos in MathVert.ToVector2Int(voronoi.Region(sitePos))) { //Drawer.DrawHLine(edgePos, Color.blue); if (!posToVertex.ContainsKey(vertPos)) { posToVertex.Add(vertPos, new Vertex(vertPos)); } vertices.Add(posToVertex[vertPos]); } Region region = new Region(sitePos, vertices.ToArray()); siteToRegion[sitePos] = region; regions.Add(region); } foreach (Vector2 site in voronoi.SiteCoords()) { foreach (Vector2 nSite in voronoi.NeighborSitesForSite(site)) { siteToRegion[site].neighbours.Add(siteToRegion[nSite]); } } this.regions = regions.ToArray(); RegionsInfo.regions = this.regions; RegionsInfo.UpdateRegionsMap(); }
public void DoForEachPosition(Action <Vector2Int> action) { foreach (Vector2Int point in MathVert.GetPositionsBetween(ranges)) { action.Invoke(point); } }
public Region(Vector2 site, Vertex[] vertices) { type = new RegionType(this); this.site = new Site(this, site); this.vertices = vertices; UpdateVertices(); bounds = MathVert.GetBoundsBetween(EdgePositions()); ranges = MathVert.GetRangesBetween(bounds); }
private void CalculatePath() { for (int i = 0; i < vertices.Count - 1; i++) { path.AddRange(MathVert.ConnectPoints(vertices[i + 1], vertices[i], false)); //Drawer.DrawLine(edges[i], edges[i + 1], Vector3.up, Color.Lerp(Color.blue, Color.black, (float)i / edges.Count)); } /*for (int i = 0; i < path.Count - 1; i++) * { * Drawer.DrawLine(path[i], path[i + 1], Color.Lerp(Color.white, Color.black, (float)i / path.Count)); * }*/ }
private Vector3 SiteWithHeight(Region region) { if (region.type.DistIndexFromCoastline <= 0) { return(MathVert.ToVector3(region.site)); } float dist = (float)region.type.DistIndexFromCoastline; dist = Mathf.Clamp(dist - heightSettings.heightOffset, 1, dist); float height = Mathf.Round(Mathf.Pow(dist / RegionsInfo.MaxDistIndex * heightSettings.heightValue, 2)); return(MathVert.ToVector3(region.site) + Vector3.up * height); }
private void SetGround() { // Set ground & water flags foreach (Region region in RegionsInfo.regions) { Vector2Int site = MathVert.ToVector2Int(region.site); if (waterMask[site.x, site.y] < 1) { region.type.MarkAsWater(); } else { region.type.MarkAsGround(); } } }
private void SetMapHeight() { foreach (Triangle triangle in Triangle.allTriangles) { if (triangle.GetMidCLIndex() <= 0) { continue; } //Drawer.DrawConnectedLines(triangle.GetSitePositions(), Color.white); Vector3[] trianglePoints = new Vector3[3]; for (int i = 0; i < 3; i++) { trianglePoints[i] = SiteWithHeight(triangle.sites[i].parent); } Vector2Int[] bounds = MathVert.GetBoundsBetween(triangle.GetSitePositions()); for (int i = 0; i < bounds.Length - 1; i++) { Vector2Int quadPos = WorldMesh.VertexPosToQuadPos(bounds[i], bounds[i + 1]); int oriantation = WorldMesh.GetOriantation(bounds[i], bounds[i + 1]); // WorldMesh.oriantationMap[quadPos.x, quadPos.y] = oriantation; } Vector2Int[] positions = MathVert.GetPositionsBetween(MathVert.GetRangesBetween(bounds)); foreach (Vector2Int position in positions) { //Drawer.DrawHLine(position, Color.white); //WorldMesh.colorMap[position.x, position.y].ALL = Color.red; Vector3 vertex = WorldMesh.verticesMap[position.x, position.y]; vertex.y = MathVert.GetHeihtBetween3Points(position, trianglePoints); WorldMesh.verticesMap[position.x, position.y] = vertex; } } }
public Vector2Int[] GetRegionPositions() { return(MathVert.GetPositionsBetween(ranges)); }
/// <summary> /// Draw line between two points. /// </summary> public static void DrawLine(Vector2 point1, Vector2 point2, Vector3 offset, Color color, float duration = float.PositiveInfinity) { DefDrawLine(MathVert.ToVector3(point1) + offset, MathVert.ToVector3(point2) + offset, color, duration); }
/// <summary> /// Draw vertical line. /// </summary> public static void DrawVLine(Vector2 point, Color color, float length, float duration = float.PositiveInfinity) { DrawVLine(MathVert.ToVector3(point), color, length, duration); }