Mercator
0.4.0
|
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>
Public Types | |
typedef std::map< int, Surface * > | Surfacestore |
STL map of pointers to Surface objects. | |
typedef std::multimap< int, const Area * > | Areastore |
STL multimap of pointers to Area objects affecting this segment. | |
Public Member Functions | |
Segment (int x, int z, unsigned 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. | |
int | getSize () const |
Accessor for array size of this segment. | |
int | getXRef () const |
Accessor for Global x reference of this segment. | |
int | getZRef () const |
Accessor for Global y reference of this segment. | |
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. | |
Matrix< 2, 2, BasePoint > & | getControlPoints () |
Accessor for modifying 2D matrix of base points. | |
const Surfacestore & | getSurfaces () const |
Accessor for list of attached Surface objects. | |
Surfacestore & | getSurfaces () |
Accessor for modifying list of attached Surface objects. | |
const float * | getPoints () const |
Accessor for buffer containing height points. | |
float * | getPoints () |
Accessor for write access to buffer containing height points. | |
const HeightMap & | getHeightMap () const |
Accessor for height map. | |
HeightMap & | getHeightMap () |
Accessor for write access to height map. | |
const float * | getNormals () const |
Accessor for buffer containing surface normals. | |
float * | getNormals () |
Accessor for write access to buffer containing surface normals. | |
float | get (int x, int z) const |
Get the height at a relative integer position in the Segment. | |
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. | |
float | getMin () const |
Accessor for the minimum height value in this Segment. | |
WFMath::AxisBox< 2 > | getRect () const |
The 2d area covered by this segment. | |
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. | |
const std::map< long, const TerrainMod * > & | getMods () const |
int | addArea (const Area *a) |
Add an area to those that affect this segment. More... | |
int | updateArea (const Area *a) |
int | removeArea (const Area *a) |
Remove an area from those that affect this segment. | |
Class storing heightfield and other data for a single fixed size square area of terrain defined by four adjacent BasePoint objects.
|
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.
Mercator::Segment::~Segment | ( | ) |
int Mercator::Segment::addArea | ( | const Area * | ar | ) |
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.
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. |
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).
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.
|
inline |
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.
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.
void Mercator::Segment::populateSurfaces | ( | ) |
Populate the surfaces associated with this Segment.
Call Surface::populate() for each Surface in turn.
|
inline |