libtcod
Loading...
Searching...
No Matches
heightmap.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_HEIGHTMAP_H_
36#define TCOD_HEIGHTMAP_H_
37
38#include "mersenne_types.h"
39#include "noise.h"
40#include "portability.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45typedef struct {
46 int w, h;
47 float* __restrict values;
49
50TCODLIB_API TCOD_heightmap_t* TCOD_heightmap_new(int w, int h);
51TCODLIB_API void TCOD_heightmap_delete(TCOD_heightmap_t* hm);
52
53TCODLIB_API float TCOD_heightmap_get_value(const TCOD_heightmap_t* hm, int x, int y);
54TCODLIB_API float TCOD_heightmap_get_interpolated_value(const TCOD_heightmap_t* hm, float x, float y);
55TCODLIB_API void TCOD_heightmap_set_value(TCOD_heightmap_t* hm, int x, int y, float value);
56TCODLIB_API float TCOD_heightmap_get_slope(const TCOD_heightmap_t* hm, int x, int y);
57TCODLIB_API void TCOD_heightmap_get_normal(const TCOD_heightmap_t* hm, float x, float y, float n[3], float waterLevel);
58TCODLIB_API int TCOD_heightmap_count_cells(const TCOD_heightmap_t* hm, float min, float max);
59TCODLIB_API bool TCOD_heightmap_has_land_on_border(const TCOD_heightmap_t* hm, float waterLevel);
60TCODLIB_API void TCOD_heightmap_get_minmax(const TCOD_heightmap_t* hm, float* min, float* max);
61
62TCODLIB_API void TCOD_heightmap_copy(const TCOD_heightmap_t* hm_source, TCOD_heightmap_t* hm_dest);
63TCODLIB_API void TCOD_heightmap_add(TCOD_heightmap_t* hm, float value);
64TCODLIB_API void TCOD_heightmap_scale(TCOD_heightmap_t* hm, float value);
65TCODLIB_API void TCOD_heightmap_clamp(TCOD_heightmap_t* hm, float min, float max);
66TCODLIB_API void TCOD_heightmap_normalize(TCOD_heightmap_t* hm, float min, float max);
67TCODLIB_API void TCOD_heightmap_clear(TCOD_heightmap_t* hm);
68TCODLIB_API void TCOD_heightmap_lerp_hm(
69 const TCOD_heightmap_t* hm1, const TCOD_heightmap_t* hm2, TCOD_heightmap_t* out, float coef);
70TCODLIB_API void TCOD_heightmap_add_hm(const TCOD_heightmap_t* hm1, const TCOD_heightmap_t* hm2, TCOD_heightmap_t* out);
71TCODLIB_API void TCOD_heightmap_multiply_hm(
72 const TCOD_heightmap_t* hm1, const TCOD_heightmap_t* hm2, TCOD_heightmap_t* out);
73
74TCODLIB_API void TCOD_heightmap_add_hill(TCOD_heightmap_t* hm, float hx, float hy, float h_radius, float h_height);
75TCODLIB_API void TCOD_heightmap_dig_hill(TCOD_heightmap_t* hm, float hx, float hy, float h_radius, float h_height);
76TCODLIB_API void TCOD_heightmap_dig_bezier(
77 TCOD_heightmap_t* hm, int px[4], int py[4], float startRadius, float startDepth, float endRadius, float endDepth);
78TCODLIB_API void TCOD_heightmap_rain_erosion(
79 TCOD_heightmap_t* hm, int nbDrops, float erosionCoef, float sedimentationCoef, TCOD_Random* rnd);
80/* TCODLIB_API void TCOD_heightmap_heat_erosion(TCOD_heightmap_t *hm, int nbPass,float minSlope,float erosionCoef,float
81 * sedimentationCoef,TCOD_Random* rnd); */
82TCODLIB_API void TCOD_heightmap_kernel_transform(
84 int kernel_size,
85 const int* dx,
86 const int* dy,
87 const float* weight,
88 float minLevel,
89 float maxLevel);
90TCODLIB_API void TCOD_heightmap_add_voronoi(
91 TCOD_heightmap_t* hm, int nbPoints, int nbCoef, const float* coef, TCOD_Random* rnd);
92TCODLIB_API void TCOD_heightmap_mid_point_displacement(TCOD_heightmap_t* hm, TCOD_Random* rnd, float roughness);
93TCODLIB_API void TCOD_heightmap_add_fbm(
95 TCOD_noise_t noise,
96 float mul_x,
97 float mul_y,
98 float add_x,
99 float add_y,
100 float octaves,
101 float delta,
102 float scale);
103TCODLIB_API void TCOD_heightmap_scale_fbm(
105 TCOD_noise_t noise,
106 float mul_x,
107 float mul_y,
108 float add_x,
109 float add_y,
110 float octaves,
111 float delta,
112 float scale);
113TCOD_DEPRECATED("This function does nothing and will be removed.")
114TCODLIB_API void TCOD_heightmap_islandify(TCOD_heightmap_t* hm, float seaLevel, TCOD_Random* rnd);
115#ifdef __cplusplus
116}
117#endif
118#endif // TCOD_HEIGHTMAP_H_
Random number generator types.
Texture noise generator module.
Miscellaneous tools needed across platforms.
Definition heightmap.h:45
Pseudorandom number generator toolkit, all attributes are private.
Definition mersenne_types.h:87