-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHydraulicErosion.h
75 lines (62 loc) · 1.5 KB
/
HydraulicErosion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef HYDRAULIC_EROSION_H
#define HYDRAULIC_EROSION_H
#include <vector>
#include <cmath>
#include <random>
#include "Tool.h"
struct Vec2{
float x;
float y;
};
struct Node {
int x;
int y;
};
struct HeightAndGradient {
float height;
Vec2 gradient;
};
struct Droplet {
Vec2 position;
Vec2 direction;
Node node;
Vec2 cellOffset;
float velocity;
float sediment;
float water;
};
struct Brush {
Node start;
Node end;
std::vector<std::vector<float>> weights;
float weightSum;
};
struct HydraulicErosionConfig {
int seed;
int numIterations;
int erosionRadius;
float inertia;
float sedimentCapacityFactor;
float minSedimentCapacity;
float erodeSpeed;
float depositSpeed;
float evaporateSpeed;
float gravity;
int maxDropletLifetime;
float initialWaterVolume;
float initialVelocity;
int mapWidth;
int mapHeight;
};
class HydraulicErosion {
public:
HydraulicErosion(HydraulicErosionConfig eroderConfig);
~HydraulicErosion();
void Simulate(std::vector<std::vector<float>> &map);
private:
HydraulicErosionConfig config;
HeightAndGradient CalculateHeightAndGradient(std::vector<std::vector<float>> &map, Droplet &droplet);
void Deposit(std::vector<std::vector<float>> &map, Droplet &droplet, float deltaHeight, float sedimentCapacity);
void Erode(std::vector<std::vector<float>> &map, Droplet &droplet, float deltaHeight, float sedimentCapacity);
};
#endif //HYDRAULIC_EROSION_H