libtcod
Loading...
Searching...
No Matches
Heightmaps (C)

Classes

struct  TCOD_heightmap_t
 A contigious 2D array of float values. More...
 

Functions

static bool TCOD_heightmap_is_valid (const TCOD_heightmap_t *heightmap)
 Return true if heightmap is valid.
 
static bool TCOD_heightmap_in_bounds (const TCOD_heightmap_t *heightmap, int x, int y)
 Return true if x,y are valid and accessible coordinates for this heightmap
 
static float TCOD_heightmap_get_value (const TCOD_heightmap_t *heightmap, int x, int y)
 Return the value at x,y from heightmap, or 0.0 for out-of-bounds coordinates.
 
static void TCOD_heightmap_set_value (TCOD_heightmap_t *heightmap, int x, int y, float value)
 Set x,y on heightmap to value, out-of-bounds coordinates are silently ignored.
 
TCOD_heightmap_tTCOD_heightmap_new (int w, int h)
 
void TCOD_heightmap_delete (TCOD_heightmap_t *hm)
 
float TCOD_heightmap_get_interpolated_value (const TCOD_heightmap_t *hm, float x, float y)
 
float TCOD_heightmap_get_slope (const TCOD_heightmap_t *hm, int x, int y)
 
void TCOD_heightmap_get_normal (const TCOD_heightmap_t *hm, float x, float y, float n[3], float waterLevel)
 
int TCOD_heightmap_count_cells (const TCOD_heightmap_t *hm, float min, float max)
 
bool TCOD_heightmap_has_land_on_border (const TCOD_heightmap_t *hm, float waterLevel)
 
void TCOD_heightmap_get_minmax (const TCOD_heightmap_t *heightmap, float *min_out, float *max_out)
 Output the highest and lowest values in heightmap to min and max
 
void TCOD_heightmap_copy (const TCOD_heightmap_t *hm_source, TCOD_heightmap_t *hm_dest)
 
void TCOD_heightmap_add (TCOD_heightmap_t *hm, float value)
 
void TCOD_heightmap_scale (TCOD_heightmap_t *hm, float value)
 
void TCOD_heightmap_clamp (TCOD_heightmap_t *hm, float min, float max)
 
void TCOD_heightmap_normalize (TCOD_heightmap_t *hm, float min, float max)
 
void TCOD_heightmap_clear (TCOD_heightmap_t *hm)
 
void TCOD_heightmap_lerp_hm (const TCOD_heightmap_t *hm1, const TCOD_heightmap_t *hm2, TCOD_heightmap_t *out, float coef)
 
void TCOD_heightmap_add_hm (const TCOD_heightmap_t *hm1, const TCOD_heightmap_t *hm2, TCOD_heightmap_t *out)
 
void TCOD_heightmap_multiply_hm (const TCOD_heightmap_t *hm1, const TCOD_heightmap_t *hm2, TCOD_heightmap_t *out)
 
void TCOD_heightmap_add_hill (TCOD_heightmap_t *hm, float hx, float hy, float h_radius, float h_height)
 
void TCOD_heightmap_dig_hill (TCOD_heightmap_t *hm, float hx, float hy, float h_radius, float h_height)
 
void TCOD_heightmap_dig_bezier (TCOD_heightmap_t *hm, int px[4], int py[4], float startRadius, float startDepth, float endRadius, float endDepth)
 
void TCOD_heightmap_rain_erosion (TCOD_heightmap_t *hm, int nbDrops, float erosionCoef, float sedimentationCoef, TCOD_Random *rnd)
 
void TCOD_heightmap_kernel_transform (TCOD_heightmap_t *hm, int kernel_size, const int *dx, const int *dy, const float *weight, float minLevel, float maxLevel)
 
void TCOD_heightmap_threshold_mask (const TCOD_heightmap_t *hm, uint8_t *mask, float minLevel, float maxLevel)
 Generate a mask from heightmap values within a threshold range.
 
void TCOD_heightmap_kernel_transform_out (const TCOD_heightmap_t *hm_src, TCOD_heightmap_t *hm_dst, int kernel_size, const int *dx, const int *dy, const float *weight, const uint8_t *mask)
 Apply a sparse kernel convolution from source to destination heightmap.
 
void TCOD_heightmap_add_voronoi (TCOD_heightmap_t *hm, int nbPoints, int nbCoef, const float *coef, TCOD_Random *rnd)
 
void TCOD_heightmap_mid_point_displacement (TCOD_heightmap_t *hm, TCOD_Random *rnd, float roughness)
 
void TCOD_heightmap_add_fbm (TCOD_heightmap_t *hm, TCOD_Noise *noise, float mul_x, float mul_y, float add_x, float add_y, float octaves, float delta, float scale)
 
