Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Heightmap.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_HEIGHTMAP_H
22#define GF_HEIGHTMAP_H
23
24#include <tuple>
25
26#include "Array2D.h"
27#include "ColorRamp.h"
28#include "CoreApi.h"
29#include "Image.h"
30#include "Noise.h"
31#include "Rect.h"
32
33namespace gf {
34#ifndef DOXYGEN_SHOULD_SKIP_THIS
35inline namespace v1 {
36#endif
37
44 class GF_CORE_API Heightmap {
45 public:
49 Heightmap() = default;
50
57
63 Vector2i getSize() const {
64 return m_data.getSize();
65 }
66
72 void reset();
73
80 double getValue(Vector2i position) const {
81 return m_data(position);
82 }
83
90 void setValue(Vector2i position, double value) {
91 m_data(position) = value;
92 }
93
99 std::tuple<double, double> getMinMax() const;
100
112 void normalize(double min = 0.0, double max = 1.0);
113
121 void addHill(Vector2d center, double radius, double height);
122
130 void digHill(Vector2d center, double radius, double height);
131
138 void addNoise(Noise2D& noise, double scale = 1.0);
139
145 void addValue(double value);
146
152 void scale(double value);
153
161 void clamp(double min = 0.0, double max = 1.0);
162
182 double getSlope(Vector2i position) const;
183
191 void thermalErosion(unsigned iterations, double talus, double fraction);
192
202 void hydraulicErosion(unsigned iterations, double rainAmount, double solubility, double evaporation, double capacity);
203
211 void fastErosion(unsigned iterations, double talus, double fraction);
212
220 double getErosionScore() const;
221
229 enum class Render {
230 Colored,
231 Shaded,
232 };
233
244 Heightmap subMap(RectI area) const;
245
256
273 Image copyToColoredImage(const ColorRampD& ramp, double waterLevel = 0.5, Render render = Render::Colored) const;
274
279 private:
281 };
282
283#ifndef DOXYGEN_SHOULD_SKIP_THIS
284}
285#endif
286}
287
288#endif // GF_HEIGHTMAP_H
A heightmap.
Definition: Heightmap.h:44
void reset()
Reset the heightmap.
void digHill(Vector2d center, double radius, double height)
Dig a hill in the heightmap.
Heightmap()=default
Default constructor.
void clamp(double min=0.0, double max=1.0)
Clamp the values of the heightmap.
void hydraulicErosion(unsigned iterations, double rainAmount, double solubility, double evaporation, double capacity)
Apply hydraulic erosision to the heightmap.
double getSlope(Vector2i position) const
Compute the slope at a position.
void addHill(Vector2d center, double radius, double height)
Add a hill to the heightmap.
Image copyToColoredImage(const ColorRampD &ramp, double waterLevel=0.5, Render render=Render::Colored) const
Export to a colored image.
void setValue(Vector2i position, double value)
Set the value at the specified position.
Definition: Heightmap.h:90
Image copyToGrayscaleImage() const
Export to a grayscale image.
void addValue(double value)
Add a constant to the heightmap.
Heightmap subMap(RectI area) const
Get a sub-map of the heightmap.
void thermalErosion(unsigned iterations, double talus, double fraction)
Apply thermal erosion to the heightmap.
std::tuple< double, double > getMinMax() const
Get the minimum and maximum of the heightmap.
void addNoise(Noise2D &noise, double scale=1.0)
Add a noise to the heightmap.
Heightmap(Vector2i size)
Constructor.
void scale(double value)
Scale the values of the heightmap.
void fastErosion(unsigned iterations, double talus, double fraction)
Apply fast erosion to the heightmap.
Render
Rendering mode.
Definition: Heightmap.h:229
void normalize(double min=0.0, double max=1.0)
Normalize the heightmap.
double getValue(Vector2i position) const
Get the value at the specified position.
Definition: Heightmap.h:80
double getErosionScore() const
Compute the erosion score for the heightmap.
Vector2i getSize() const
Get the size of the heightmap.
Definition: Heightmap.h:63
Class for loading, manipulating and saving images.
Definition: Image.h:81
2D A noise function
Definition: Noise.h:35
GF_CORE_API void scale(Matrix3f &mat, Vector2f factor)
Combine the current transform with a scaling.
The namespace for gf classes.
A color ramp.
Definition: ColorRamp.h:49