![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
A heightmap. More...
#include <gf/Heightmap.h>
Public Types | |
enum class | Render { Colored , Shaded } |
Rendering mode. More... | |
Public Member Functions | |
Heightmap ()=default | |
Default constructor. More... | |
Heightmap (Vector2i size) | |
Constructor. More... | |
Vector2i | getSize () const |
Get the size of the heightmap. More... | |
void | reset () |
Reset the heightmap. More... | |
double | getValue (Vector2i position) const |
Get the value at the specified position. More... | |
void | setValue (Vector2i position, double value) |
Set the value at the specified position. More... | |
std::tuple< double, double > | getMinMax () const |
Get the minimum and maximum of the heightmap. More... | |
Shaping | |
void | normalize (double min=0.0, double max=1.0) |
Normalize the heightmap. More... | |
void | addHill (Vector2d center, double radius, double height) |
Add a hill to the heightmap. More... | |
void | digHill (Vector2d center, double radius, double height) |
Dig a hill in the heightmap. More... | |
void | addNoise (Noise2D &noise, double scale=1.0) |
Add a noise to the heightmap. More... | |
void | addValue (double value) |
Add a constant to the heightmap. More... | |
void | scale (double value) |
Scale the values of the heightmap. More... | |
void | clamp (double min=0.0, double max=1.0) |
Clamp the values of the heightmap. More... | |
Erosion | |
double | getSlope (Vector2i position) const |
Compute the slope at a position. More... | |
void | thermalErosion (unsigned iterations, double talus, double fraction) |
Apply thermal erosion to the heightmap. More... | |
void | hydraulicErosion (unsigned iterations, double rainAmount, double solubility, double evaporation, double capacity) |
Apply hydraulic erosision to the heightmap. More... | |
void | fastErosion (unsigned iterations, double talus, double fraction) |
Apply fast erosion to the heightmap. More... | |
double | getErosionScore () const |
Compute the erosion score for the heightmap. More... | |
Export | |
Heightmap | subMap (RectI area) const |
Get a sub-map of the heightmap. More... | |
Image | copyToGrayscaleImage () const |
Export to a grayscale image. More... | |
Image | copyToColoredImage (const ColorRampD &ramp, double waterLevel=0.5, Render render=Render::Colored) const |
Export to a colored image. More... | |
A heightmap.
|
strong |
|
default |
Default constructor.
gf::Heightmap::Heightmap | ( | Vector2i | size | ) |
Constructor.
size | The size of the heightmap |
void gf::Heightmap::addHill | ( | Vector2d | center, |
double | radius, | ||
double | height | ||
) |
Add a hill to the heightmap.
center | The center of the hill |
radius | The radius of the hill |
height | The height of the hill |
void gf::Heightmap::addNoise | ( | Noise2D & | noise, |
double | scale = 1.0 |
||
) |
Add a noise to the heightmap.
noise | The noise to use |
scale | The scale of the noise |
void gf::Heightmap::addValue | ( | double | value | ) |
Add a constant to the heightmap.
value | The value of the constant |
void gf::Heightmap::clamp | ( | double | min = 0.0 , |
double | max = 1.0 |
||
) |
Clamp the values of the heightmap.
min | The minimum value (defaults to \( 0.0 \)) |
max | The maximum value (defaults to \( 1.0 \)) |
Image gf::Heightmap::copyToColoredImage | ( | const ColorRampD & | ramp, |
double | waterLevel = 0.5 , |
||
Render | render = Render::Colored |
||
) | const |
Export to a colored image.
The heightmap is assumed to be normalized.
The color ramp assumes that the water level is at \( 0.5 \). The actual water level can be specified and the ramp is automatically adapted on the fly.
ramp | A color ramp |
waterLevel | The actual water level (defaults to \( 0.5 \)) |
render | The rendering mode |
Image gf::Heightmap::copyToGrayscaleImage | ( | ) | const |
Export to a grayscale image.
The heightmap is assumed to be normalized.
void gf::Heightmap::digHill | ( | Vector2d | center, |
double | radius, | ||
double | height | ||
) |
Dig a hill in the heightmap.
center | The center of the hill |
radius | The radius of the hill |
height | The height of the hill |
void gf::Heightmap::fastErosion | ( | unsigned | iterations, |
double | talus, | ||
double | fraction | ||
) |
Apply fast erosion to the heightmap.
iterations | The number of iterations |
talus | The maximum difference for a move of material (typically \( \frac{8}{N} \) or more) |
fraction | The fraction of material that moves (typically \( 0.5 \)) |
double gf::Heightmap::getErosionScore | ( | ) | const |
Compute the erosion score for the heightmap.
The erosion score is the average slope divided by the standard deviation of slopes. A high erosion score means that the terrain has large flat areas and has some steep areas.
std::tuple< double, double > gf::Heightmap::getMinMax | ( | ) | const |
Get the minimum and maximum of the heightmap.
|
inline |
Get the size of the heightmap.
double gf::Heightmap::getSlope | ( | Vector2i | position | ) | const |
Compute the slope at a position.
The slope is defined as "the greatest of the height differences between the cell and its four neighbours in a Von Neumann neighbourhood".
\[ \text{slope}(x, y) = \max(|h(x,y) - h(x - 1, y)|, |h(x,y) - h(x + 1, y)|, |h(x,y) - h(x, y - 1)|, |h(x,y) - h(x, y + 1)|) \]
position | The given position |
|
inline |
Get the value at the specified position.
position | A position |
void gf::Heightmap::hydraulicErosion | ( | unsigned | iterations, |
double | rainAmount, | ||
double | solubility, | ||
double | evaporation, | ||
double | capacity | ||
) |
Apply hydraulic erosision to the heightmap.
iterations | The number of iterations |
rainAmount | The amount of rain each cell receives at each iteration (typically \( 0.01 \)) |
solubility | The solubility of the terrain (typically \( 0.01 \)) |
evaporation | The proportion of evaporated water at each iteration (typically \( 0.5 \)) |
capacity | The maximum proportion of material that can be carried by water (typically \( 0.01 \)) |
void gf::Heightmap::normalize | ( | double | min = 0.0 , |
double | max = 1.0 |
||
) |
Normalize the heightmap.
min | The new minimum value (defaults to \( 0.0 \)) |
max | The new maximum value (defaults to \( 1.0 \)) |
void gf::Heightmap::reset | ( | ) |
Reset the heightmap.
The values are all set to \( 0.0 \)
void gf::Heightmap::scale | ( | double | value | ) |
Scale the values of the heightmap.
value | The factor of scaling |
|
inline |
Set the value at the specified position.
position | A position |
value | The new value |
Get a sub-map of the heightmap.
area | The area of the sub-map in the heightmap |
void gf::Heightmap::thermalErosion | ( | unsigned | iterations, |
double | talus, | ||
double | fraction | ||
) |
Apply thermal erosion to the heightmap.
iterations | The number of iterations |
talus | The minimum difference for a move of material (typically \( \frac{4}{N} \)) |
fraction | The fraction of material that moves (typically \( 0.5 \)) |