抱歉,如果该标题不是很具有描述性。无论如何,我正在研究处理随机生成的景观。我制作了湖泊,但由于它们的制作方式,它们经常导致直边/下降,这是不可取的。我正在尝试通过定义最大变化量(因此土地高度的变化不能超过它)来平滑它(如果可能的话,就在造湖之后),如果它变化很大,让它固定土地,如果它是退出美好的。
问题:

我尝试的修复:

正如你所看到的......它没有工作。我也想到,如果它不得不向下移动,我认为它会被打破,尽管这种情况实际上不应该发生,因为湖泊只会沉没景观。无论如何,这是我尝试的来源:
//smoothing land nearby
            int maxVariation = 2; //similar to the max height variation when the land is generated
            //going right
            for (int xPos = rightBound + 1, previousHeight = 0; ; ++xPos)
            {
                if (previousHeight == 0)
                    for (; previousHeight < size.y; ++previousHeight)
                        if (grid[0][rightBound][previousHeight] != BlockColor::DIRT && grid[0][rightBound][previousHeight] != BlockColor::GRASS)
                        {
                            --previousHeight;
                            break;
                        }
                for (int y = 0; y < size.y; ++y)
                    if (grid[0][xPos][y] == BlockColor::WATER)
                        goto done_smoothing_right;
                int height;
                for (height = 0; height < size.y; ++height)
                    if (grid[0][xPos][height] != BlockColor::DIRT && grid[0][xPos][height] != BlockColor::GRASS)
                    {
                        --height;
                        break;
                    }
                    int difference = std::abs(height - previousHeight);
                    previousHeight = height;
                    if (difference > maxVariation)
                    {
                        for (int j = 0; j < size.y; ++j)
                        {
                            int toMove = difference;
                            while (j + toMove >= size.y)
                                --toMove;
                            grid[0][xPos][j] = grid[0][xPos][j + toMove];
                        }
                    }
                    else
                        goto done_smoothing_right;
            }
done_smoothing_right:
            int tomakegotowork;
请注意,这只是右侧,但左侧应该大致相同。我怎样才能正确地做到这一点?
谢谢,如果你能帮忙。
编辑:
我从来没有解决过这个问题。相反,我做了一个递归函数来测量空气,(从某个高度),如果一个空气袋(由土地形成)有足够的,可以装满水。这样做的好处是土地看起来很光滑,因为它没有被改变。