@@ -48,8 +48,8 @@ void HydraulicErosion::Simulate(std::vector<std::vector<float>> &map) {
48
48
HeightAndGradient heightAndGradient;
49
49
50
50
// Cast position floats to ints
51
- droplet.node .x = static_cast < int >( droplet.position .x ) ;
52
- droplet.node .y = static_cast < int >( droplet.position .y ) ;
51
+ droplet.node .x = ( int ) droplet.position .x ;
52
+ droplet.node .y = ( int ) droplet.position .y ;
53
53
54
54
// Calculate droplet's offset inside the cell (0,0) = at NW node, (1,1) = at SE node
55
55
droplet.cellOffset .x = droplet.position .x - droplet.node .x ;
@@ -76,20 +76,17 @@ void HydraulicErosion::Simulate(std::vector<std::vector<float>> &map) {
76
76
77
77
// Stop simulating droplet if it's not moving or has flowed over edge of map
78
78
if ((droplet.direction .x == 0 && droplet.direction .y == 0 ) ||
79
- droplet.position .x < 0 ||
80
- droplet.position .x >= xMax ||
81
- droplet.position .y < 0 ||
82
- droplet.position .y >= yMax ||
83
- droplet.node .x < 0 ||
84
- droplet.node .y < 0 ) {
79
+ droplet.position .x < 0 || droplet.position .x >= xMax ||
80
+ droplet.position .y < 0 || droplet.position .y >= yMax ||
81
+ droplet.node .x < 0 || droplet.node .y < 0 ) {
85
82
break ;
86
83
}
87
84
88
85
// Find the droplet's new height and calculate the deltaHeight
89
86
float newHeight = this ->CalculateHeightAndGradient (map, droplet).height ;
90
87
float oldHeight = heightAndGradient.height ;
91
88
float deltaHeight = newHeight - oldHeight;
92
-
89
+
93
90
// Calculate the droplet's sediment capacity (higher when moving fast down a slope and contains lots of water)
94
91
float sedimentCapacity = std::max (-deltaHeight * droplet.velocity * droplet.water * this ->config .sedimentCapacityFactor , this ->config .minSedimentCapacity );
95
92
0 commit comments