From f89e7107bbf6d5b61d0d4160b32bc92f6c2b456f Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 9 Mar 2008 19:22:21 +0000 Subject: * Fix for hydraulic erosion brush. Still not working as planned, but getting closer. Bugs may be due to the water distribution pattern. --- .../Modules/Terrain/PaintBrushes/ErodeSphere.cs | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs index d6f666d..2d46fd9 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs @@ -37,9 +37,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes { NeighbourSystem type = NeighbourSystem.Moore; // Parameter - double rainHeight = 1.0; + double rainHeight = 0.2; int rounds = 10; - double waterSaturation = 0.01; // Can carry 1% of water in height + double waterSaturation = 0.30; // Can carry 1% of water in height #region Supporting Functions private enum NeighbourSystem @@ -257,7 +257,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes double altitudeNeighbour = water[coords[0], coords[1]] + map[coords[0], coords[1]]; // If it's greater than me... - if (altitudeNeighbour - altitudeMe > 0) + if (altitudeNeighbour - altitudeMe < 0) { // Add it to our calculations neighbours++; @@ -290,13 +290,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes if (coords[1] < 0) continue; + // Skip if we dont have water to begin with. + if (water[x, y] < 0) + continue; + // Calculate our delta average double altitudeDelta = altitudeMe - altitudeAvg; + if (altitudeDelta < 0) + continue; + // Calculate how much water we can move - double waterDelta = Math.Min(water[x, y], altitudeDelta) - * (water[coords[0], coords[1]] + map[coords[0], coords[1]]) - / altitudeTotal; + double waterMin = Math.Min(water[x, y], altitudeDelta); + double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) + / altitudeTotal); double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); @@ -320,9 +327,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes double waterCapacity = waterSaturation * water[x, y]; - double sedimentDeposit = Math.Max(0, sediment[x, y] - waterCapacity); - sediment[x, y] -= sedimentDeposit; - map[x, y] += sedimentDeposit; + double sedimentDeposit = sediment[x, y] - waterCapacity; + if (sedimentDeposit > 0) + { + sediment[x, y] -= sedimentDeposit; + map[x, y] += sedimentDeposit; + } } } } -- cgit v1.1