libtcoddocumentation

14.2. Basic operations

Those are simple operations applied either on a single map cell or on every map cell.

Setting a cell value

Once the heightmap has been created, you can do some basic operations on the values inside it.
You can set a single value :

void TCODHeightMap::setValue(int x, int y, float v)

void TCOD_heightmap_set_value(TCOD_heightmap_t *hm, int x, int y, float value)

heightmap_set_value(hm, x, y, value)

void TCODHeightMap::setValue(int x, int y, float v)

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.
x,yCoordinates of the cells to modify inside the map.
0 <= x < map width
0 <= y < map height
valueThe new value of the map cell.

Adding a float value to all cells

void TCODHeightMap::add(float value)

void TCOD_heightmap_add(TCOD_heightmap_t *hm, float value)

heightmap_add(hm, value)

void TCODHeightMap::add(float value)

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.
valueValue to add to every cell.

Multiplying all values by a float

void TCODHeightMap::scale(float value)

void TCOD_heightmap_scale(TCOD_heightmap_t *hm, float value)

heightmap_scale(hm, value)

void TCODHeightMap::scale(float value)

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.
valueEvery cell's value is multiplied by this value.

Resetting all values to 0.0

void TCODHeightMap::clear()

void TCOD_heightmap_clear(TCOD_heightmap_t *hm)

heightmap_clear(hm)

void TCODHeightMap::clear()

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.

Clamping all values

void TCODHeightMap::clamp(float min, float max)

void TCOD_heightmap_clamp(TCOD_heightmap_t *hm, float min, float max)

heightmap_clamp(hm, mi, ma)

void TCODHeightMap::clamp(float min, float max)

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.
min,maxEvery cell value is clamped between min and max.
min < max

Copying values from another heightmap

void TCODHeightMap::copy(const TCODHeightMap *source)

void TCOD_heightmap_copy(const TCOD_heightmap_t *source,TCOD_heightmap_t *dest)

heightmap_copy(source,dest)

void TCODHeightMap::copy(TCODHeightMap source)

ParameterDescription
sourceEach cell value from the source heightmap is copied in the destination (this for C++) heightmap.
The source and destination heightmap must have the same width and height.
destIn the C and python versions, the address of the destination heightmap.

Normalizing values

void TCODHeightMap::normalize(float min=0.0f, float max=1.0f)

void TCOD_heightmap_normalize(TCOD_heightmap_t *hm, float min, float max)

heightmap_normalize(hm, mi=0.0, ma=1.0)

void TCODHeightMap::normalize()
void
TCODHeightMap::normalize(float min)
void
TCODHeightMap::normalize(float min, float max)

ParameterDescription
hmIn the C version, the address of the heightmap struct returned by the creation function.
min,maxThe whole heightmap is translated and scaled so that the lowest cell value becomes min and the highest cell value becomes max
min < max

Doing a lerp operation between two heightmaps

void TCODHeightMap::lerp(const TCODHeightMap *a, const TCODHeightMap *b,float coef)

void TCOD_heightmap_lerp_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res, float coef)

heightmap_lerp_hm(a, b, res, coef)

void TCODHeightMap::lerp(TCODHeightMap a, TCODHeightMap b, float coef)

ParameterDescription
aFirst heightmap in the lerp operation.
bSecond heightmap in the lerp operation.
coeflerp coefficient.
For each cell in the destination map (this for C++), value = a.value + (b.value - a.value) * coef
resIn the C and python versions, the address of the destination heightmap.

Adding two heightmaps

void TCODHeightMap::add(const TCODHeightMap *a, const TCODHeightMap *b)

void TCOD_heightmap_add_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)

heightmap_add_hm(a, b, res)

void TCODHeightMap::add(TCODHeightMap a, TCODHeightMap b)

ParameterDescription
aFirst heightmap.
bSecond heightmap. For each cell in the destination map (this for C++), value = a.value + b.value
resIn the C and python versions, the address of the destination heightmap.

Multiplying two heightmaps

void TCODHeightMap::multiply(const TCODHeightMap *a, const TCODHeightMap *b)

void TCOD_heightmap_multiply_hm(const TCOD_heightmap_t *a, const TCOD_heightmap_t *b, TCOD_heightmap_t *res)

heightmap_multiply_hm(a, b, res)

void TCODHeightMap::multiply(TCODHeightMap a, TCODHeightMap b)

ParameterDescription
aFirst heightmap.
bSecond heightmap. For each cell in the destination map (this for C++), value = a.value * b.value
resIn the C and python versions, the address of the destination heightmap.