Beispiel #1
0
        public void ZoomY()
        {
            if (XAxis == null)
            {
                return;
            }

            foreach (var group in _sections.SelectMany(x => x).Where(x => x != null).GroupBy(x => x.Series.YAxisKey))
            {
                var axisMinMax = new MinMaxTracker();

                foreach (var wrapper in group)
                {
                    var minMax = wrapper.GetMinMaxY(XAxis.ActualMinimum, XAxis.ActualMaximum);
                    if (!double.IsNaN(minMax.Min) && !double.IsNaN(minMax.Max))
                    {
                        axisMinMax.Track(minMax.Min, minMax.Max);
                    }
                }

                if (!double.IsNaN(axisMinMax.Min) && !double.IsNaN(axisMinMax.Max))
                {
                    double delta = Math.Abs(axisMinMax.Max - axisMinMax.Min) * 0.02;
                    Axes.First(x => x.Key == group.Key).Zoom(axisMinMax.Min - delta, axisMinMax.Max + delta);
                }
            }
        }
    public void DrawMesh(MeshData meshData, MinMaxTracker heightTracker, ColorSettings colorSettings)
    {
        colorGen.UpdateSettings(colorSettings);
        colorGen.UpdateHeight(heightTracker);
        colorGen.UpdateColors();

        meshFilter.sharedMesh = meshData.CreateMesh();
        meshFilter.GetComponent <MeshRenderer>().sharedMaterial = colorSettings.terrainMaterial;
    }
Beispiel #3
0
        public void ZoomX()
        {
            if (XAxis == null)
            {
                return;
            }

            var tracker = new MinMaxTracker();

            foreach (var series in FlatSeries)
            {
                var minMax = series.GetMinMaxX();
                if (minMax != null)
                {
                    tracker.Track(minMax.Value.Min, minMax.Value.Max);
                }
            }

            double delta = Math.Abs(tracker.Max - tracker.Min) * 0.02;

            XAxis.Zoom(tracker.Min - delta, tracker.Max + delta);
        }
Beispiel #4
0
        public override MinMaxTracker GetMinMaxY(double startX, double endX)
        {
            var result = new MinMaxTracker();

            if (_points.Count == 0)
            {
                return(result);
            }

            GotoX(startX);

            PointWrapper point;
            int          idx = _curIdx;

            while (idx < _points.Count && (point = _pointWrapperFunc(_points[idx])).X < endX)
            {
                result.Track(point.MaxY, point.MinY);
                idx++;
            }

            return(result);
        }
 public void UpdateHeight(MinMaxTracker heightTracker)
 {
     settings.terrainMaterial.SetVector("_heightMinMax", new Vector4(heightTracker.Min, heightTracker.Max, 0, 0));
 }
Beispiel #6
0
    public MeshMatData GetGeneratedData(Vector2 centre, Vector2 coord)
    {
        heightTracker = new MinMaxTracker();

        float[,] map = new float[noiseSettings.mapChunkSize, noiseSettings.mapChunkSize];
        for (int i = 0; i < noiseSettings.SettingsVariations.Length; i++)
        {
            float[,] firstLayerValue = new float[noiseSettings.mapChunkSize, noiseSettings.mapChunkSize];
            if (noiseSettings.SettingsVariations.Length > 0)
            {
                firstLayerValue = NoiseGenerator.GenerateNoise(noiseSettings.SettingsVariations[0], seed, centre);
            }

            SettingsVariation sv = noiseSettings.SettingsVariations[i];
            if (sv.enabled)
            {
                float[,] newMap = NoiseGenerator.GenerateNoise(sv, seed, centre);
                for (int y = 0; y < newMap.GetLength(0); y++)
                {
                    for (int x = 0; x < newMap.GetLength(1); x++)
                    {
                        if (sv.noiseMode == NoiseMode.Add)
                        {
                            float mask = 1;

                            if (sv.useLayerAsMask)
                            {
                                mask = firstLayerValue[x, y];
                                if (sv.InverseLayer)
                                {
                                    mask = 1 - mask;
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                                else
                                {
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                            }
                            newMap[x, y] = Mathf.Max(0, newMap[x, y] - sv.minValue);
                            map[x, y]   += newMap[x, y] * sv.strength * mask;
                        }
                        else
                        if (sv.noiseMode == NoiseMode.Multiply)
                        {
                            map[x, y] *= newMap[x, y];
                        }
                        else
                        if (sv.noiseMode == NoiseMode.Subtract)
                        {
                            float mask = 1;

                            if (sv.useLayerAsMask)
                            {
                                mask = firstLayerValue[x, y];
                                if (sv.InverseLayer)
                                {
                                    mask = 1 - mask;
                                    if (mask <= sv.sampleBelow)
                                    {
                                        mask = 0;
                                    }
                                }
                            }
                            newMap[x, y] += Mathf.Min(0, -newMap[x, y] * sv.minValue);
                            map[x, y]    += newMap[x, y] * sv.strength * mask;
                        }
                    }
                }
            }
        }

        Debug.Log(centre);


        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                heightTracker.AddValue(map[x, y]);
            }
        }

        if (noiseSettings.mapType != MapType.None)
        {
            for (int x = 0; x < map.GetLength(0); x++)
            {
                for (int y = 0; y < map.GetLength(1); y++)
                {
                    float m1     = (map.GetLength(0) - 1) * 3f;
                    float m2     = (map.GetLength(1) - 1) * 3f;
                    float pointX = ((float)x + (centre.x)) / m1;
                    float pointY = ((float)y + (-centre.y)) / m2;


                    map[x, y] = map[x, y] * GradientMap.sampleGradient(pointY, pointX);
                }
            }
        }

        //SmoothenTerrain(map,1,1);
        map = SmoothenTerrain(map);


        colorGen.UpdateSettings(colorSettings);
        colorGen.UpdateHeight(heightTracker);
        colorGen.UpdateColors();
        return(new MeshMatData(map, colorSettings.terrainMaterial));
    }