Exemple #1
0
        private static float GetVornoiHeight(bool domainMap, float voronoiScale, PeakDistance d1, PeakDistance d2, int tx, int ty, double voronoiCells, List <Peak> voronoiSet, SpanningTree tree)
        {
            if (domainMap)
            {
                var peakOne = voronoiSet[d1.Id];
                var peakTwo = voronoiSet[d2.Id];
                var hScore  = peakOne.PeakHeight;
                if (tree.IsEdgeBetweenVectors(peakOne.PeakPoint, peakTwo.PeakPoint))
                {
                    hScore = GetSlopeHeight(d1, d2, voronoiSet);
                }


                return(hScore);
            }
            else
            {
                var scale   = (float)(Math.Abs(d1.Dist - d2.Dist) / ((tx + ty) / Math.Sqrt(voronoiCells)));
                var peakOne = voronoiSet[d1.Id];
                var h1      = peakOne.PeakHeight;
                var hScore  = h1 - Math.Abs(d1.Dist / d2.Dist) * h1;

                hScore = (hScore * scale * voronoiScale) + (hScore * (1.0f - voronoiScale));
                return(hScore);
            }
        }
Exemple #2
0
        private static float GetSlopeHeight(PeakDistance d1, PeakDistance d2, List <Peak> voronoiSet)
        {
            var pos = d1.Dist / (d1.Dist + d2.Dist);

            if (pos < 0.3)
            {
                return(voronoiSet[d1.Id].PeakHeight);
            }
            if (pos > 0.7)
            {
                return(voronoiSet[d2.Id].PeakHeight);
            }
            pos = (pos - 0.3f) * 2.5f;
            var dif = voronoiSet[d2.Id].PeakHeight - voronoiSet[d1.Id].PeakHeight;

            return(dif * pos + voronoiSet[d1.Id].PeakHeight);
        }
Exemple #3
0
        /*protected internal float[,] GenerateCutPattern()
         * {
         *  var tx = (int)_arraySize.X;
         *  var ty = (int)_arraySize.Y;
         *  var cutPattern = new float[tx,ty];
         *  var tree = new PeakSearchTree(_voronoiSet, 30);
         *  Console.WriteLine("NearestPeakAmount:" + tree.GetNearestPeaks(10, 10, 1).Count);
         *
         *  //delete center Pieces
         *  var centerDistances = PeakDistances(_voronoiSet, (int)_arraySize.X / 2, (int)_arraySize.Y / 2);
         *  var toDelete = _voronoiSet.ToArray();
         *  for (var i = 0; i < centerDistances.Count*0.25; i++)
         *  {
         *      _voronoiSet.Remove(toDelete[((PeakDistance)centerDistances[i]).Id]);
         *  }
         *
         *
         *  for (var x = 0; x < _arraySize.X; x++)
         *  {
         *      var peakDistances = PeakDistances(_voronoiSet, x, 0);
         *      var peak = _voronoiSet[((PeakDistance)peakDistances[0]).Id];
         *      peak.PeakHeight = 0f;
         *      peakDistances = PeakDistances(_voronoiSet, x, (int)_arraySize.Y - 1);
         *      peak = _voronoiSet[((PeakDistance)peakDistances[0]).Id];
         *      peak.PeakHeight = 0f;
         *  }
         *
         *  for (var x = 0; x <=1; x++)
         *  {
         *      x *= (int) _arraySize.X-1;
         *      for (var y = 0; y < _arraySize.Y; y++)
         *      {
         *          var peakDistances = PeakDistances(_voronoiSet, x, y);
         *          var peak = _voronoiSet[((PeakDistance)peakDistances[0]).Id];
         *          peak.PeakHeight = 0f;
         *      }
         *
         *  }
         *
         *  //Colorize pixels
         *  //_voronoiSet = voronoiSetCopy;
         *  for (var my = 0; my < ty; my++)
         *  {
         *      for (var mx = 0; mx < tx; mx++)
         *      {
         *          var peakDistances = PeakDistances(_voronoiSet, mx, my);
         *          var peak = _voronoiSet[((PeakDistance) peakDistances[0]).Id];
         *          var hScore = peak.PeakHeight;
         *          hScore = (int)(hScore*1000) == 0 ? 0.0f : 1.0f;
         *          cutPattern[mx, my] = hScore;
         *      }
         *  }
         *  return cutPattern;
         * }*/

        private static ArrayList PeakDistances(List <Peak> voronoiSet, int mx, int my)
        {
            var peakDistances = new ArrayList();
            int i;

            for (i = 0; i < voronoiSet.Count; i++)
            {
                var peakI           = voronoiSet[i];
                var peakPoint       = peakI.PeakPoint;
                var distanceToPeak  = (peakPoint - new Vector2(mx, my)).magnitude;
                var newPeakDistance = new PeakDistance {
                    Id = i, Dist = distanceToPeak
                };
                peakDistances.Add(newPeakDistance);
                //if (mx == 0) Debug.Log(mx + "/" + my + ": " + _voronoiSet[i].PeakPoint);
            }
            peakDistances.Sort();
            return(peakDistances);
        }