/// Produces a heightmap using the Voronoi generator. /// Returns true if the map must be renormalized. /// The debugHeightmap parameter is used for debug to display the generated curve (with higher precision). /// See e2dGeneratorCurveMethod for details. private bool GenerateCurveVoronoi(float[] heightMap, Rect targetRect, ref float[] debugHeightmap) { // init the peaks int peakCount = Mathf.RoundToInt(Voronoi.frequencyPerUnit * targetRect.width); List <Vector2> peaks = PreparePeaks(peakCount, Voronoi.peakRatio, Voronoi.usePeaks, targetRect); // init the function e2dVoronoi function = new e2dVoronoi(peaks, Voronoi.peakType, Voronoi.peakWidth); // produce heights for (int i = 0; i < heightMap.Length; i++) { float x = (float)i / (float)(heightMap.Length - 1); heightMap[i] = function.GetValue(x); } // fill the heightmap for debug if (e2dUtils.DEBUG_GENERATOR_CURVE) { debugHeightmap = new float[10 * heightMap.Length]; for (int i = 0; i < debugHeightmap.Length; i++) { float x = (float)i / (float)(debugHeightmap.Length - 1); debugHeightmap[i] = function.GetValue(x) * targetRect.height; } } return(!Voronoi.usePeaks); }
private bool GenerateCurveVoronoi(float[] heightMap, Rect targetRect, ref float[] debugHeightmap) { int totalPeakCount = Mathf.RoundToInt(this.Voronoi.frequencyPerUnit * targetRect.width); List <Vector2> peaks = this.PreparePeaks(totalPeakCount, this.Voronoi.peakRatio, this.Voronoi.usePeaks, targetRect); e2dVoronoi e2dVoronoi = new e2dVoronoi(peaks, this.Voronoi.peakType, this.Voronoi.peakWidth); for (int i = 0; i < heightMap.Length; i++) { float x = (float)i / (float)(heightMap.Length - 1); heightMap[i] = e2dVoronoi.GetValue(x); } if (e2dUtils.DEBUG_GENERATOR_CURVE) { debugHeightmap = new float[10 * heightMap.Length]; for (int j = 0; j < debugHeightmap.Length; j++) { float x2 = (float)j / (float)(debugHeightmap.Length - 1); debugHeightmap[j] = e2dVoronoi.GetValue(x2) * targetRect.height; } } return(!this.Voronoi.usePeaks); }