mercator
0.4.0
A terrain generation library for the Worldforge system.
|
Class storing heightfield and other data for a single fixed size square area of terrain defined by four adjacent BasePoint objects. More...
#include <Segment.h>
Classes | |
struct | AreaEntry |
Public Types | |
typedef std::map< int, std::unique_ptr< Surface > > | Surfacestore |
STL map of pointers to Surface objects. More... | |
typedef std::multimap< int, AreaEntry > | Areastore |
STL multimap of pointers to Area objects affecting this segment. More... | |
Public Member Functions | |
Segment (int x, int z, int resolution) | |
Construct an empty segment with the given resolution. More... | |
~Segment () | |
Destruct the Segment. More... | |
int | getResolution () const |
Accessor for resolution of this segment. More... | |
int | getSize () const |
Accessor for array size of this segment. More... | |
int | getXRef () const |
Accessor for Global x reference of this segment. More... | |
int | getZRef () const |
Accessor for Global y reference of this segment. More... | |
bool | isValid () const |
Check whether this Segment contains valid point data. More... | |
void | invalidate (bool points=true) |
Mark the contents of this Segment as stale. More... | |
void | setCornerPoint (unsigned int x, unsigned int z, const BasePoint &bp) |
Set the BasePoint data for one of the four that define this Segment. More... | |
const Matrix< 2, 2, BasePoint > & | getControlPoints () const |
Accessor for 2D matrix of base points. More... | |
Matrix< 2, 2, BasePoint > & | getControlPoints () |
Accessor for modifying 2D matrix of base points. More... | |
const Surfacestore & | getSurfaces () const |
Accessor for list of attached Surface objects. More... | |
Surfacestore & | getSurfaces () |
Accessor for modifying list of attached Surface objects. More... | |
const float * | getPoints () const |
Accessor for buffer containing height points. More... | |
float * | getPoints () |
Accessor for write access to buffer containing height points. More... | |
const HeightMap & | getHeightMap () const |
Accessor for height map. More... | |
HeightMap & | getHeightMap () |
Accessor for write access to height map. More... | |
const float * | getNormals () const |
Accessor for buffer containing surface normals. More... | |
float * | getNormals () |
Accessor for write access to buffer containing surface normals. More... | |
float | get (int x, int z) const |
Get the height at a relative integer position in the Segment. More... | |
void | getHeight (float x, float y, float &h) const |
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. More... | |
bool | clipToSegment (const WFMath::AxisBox< 2 > &bbox, int &lx, int &hx, int &lz, int &hz) const |
Determine the intersection between an axis aligned box and this segment. More... | |
void | populate () |
Populate the Segment with heightfield data. More... | |
void | populateNormals () |
Populate the Segment with surface normal data. More... | |
void | populateSurfaces () |
Populate the surfaces associated with this Segment. More... | |
void | populateHeightMap (HeightMap &heightMap) |
float | getMax () const |
Accessor for the maximum height value in this Segment. More... | |
float | getMin () const |
Accessor for the minimum height value in this Segment. More... | |
WFMath::AxisBox< 2 > | getRect () const |
The 2d area covered by this segment. More... | |
void | updateMod (long id, const TerrainMod *t) |
void | clearMods () |
Delete all the modifications applied to this Segment. More... | |
const Areastore & | getAreas () const |
Accessor for multimap of Area objects. More... | |
const std::map< long, const TerrainMod * > & | getMods () const |
void | updateArea (long id, const Area *area, const Shader *shader) |
Class storing heightfield and other data for a single fixed size square area of terrain defined by four adjacent BasePoint objects.
typedef std::multimap<int, AreaEntry> Mercator::Segment::Areastore |
typedef std::map<int, std::unique_ptr<Surface> > Mercator::Segment::Surfacestore |
|
explicit |
Construct an empty segment with the given resolution.
Generally it is not necessary to call this from outside the Mercator library Segment objects are created as required. The Segment is constructed without allocating any storage for heightfield or surface normal data. The m_min and m_max members are initialised to extreme values, and should be set to appropriate using setMinMax() as soon as possible after construction. Similarly the control points should be set soon after construction.
Definition at line 37 of file Segment.cpp.
Mercator::Segment::~Segment | ( | ) |
Destruct the Segment.
Generally it is not necessary to delete Segment objects from application code, as Segment instances are owned by the Terrain object. Storage allocated for heightfield and surface normals is implicitly deleted as well as all surfaces.
Definition at line 50 of file Segment.cpp.
References clearMods().
void Mercator::Segment::clearMods | ( | ) |
Delete all the modifications applied to this Segment.
Usually called from the destructor. It is not normally necessary to call this function from the application.
Definition at line 274 of file Segment.cpp.
References Mercator::TerrainMod::apply(), Mercator::Effector::bbox(), Mercator::HeightMap::checkMaxMin(), clipToSegment(), Mercator::Buffer< DataType >::getData(), Mercator::Area::getLayer(), invalidate(), and Mercator::Shader::newSurface().
Referenced by ~Segment().
bool Mercator::Segment::clipToSegment | ( | const WFMath::AxisBox< 2 > & | bbox, |
int & | lx, | ||
int & | hx, | ||
int & | lz, | ||
int & | hz | ||
) | const |
Determine the intersection between an axis aligned box and this segment.
bbox | axis aligned box to be tested. |
lx | lower x coordinate of intersection area. |
hx | upper x coordinate of intersection area. |
lz | lower z coordinate of intersection area. |
hz | upper z coordinate of intersection area. |
Definition at line 238 of file Segment.cpp.
References invalidate().
Referenced by clearMods().
|
inline |
Get the height at a relative integer position in the Segment.
Definition at line 173 of file Segment.h.
References Mercator::HeightMap::get().
Referenced by Mercator::Terrain::get(), and Mercator::GrassShader::shade().
|
inline |
Accessor for multimap of Area objects.
Definition at line 201 of file Segment.h.
Referenced by Mercator::AreaShader::checkIntersect(), and Mercator::AreaShader::shade().
void Mercator::Segment::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.
The height and surface normal are determined by finding the four adjacent height points nearest to the coordinate, and interpolating between those height values. The square area defined by the 4 height points is considered as two triangles for the purposes of interpolation to ensure that the calculated height falls on the surface rendered by a 3D graphics engine from the same heightfield data. The line used to divide the area is defined by the gradient y = x, so the first triangle has relative vertex coordinates (0,0) (1,0) (1,1) and the second triangle has vertex coordinates (0,0) (0,1) (1,1).
Definition at line 223 of file Segment.cpp.
References Mercator::HeightMap::getHeightAndNormal().
Referenced by Mercator::Terrain::getHeightAndNormal().
|
inline |
|
inline |
|
inline |
Accessor for the maximum height value in this Segment.
Definition at line 189 of file Segment.h.
References Mercator::HeightMap::getMax().
Referenced by Mercator::HighShader::checkIntersect(), Mercator::BandShader::checkIntersect(), and Mercator::GrassShader::checkIntersect().
|
inline |
Accessor for the minimum height value in this Segment.
Definition at line 191 of file Segment.h.
References Mercator::HeightMap::getMin().
Referenced by Mercator::DepthShader::checkIntersect(), Mercator::LowShader::checkIntersect(), Mercator::BandShader::checkIntersect(), and Mercator::GrassShader::checkIntersect().
|
inline |
|
inline |
|
inline |
Accessor for buffer containing height points.
Definition at line 143 of file Segment.h.
References Mercator::Buffer< DataType >::getData().
Referenced by Mercator::HighShader::shade(), Mercator::DepthShader::shade(), Mercator::LowShader::shade(), Mercator::BandShader::shade(), and Mercator::GrassShader::shade().
|
inline |
Accessor for write access to buffer containing height points.
Definition at line 148 of file Segment.h.
References Mercator::Buffer< DataType >::getData().
WFMath::AxisBox< 2 > Mercator::Segment::getRect | ( | ) | const |
The 2d area covered by this segment.
Definition at line 337 of file Segment.cpp.
Referenced by Mercator::Area::checkIntersects(), Mercator::Area::clipToSegment(), Mercator::AreaShader::shade(), and Mercator::ShapeTerrainMod< Shape >::ShapeTerrainMod().
|
inline |
Accessor for resolution of this segment.
Definition at line 83 of file Segment.h.
Referenced by Mercator::GrassShader::shade().
|
inline |
Accessor for array size of this segment.
Definition at line 88 of file Segment.h.
Referenced by Mercator::AreaShader::shade(), Mercator::FillShader::shade(), Mercator::HighShader::shade(), Mercator::DepthShader::shade(), Mercator::LowShader::shade(), Mercator::BandShader::shade(), and Mercator::GrassShader::shade().
|
inline |
Accessor for list of attached Surface objects.
Definition at line 133 of file Segment.h.
Referenced by Mercator::Terrain::removeShader().
|
inline |
|
inline |
Accessor for Global x reference of this segment.
Definition at line 93 of file Segment.h.
Referenced by Mercator::Terrain::get(), Mercator::Terrain::getHeight(), and Mercator::Terrain::getHeightAndNormal().
|
inline |
Accessor for Global y reference of this segment.
Definition at line 98 of file Segment.h.
Referenced by Mercator::Terrain::get(), Mercator::Terrain::getHeight(), and Mercator::Terrain::getHeightAndNormal().
void Mercator::Segment::invalidate | ( | bool | points = true | ) |
Mark the contents of this Segment as stale.
This is called internally whenever changes occur that mean that the heightfield and surface normal data are no longer valid. If surface normal storage is deallocated, and if the points argument is true the heightfield storage is also deallocated.
Definition at line 83 of file Segment.cpp.
References Mercator::Buffer< DataType >::invalidate().
Referenced by clearMods(), and clipToSegment().
|
inline |
Check whether this Segment contains valid point data.
Definition at line 105 of file Segment.h.
References Mercator::Buffer< DataType >::isValid().
Referenced by Mercator::Terrain::get(), Mercator::Terrain::getHeight(), and Mercator::Terrain::getHeightAndNormal().
void Mercator::Segment::populate | ( | ) |
Populate the Segment with heightfield data.
Storage for the heightfield data is allocated if necessary, the qRMD algorithm is used to calculate the heightfield data, and required modifications are applied.
Definition at line 60 of file Segment.cpp.
References Mercator::Buffer< DataType >::allocate(), and Mercator::HeightMap::fill2d().
void Mercator::Segment::populateNormals | ( | ) |
Populate the Segment with surface normal data.
Storage for the normals is allocated if necessary, and the average normal at each heightpoint is calculated. The middle normals are calculated first, followed by the boundaries which are done in 2 dimensions to ensure that there is no visible seam between segments.
Definition at line 111 of file Segment.cpp.
References Mercator::HeightMap::get(), and Mercator::Buffer< DataType >::isValid().
void Mercator::Segment::populateSurfaces | ( | ) |
Populate the surfaces associated with this Segment.
Call Surface::populate() for each Surface in turn.
Definition at line 197 of file Segment.cpp.
Referenced by Mercator::Terrain::removeShader().
|
inline |