コード例 #1
0
 private void SetDomainHeight(SpanningTree tree)
 {
     foreach (var peak in _voronoiSet)
     {
         peak.PeakHeight = tree.GetHeight(peak.PeakPoint);
     }
 }
コード例 #2
0
        protected internal float[,] GenerateVoronoi(bool domainMap)
        {
            var tx = (int)_arraySize.x;
            var ty = (int)_arraySize.y;

            //var tree = new PeakSearchTree(_voronoiSet, 100);
            int          mx;
            int          my;
            SpanningTree spanningTree = null;

            if (domainMap)
            {
                //Bottom Center Peace
                var start = _voronoiSet[((PeakDistance)(PeakDistances(_voronoiSet, tx / 2, 0)[0])).Id];
                spanningTree = new SpanningTree(_voronoiSet, start);
                SetDomainHeight(spanningTree);
            }


            var highestScore = 0.0f;

            for (my = 0; my < ty; my++)
            {
                for (mx = 0; mx < tx; mx++)
                {
                    var peakDistances = PeakDistances(_voronoiSet, mx, my);
                    var peakDistOne   = (PeakDistance)peakDistances[0];
                    var peakDistTwo   = (PeakDistance)peakDistances[1];
                    var hScore        = GetVornoiHeight(domainMap, _voronoiScale, peakDistOne, peakDistTwo, tx, ty, _voronoiCells, _voronoiSet, spanningTree);
                    hScore             = Math.Max(0.0f, hScore);
                    hScore             = Math.Min(1.0f, hScore);
                    _heightMap[mx, my] = hScore;
                    if (hScore > highestScore)
                    {
                        highestScore = hScore;
                    }
                }
            }
            // Normalise...
            for (my = 0; my < ty; my++)
            {
                for (mx = 0; mx < tx; mx++)
                {
                    var normalisedHeight = _heightMap[mx, my] * (1.0f / highestScore);
                    _heightMap[mx, my] = normalisedHeight;
                }
            }
            return(_heightMap);
        }
コード例 #3
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);
            }
        }