mercator 0.4.0
A terrain generation library for the Worldforge system.
HeightMap.h
1// This file may be redistributed and modified only under the terms of
2// the GNU General Public License (See COPYING for details).
3// Copyright (C) 2003 Alistair Riddoch, Damien McGinnes
4
5#ifndef MERCATOR_HEIGHTMAP_H
6#define MERCATOR_HEIGHTMAP_H
7
8#include "BasePoint.h"
9#include "Buffer.h"
10
11#include <wfmath/vector.h>
12
13namespace WFMath {
14class MTRand;
15}
16
17namespace Mercator {
18
21class HeightMap : public Buffer<float> {
22 private:
24 const int m_res;
26 float m_max;
28 float m_min;
29
30 public:
31 explicit HeightMap(int resolution);
32 ~HeightMap() override = default;
33
35 int getResolution() const {
36 return m_res;
37 }
38
40 float get(int x, int z) const {
41 return m_data[z * (m_res + 1) + x];
42 }
43
44 void getHeightAndNormal(float x, float z, float &h,
45 WFMath::Vector<3> &normal) const;
46 void getHeight(float x, float z, float &h) const;
47
49 float getMax() const { return m_max; }
51 float getMin() const { return m_min; }
52
53 void fill2d(const BasePoint& p1, const BasePoint& p2,
54 const BasePoint& p3, const BasePoint& p4);
55
56 void checkMaxMin(float h);
57
58 private:
59
60 void fill1d(const BasePoint& l, const BasePoint &h, float *array) const;
61
62 float qRMD(WFMath::MTRand& rng, float nn, float fn, float ff, float nf,
63 float roughness, float falloff, float depth) const;
64
65};
66
67
68} // namespace Mercator
69
70#endif // MERCATOR_HEIGHTMAP_H
Point on the fundamental grid that is used as the basis for terrain.
Definition: BasePoint.h:19
Template for managing buffers of data for a segment.
Definition: Buffer.h:14
std::vector< float > m_data
Pointer to buffer containing data values.
Definition: Buffer.h:21
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: HeightMap.h:21
void fill2d(const BasePoint &p1, const BasePoint &p2, const BasePoint &p3, const BasePoint &p4)
Two dimensional midpoint displacement fractal.
Definition: HeightMap.cpp:201
float getMin() const
Accessor for the minimum height value in this Segment.
Definition: HeightMap.h:51
void checkMaxMin(float h)
Check a value against m_min and m_max and set one of them if appropriate.
Definition: HeightMap.cpp:117
void getHeightAndNormal(float x, float z, float &h, WFMath::Vector< 3 > &normal) const
Get an accurate height and normal vector at a given coordinate relative to this segment.
Definition: HeightMap.cpp:380
float get(int x, int z) const
Get the height at a relative integer position in the Segment.
Definition: HeightMap.h:40
float getMax() const
Accessor for the maximum height value in this Segment.
Definition: HeightMap.h:49
int getResolution() const
Accessor for resolution of this segment.
Definition: HeightMap.h:35
HeightMap(int resolution)
Construct an empty height map with the given resolution.
Definition: HeightMap.cpp:104