mercator
0.4.0
A terrain generation library for the Worldforge system.
|
5 #ifndef MERCATOR_TERRAIN_H
6 #define MERCATOR_TERRAIN_H
11 #include <wfmath/axisbox.h>
12 #include <wfmath/point.h>
40 typedef WFMath::AxisBox<2>
Rect;
56 static const unsigned int DEFAULT = 0x0000;
58 static const unsigned int SHADED = 0x0001;
63 const unsigned int m_options;
67 const float m_spacing;
76 struct TerrainModEntry {
80 std::unique_ptr<TerrainMod> terrainMod;
95 std::map<long, TerrainModEntry> m_terrainMods;
97 struct TerrainAreaEntry {
101 std::unique_ptr<Area> terrainArea;
112 std::map<long, TerrainAreaEntry> m_terrainAreas;
123 void addSurfaces(Segment &);
130 void shadeSurfaces(Segment &);
135 bool isShaded()
const {
149 int resolution = defaultResolution);
167 float get(
float x,
float z)
const;
184 bool getHeight(
float x,
float z,
float& h)
const;
302 bool hasMod(
long id)
const;
313 const Area* getArea(
long id)
const;
327 void processSegments(
const WFMath::AxisBox<2>& area,
const std::function<
void(
Segment&,
int,
int)>& func)
const;
331 return (
int)std::lround(std::floor(pos / m_spacing));
342 #endif // MERCATOR_TERRAIN_H
Class storing centrally all data about an instance of some terrain.
static const unsigned int DEFAULT
value provided for no flags set.
static constexpr float defaultLevel
Height value used when no data is available.
Segment * getSegmentAtIndex(int x, int z) const
Get the Segment at a given index.
const Segmentstore & getTerrain() const
Accessor for 2D sparse array of Segment pointers.
bool getHeightAndNormal(float x, float z, float &h, WFMath::Vector< 3 > &n) const
Get an accurate height and normal vector at a given coordinate x,z.
bool hasMod(long id) const
Checks if a mod with the supplied id has been registered with the terrain.
std::map< int, Pointcolumn > Pointstore
STL map to store sparse array of BasePoint columns.
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Rect updateArea(long id, std::unique_ptr< Area > a)
Updates the terrain affected by an area.
std::map< int, Segmentcolumn > Segmentstore
STL map to store sparse array of Segment pointer columns.
const Pointstore & getPoints() const
Accessor for 2D sparse array of BasePoint objects.
std::map< int, std::unique_ptr< Segment > > Segmentcolumn
STL map to store sparse array of Segments.
void setBasePoint(int x, int y, float z)
Set the height of the basepoint at x,y to z.
Rect updateMod(long id, std::unique_ptr< TerrainMod > mod)
Updates the terrain with a mod.
std::map< int, BasePoint > Pointcolumn
STL map to store sparse array of BasePoints.
bool getHeight(float x, float z, float &h) const
Get an accurate height at a given coordinate x,z.
bool getBasePoint(int x, int z, BasePoint &y) const
Get the BasePoint at a given base point coordinate.
void setBasePoint(int x, int z, const BasePoint &y)
Set the BasePoint value at a given base point coordinate.
Region of terrain surface which is modified.
float getSpacing() const
Accessor for base point spacing.
Point on the fundamental grid that is used as the basis for terrain.
std::map< int, const Shader * > Shaderstore
STL map to store sparse array of Shader pointers.
const Shaderstore & getShaders() const
Accessor for list of Shader pointers.
void processSegments(const WFMath::AxisBox< 2 > &area, const std::function< void(Segment &, int, int)> &func) const
Base class for Shader objects which create surface data for use when rendering terrain.
void removeShader(const Shader *t, int id)
remove a Shader from the list for this terrain.
Terrain(unsigned int options=DEFAULT, int resolution=defaultResolution)
Construct a new Terrain object with optional options and resolution.
Segment * getSegmentAtPos(float x, float z) const
Get a pointer to the segment which contains the coord x,y.
float get(float x, float z) const
Get the height value at a given coordinate x,z.
~Terrain()
Destroy Terrain object, deleting contained objects.
Base class for modifiers to the procedurally generated terrain.
int posToIndex(float pos) const
Converts the supplied position into a segment index.
WFMath::AxisBox< 2 > Rect
Bounding box.
static const unsigned int SHADED
set if shaders are going to be used on this terrain.
void addShader(const Shader *t, int id)
Add a new Shader to the list for this terrain.
int getResolution() const
Accessor for base point resolution.