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)
Parameter | Description |
---|---|
hm | In the C version, the address of the heightmap struct returned by the creation function. |
x,y | Coordinates of the cells to modify inside the map. 0 <= x < map width 0 <= y < map height |
value | The 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)
Parameter | Description |
---|---|
hm | In the C version, the address of the heightmap struct returned by the creation function. |
value | Value 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)
Parameter | Description |
---|---|
hm | In the C version, the address of the heightmap struct returned by the creation function. |
value | Every 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()
Parameter | Description |
---|---|
hm | In 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)
Parameter | Description |
---|---|
hm | In the C version, the address of the heightmap struct returned by the creation function. |
min,max | Every 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)
Parameter | Description |
---|---|
source | Each 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. |
dest | In 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)
Parameter | Description |
---|---|
hm | In the C version, the address of the heightmap struct returned by the creation function. |
min,max | The 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)
Parameter | Description |
---|---|
a | First heightmap in the lerp operation. |
b | Second heightmap in the lerp operation. |
coef | lerp coefficient. For each cell in the destination map (this for C++), value = a.value + (b.value - a.value) * coef |
res | In 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)
Parameter | Description |
---|---|
a | First heightmap. |
b | Second heightmap. For each cell in the destination map (this for C++), value = a.value + b.value |
res | In 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)
Parameter | Description |
---|---|
a | First heightmap. |
b | Second heightmap. For each cell in the destination map (this for C++), value = a.value * b.value |
res | In the C and python versions, the address of the destination heightmap. |