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));
Region of terrain surface which is modified.
Point on the fundamental grid that is used as the basis for terrain.
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Base class for Shader objects which create surface data for use when rendering terrain.
Base class for modifiers to the procedurally generated terrain.
Class storing centrally all data about an instance of some terrain.
bool getHeight(float x, float z, float &h) const
Get an accurate height at a given coordinate x,z.
float getSpacing() const
Accessor for base point spacing.
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 getBasePoint(int x, int z, BasePoint &y) const
Get the BasePoint at a given base point coordinate.
void processSegments(const WFMath::AxisBox< 2 > &area, const std::function< void(Segment &, int, int)> &func) const
void addShader(const Shader *t, int id)
Add a new Shader to the list for this terrain.
bool hasMod(long id) const
Checks if a mod with the supplied id has been registered with the terrain.
int getResolution() const
Accessor for base point resolution.
std::map< int, Segmentcolumn > Segmentstore
STL map to store sparse array of Segment pointer columns.
Rect updateMod(long id, std::unique_ptr< TerrainMod > mod)
Updates the terrain with a mod.
Segment * getSegmentAtPos(float x, float z) const
Get a pointer to the segment which contains the coord x,y.
void setBasePoint(int x, int y, float z)
Set the height of the basepoint at x,y to z.
std::map< int, Pointcolumn > Pointstore
STL map to store sparse array of BasePoint columns.
WFMath::AxisBox< 2 > Rect
Bounding box.
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.
void removeShader(const Shader *t, int id)
remove a Shader from the list for this terrain.
std::map< int, BasePoint > Pointcolumn
STL map to store sparse array of BasePoints.
int posToIndex(float pos) const
Converts the supplied position into a segment index.
float get(float x, float z) const
Get the height value at a given coordinate x,z.
std::map< int, std::unique_ptr< Segment > > Segmentcolumn
STL map to store sparse array of Segments.
Rect updateArea(long id, std::unique_ptr< Area > a)
Updates the terrain affected by an area.
~Terrain()
Destroy Terrain object, deleting contained objects.
std::map< int, const Shader * > Shaderstore
STL map to store sparse array of Shader pointers.
static const unsigned int DEFAULT
value provided for no flags set.
const Segmentstore & getTerrain() const
Accessor for 2D sparse array of Segment pointers.
Terrain(unsigned int options=DEFAULT, int resolution=defaultResolution)
Construct a new Terrain object with optional options and resolution.
const Shaderstore & getShaders() const
Accessor for list of Shader pointers.
void setBasePoint(int x, int z, const BasePoint &y)
Set the BasePoint value at a given base point coordinate.
static const unsigned int SHADED
set if shaders are going to be used on this terrain.
const Pointstore & getPoints() const
Accessor for 2D sparse array of BasePoint objects.