-
Notifications
You must be signed in to change notification settings - Fork 4
/
TerrainColor.cpp
56 lines (48 loc) · 1.93 KB
/
TerrainColor.cpp
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
#include "TerrainColor.h"
TerrainColor::TerrainColor() {
}
TerrainColor::TerrainColor(GUI::Settings s) {
oceanElevation = 0.0;
coastElevation = 0.4;
beachElevation = 0.5;
plainElevation = 0.55;
forestElevation = 0.75;
hillElevation = 0.85;
mountainElevation = 1.0;
oceanColor = s.oceanColor;
coastColor = s.coastColor;
beachColor = s.beachColor;
plainColor = s.plainColor;
forestColor = s.forestColor;
hillColor = s.hillColor;
mountainColor = s.mountainColor;
}
void TerrainColor::calculateColor(float triangleElevation) {
this->triangleElevation = triangleElevation;
if (triangleElevation < coastElevation) {
interpolateColor(oceanElevation, coastElevation, oceanColor, coastColor);
}
else if (triangleElevation < beachElevation) {
interpolateColor(coastElevation, beachElevation, coastColor, beachColor);
}
else if (triangleElevation < plainElevation) {
interpolateColor(beachElevation, plainElevation, beachColor, plainColor);
}
else if (triangleElevation < forestElevation) {
interpolateColor(plainElevation, forestElevation, plainColor, forestColor);
}
else if (triangleElevation < hillElevation) {
interpolateColor(forestElevation, hillElevation, forestColor, hillColor);
}
else {
interpolateColor(hillElevation, mountainElevation, hillColor, mountainColor);
}
}
void TerrainColor::interpolateColor(float lowElevation, float highElevation, ofColor lowColor, ofColor highColor) {
triangleColor.r = ofMap(triangleElevation, lowElevation, highElevation, lowColor.r, highColor.r);
triangleColor.g = ofMap(triangleElevation, lowElevation, highElevation, lowColor.g, highColor.g);
triangleColor.b = ofMap(triangleElevation, lowElevation, highElevation, lowColor.b, highColor.b);
}
ofColor TerrainColor::getColor() {
return triangleColor;
}