Smoothing land around lakes

Sorry if this title is not very descriptive. Anyway, I'm working on randomly creating landscapes. I made lakes, but because of how they are made, they often cause straight edges / outliers, which are undesirable. I try to smooth it out (immediately after the creation of the lake, if possible) by determining the maximum variation (so that the height of the earth cannot be greater than it), and let it correct the earth if it varies a lot, and leave if it well.

Problem:

Large dropoff

My attempt to fix:

Attempted fix

As you can see ... this did not work. This is also the case for me, I think it would break if he had to go down, although this case should not happen, because the lakes only ever lower the landscape. Anyway, here is the source of my attempt:

//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; 

Note that this is only the right side, but the left should be approximately the same. How can I do it right?

Thanks if you can help.

EDIT:

I have never solved this problem. Instead, I made a recursive function to measure air (from a certain height) and, if there was a sufficient supply of air (formed by the ground) to fill with water. This has the advantage that the earth looks smooth because it does not change.

+6
source share
1 answer

It is written in java, so you will need to convert it to C ++, but it should give you the main idea. It will work only to smooth up, and I only do the right side of the lake, but it is very easy to change it for the left side of the lake. I tried to match what, in my opinion, has the functionality of your code.

Hope this helps ...

 void smoothLakeRight(Lake lake){ int x = lake.rightBound+1; if(getGrassHeight(x)-lake.height>WorldConstants.MAX_LAKESIDE_VARIATION){ //if the right bank is too high start smoothing int y =lake.height+WorldConstants.MAX_LAKESIDE_VARIATION; while(grid[0][x][y] == BlockColor.DIRT){ fixGrass(x++, y++); } } } private int getGrassHeight(int xPos){ int y = WorldConstants.LOWEST_GRASS; while(grid[0][xPos][y++] != BlockColor.GRASS); return y-1; } private void fixGrass(int xPos, int yPos){ grid[0][xPos][yPos] = BlockColor.GRASS; aboveAir(xPos,yPos); belowDirt(xPos, yPos); } private void aboveAir(int xPos, int yPos) { while(grid[0][xPos][++yPos]!=BlockColor.AIR){ if(grid[0][xPos][yPos]==BlockColor.TREE){ upRootTree(xPos, yPos); }else{ grid[0][xPos][yPos]=BlockColor.AIR; } } } private void upRootTree(int xPos, int yPos) { while(grid[0][xPos][yPos]==BlockColor.TREE){//remove stump grid[0][xPos][yPos++]=BlockColor.AIR; } //remove leaves grid[0][xPos][yPos] = BlockColor.AIR; grid[0][xPos+1][yPos] = BlockColor.AIR; grid[0][xPos-1][yPos] = BlockColor.AIR; grid[0][xPos+1][yPos-1] = BlockColor.AIR; grid[0][xPos-1][yPos-1] = BlockColor.AIR; } private void belowDirt(int xPos, int yPos) { while(grid[0][xPos][--yPos]!=BlockColor.DIRT){ grid[0][xPos][yPos] = BlockColor.DIRT; } } 
+1
source

Source: https://habr.com/ru/post/949251/


All Articles