Gamedev Framework (gf)  0.8.0 A C++14 framework for 2D games
gf::Heightmap Class Reference

A heightmap. More...

#include <gf/Heightmap.h>

Public Types

enum  Render {
Render::Colored,
}
Rendering mode. More...

Public Member Functions

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 ColorRamp &ramp, double waterLevel=0.5, Render render=Render::Colored) const
Export to a colored image. More...

Detailed Description

A heightmap.

gf::midpointDisplacement2D(), gf::diamondSquare2D()

◆ Render

 strong

Rendering mode.

Enumerator
Colored

Export to a simply colored image.

Export to a shaded image.

◆ Heightmap()

 gf::Heightmap::Heightmap ( Vector2i size )

Constructor.

Parameters
 size The size of the heightmap

Member Function Documentation

 void gf::Heightmap::addHill ( Vector2d center, double radius, double height )

Add a hill to the heightmap.

Parameters
 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.

Parameters
 noise The noise to use scale The scale of the noise

 void gf::Heightmap::addValue ( double value )

Add a constant to the heightmap.

Parameters
 value The value of the constant

◆ clamp()

 void gf::Heightmap::clamp ( double min = 0.0, double max = 1.0 )

Clamp the values of the heightmap.

Parameters
 min The minimum value (defaults to $$0.0$$) max The maximum value (defaults to $$1.0$$)
normalize()

◆ copyToColoredImage()

 Image gf::Heightmap::copyToColoredImage ( const ColorRamp & 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.

Parameters
 ramp A color ramp waterLevel The actual water level (defaults to $$0.5$$) render The rendering mode
Returns
A colored image representing the heightmap
copyToGrayscaleImage()

◆ copyToGrayscaleImage()

 Image gf::Heightmap::copyToGrayscaleImage ( ) const

Export to a grayscale image.

The heightmap is assumed to be normalized.

Returns
A grayscale image representing the heightmap
copyToColoredImage()

◆ digHill()

 void gf::Heightmap::digHill ( Vector2d center, double radius, double height )

Dig a hill in the heightmap.

Parameters
 center The center of the hill radius The radius of the hill height The height of the hill

◆ fastErosion()

 void gf::Heightmap::fastErosion ( unsigned iterations, double talus, double fraction )

Apply fast erosion to the heightmap.

Parameters
 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$$)

◆ getErosionScore()

 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.

◆ getMinMax()

 std::tuple gf::Heightmap::getMinMax ( ) const

Get the minimum and maximum of the heightmap.

Returns
A pair with the first element being the minimum and the second element the maximum

◆ getSize()

 Vector2i gf::Heightmap::getSize ( ) const
inline

Get the size of the heightmap.

Returns
The current size of the heightmap

◆ getSlope()

 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)|)$

Parameters
 position The given position

◆ getValue()

 double gf::Heightmap::getValue ( Vector2i position ) const
inline

Get the value at the specified position.

Parameters
 position A position
Returns
The value at the given position

◆ hydraulicErosion()

 void gf::Heightmap::hydraulicErosion ( unsigned iterations, double rainAmount, double solubility, double evaporation, double capacity )

Apply hydraulic erosision to the heightmap.

Parameters
 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$$)

◆ normalize()

 void gf::Heightmap::normalize ( double min = 0.0, double max = 1.0 )

Normalize the heightmap.

Parameters
 min The new minimum value (defaults to $$0.0$$) max The new maximum value (defaults to $$1.0$$)

◆ reset()

 void gf::Heightmap::reset ( )

Reset the heightmap.

The values are all set to $$0.0$$

◆ scale()

 void gf::Heightmap::scale ( double value )

Scale the values of the heightmap.

Parameters
 value The factor of scaling

◆ setValue()

 void gf::Heightmap::setValue ( Vector2i position, double value )
inline

Set the value at the specified position.

Parameters
 position A position value The new value

◆ subMap()

 Heightmap gf::Heightmap::subMap ( RectI area ) const

Get a sub-map of the heightmap.

Parameters
 area The area of the sub-map in the heightmap

◆ thermalErosion()

 void gf::Heightmap::thermalErosion ( unsigned iterations, double talus, double fraction )

Apply thermal erosion to the heightmap.

Parameters
 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$$)