Theo Walton
Theo Walton

Reputation: 1105

how to imitate water on a landscape

I have a double array that contains the ground height and the water height of each 'block' of land, and I am trying to create a function move_water() that will mutate this array so that repeated calls of the function will imitate water moving along the terrain...

My first instinct was:

This doesn't really work very well though and creates some weird wave patterns as the water level on any given block seems to oscillate between 2 values

The water simulation doesn't have to be perfect, I just want it to flow to the lowest point

Upvotes: 0

Views: 90

Answers (2)

yacc
yacc

Reputation: 3361

If you are not concerned about erosion or where the sources of the water are located then I'd go with the simple solution you got from your last question. You'd have to build a one-dimensional array from your landscape and after you got the new mean (see my answer there) you run through your two-dimensional array and adjust the heights that fall below that mean value.

Upvotes: 0

ROX
ROX

Reputation: 1266

Since you say it doesn't have to be perfect, updating in steps defined in terms of how much water has moved, might not be a problem - even though the amount of time it takes for half the water to move will vary according to the slope and the amount of water. It may still look odd therefore that half of a large amount of water on a steep slope takes the same amount of time as a smaller amount on a less steep slope. But your method may still have potential.

Its not clear to me though if you update one block per call or all of them for each call to move_water, I'm going to assume its not just one because that will look odd.

Assuming you process all the blocks, your rule will give different results depending on the order you process the blocks. If you just process them in order of increasing x coordinate, I can imagine why you might see unnatural waves (A lower block can gain from another block, then give to another block then gain again). If on the other hand you processed the highest points first, or processed in order of the highest height difference, you may get better results.

You need to consider the combined height of the land and water, and I would suggest trying moving half of the height difference, not half of the total water.

If you haven't already done this, you might find it helps to consider 1 dimension, flat terrain, placing different amounts of water in the block to start - just to make it easier to work out what's happening.

Finally just moving water to 4 of the surrounding blocks will look a bit odd, if you mean up, down left, and right without water moving diagonally. Once you've got the flow working well in one dimension consider moving to all 8 nearby blocks in the 2D case (assuming the blocks are in a rectangular grid)

Upvotes: 1

Related Questions