void TCOD_heightmap_scale_fbm (TCOD_heightmap_t *hm, TCOD_Noise *noise, float mul_x, float mul_y, float add_x, float add_y, float octaves, float delta, float scale)
 
void TCOD_heightmap_islandify (TCOD_heightmap_t *hm, float seaLevel, TCOD_Random *rnd)
 

Detailed Description

Function Documentation

◆ TCOD_heightmap_get_minmax()

void TCOD_heightmap_get_minmax ( const TCOD_heightmap_t * heightmap,
float * min_out,
float * max_out )

Output the highest and lowest values in heightmap to min and max

Parameters
heightmapInput heightmap, can be NULL
min_outThe lowest value in heightmap or FLT_MAX if heightmap has no values, can be NULL
max_outThe highest value in heightmap or -FLT_MAX if heightmap has no values, can be NULL

◆ TCOD_heightmap_get_value()

static float TCOD_heightmap_get_value ( const TCOD_heightmap_t * heightmap,
int x,
int y )
inlinestatic

Return the value at x,y from heightmap, or 0.0 for out-of-bounds coordinates.

Parameters
heightmapCan be NULL
xX coordinate in range: 0 <= x < heightmap->w
yY coordinate in range: 0 <= y < heightmap->h
Returns
Value at heightmap->values[y * heightmap->w + x], out-of-bounds coordinates return 0.0

◆ TCOD_heightmap_in_bounds()

static bool TCOD_heightmap_in_bounds ( const TCOD_heightmap_t * heightmap,
int x,
int y )
inlinestatic

Return true if x,y are valid and accessible coordinates for this heightmap

Parameters
heightmapPointer to heightmap to access, NULL or invalid heightmaps are always out-of-bounds
xX coordinate in range: 0 <= x < heightmap->w
yY coordinate in range: 0 <= y < heightmap->h
Returns
true if the coordinates at x,y are safe to access

◆ TCOD_heightmap_is_valid()

static bool TCOD_heightmap_is_valid ( const TCOD_heightmap_t * heightmap)
inlinestatic

Return true if heightmap is valid.

Parameters
heightmapCan be NULL

Valid heightmaps are non-NULL and never have negative shapes

◆ TCOD_heightmap_kernel_transform_out()

void TCOD_heightmap_kernel_transform_out ( const TCOD_heightmap_t * hm_src,
TCOD_heightmap_t * hm_dst,
int kernel_size,
const int * dx,
const int * dy,
const float * weight,
const uint8_t * mask )

Apply a sparse kernel convolution from source to destination heightmap.

This function reads from the source heightmap and writes results to a separate destination heightmap. This avoids the need for an internal copy when the caller already has separate source and destination buffers.

The kernel is defined by parallel arrays of x-offsets, y-offsets, and weights. For each cell, the weighted sum of neighboring values (as defined by the kernel) is computed and normalized by the total weight of in-bounds neighbors.

If mask is non-NULL, only cells with non-zero mask values are transformed; cells with zero mask values are unmodified by the transformation. If mask is NULL, all cells are transformed.

Parameters
hm_srcSource heightmap (read-only). Must not alias hm_dst.
hm_dstDestination heightmap (must be same size as source). Must not alias hm_src.
kernel_sizeNumber of elements in the kernel arrays.
dxArray of x-offsets for kernel positions.
dyArray of y-offsets for kernel positions.
weightArray of weights for each kernel position.
maskOptional mask array (hm->w * hm->h bytes, row-major). NULL transforms all cells.
embed:rst:leading-asterisk
 .. versionadded:: Unreleased

◆ TCOD_heightmap_set_value()

static void TCOD_heightmap_set_value ( TCOD_heightmap_t * heightmap,
int x,
int y,
float value )
inlinestatic

Set x,y on heightmap to value, out-of-bounds coordinates are silently ignored.

Parameters
heightmapCan be NULL
xX coordinate in range: 0 <= x < heightmap->w
yY coordinate in range: 0 <= y < heightmap->h
valueValue to write to heightmap->values[y * heightmap->w + x] if within bounds

◆ TCOD_heightmap_threshold_mask()

void TCOD_heightmap_threshold_mask ( const TCOD_heightmap_t * hm,
uint8_t * mask,
float minLevel,
float maxLevel )

Generate a mask from heightmap values within a threshold range.

Sets mask values to 1 where heightmap values are in [minLevel, maxLevel], and 0 elsewhere. The mask array must be allocated by the caller with size (hm->w * hm->h) bytes, stored in row-major order.

Parameters
hmSource heightmap to threshold.
maskDestination mask array (must be hm->w * hm->h bytes, row-major).
minLevelMinimum value (inclusive) for cells to be marked.
maxLevelMaximum value (inclusive) for cells to be marked.
embed:rst:leading-asterisk
 .. versionadded:: Unreleased