protected override Vector3 _ModifyOffset(VertexData vertexData) { if (!noiseModule.IsDisposed) { noiseModule.Dispose(); } var value = 0.5f + (float)noiseModule.GetValue(GetSampleCoordinate(vertexData.position)); return(FormatValue(value, vertexData)); }
public void MapGen() { Points = PointSelectorGen(NumPoints); for (int i = 0; i < 2; i++) { Points = Voronoi.RelaxPoints(Points, new Rectf(0, 0, MapSize, MapSize)); } Voronoi voronoi = new Voronoi(Points, new Rectf(0, 0, MapSize, MapSize)); BuildGraph(Points, voronoi); //ImproveCorners(); voronoi.Dispose(); voronoi = null; Points = null; ////////////////////////////////////// AssignCornerElevations(); AssignOceanCoastAndLand(); AssignBiomes(); //return; RedistributeElevations(landCorners(Corners)); foreach (Corner q in Corners) { if (q.Ocean || q.Coast) { q.Elevation = 0; } } AssignPolygonElevations(); CalculateDownslopes(); CalculateWatersheds(); CreateRivers(); AssignCornerMoisture(); RedistributeMoisture(landCorners(Corners)); AssignPolygonMoisture(); ////////////////////////////////////// AssignBiomes(); }
// Selects the closest node to the center point using the Voronoi diagram public int CreateNewVoronoiSelection(List <Vector2> voronoiNodes, Vector2 centerPoint) { var points = new List <Vector2f>(); foreach (var node in voronoiNodes) { points.Add(new Vector2f(node.x, node.y)); } if (voronoi != null) { voronoi.Dispose(); } // There are two ways you can create the voronoi diagram: with or without the lloyd relaxation. // We do not want lloyd relaxation as it does not represent the real location of the 3D objects. voronoi = new Voronoi(points, bounds, WeightDistributor); edges = voronoi.Edges; if (edges.Count < 1) { return(-1); } // Returns the closest site based on a point. // The algorithm calculates the closest edge and picks the closest adjacent site of that edge. var closestSite = GetClosestSiteByPoint(new Vector2f(centerPoint.x, centerPoint.y)); if (closestSite == null) { return(-1); } // The site index does not match the initial points index, we need to check for the correct index. for (int i = 0; i < points.Count; i++) { if (points[i] == closestSite.Coord) { return(i); } } return(-1); }
public static PointGen generateRelaxed(int size, uint seed) { List <Vector2f> generate(int numPoint) { Voronoi voronoi; List <Vector2f> region = new List <Vector2f>(); List <Vector2f> points = generateRandom(size, seed)(numPoint); for (int i = 0; i < NUM_LLOYD_RELAXATIONS; i++) { voronoi = new Voronoi(points, new Rectf(0, 0, size, size)); for (int j = 0; j < points.Count; j++) { Vector2f p = points[j]; region = voronoi.Region(p); p.x = 0.0f; p.y = 0.0f; for (int k = 0; k < region.Count; k++) { Vector2f q = region[k]; p.x += q.x; p.y += q.y; region.Clear(); } } voronoi.Dispose(); } return(points); } PointGen pGen = generate; return(pGen); }