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 <HeightMap.h>
Public Member Functions | |
HeightMap (unsigned int resolution) | |
Construct an empty height map with the given resolution. | |
int | getResolution () const |
Accessor for resolution of this segment. | |
float | get (int x, int z) const |
Get the height at a relative integer position in the Segment. | |
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... | |
void | getHeight (float x, float z, float &h) const |
float | getMax () const |
Accessor for the maximum height value in this Segment. | |
float | getMin () const |
Accessor for the minimum height value in this Segment. | |
void | fill2d (const BasePoint &p1, const BasePoint &p2, const BasePoint &p3, const BasePoint &p4) |
Two dimensional midpoint displacement fractal. More... | |
void | checkMaxMin (float h) |
Check a value against m_min and m_max and set one of them if appropriate. More... | |
![]() | |
Buffer (unsigned int size, unsigned int channels) | |
Constructor. More... | |
float & | operator() (unsigned int x, unsigned int y, unsigned int channel) |
Retrieve the data value at a given point. More... | |
const float & | operator() (unsigned int x, unsigned int y, unsigned int channel) const |
Retrieve the data value at a given point. More... | |
unsigned int | getSize () const |
Accessor for the size of segment, m_res + 1. | |
unsigned int | getChannels () const |
Accessor for the number of data values per height point. | |
float * | getData () |
Accessor for a pointer to buffer containing data values. | |
const float * | getData () const |
Accessor for a pointer to buffer containing data values. | |
void | allocate () |
Allocate the storage required by the buffer. More... | |
bool | isValid () const |
Determine if this buffer has valid allocated storage. More... | |
void | invalidate () |
De-allocate the storage for this buffer. More... | |
Additional Inherited Members | |
![]() | |
const unsigned int | m_channels |
The number of data values per height point. | |
const unsigned int | m_size |
The size of segment, m_res + 1. | |
float * | m_data |
Pointer to buffer containing data values. | |
Class storing heightfield and other data for a single fixed size square area of terrain defined by four adjacent BasePoint objects.
void Mercator::HeightMap::checkMaxMin | ( | float | h | ) |
Check a value against m_min and m_max and set one of them if appropriate.
Called by internal functions whenever a new data point is generated.
void Mercator::HeightMap::fill2d | ( | const BasePoint & | p1, |
const BasePoint & | p2, | ||
const BasePoint & | p3, | ||
const BasePoint & | p4 | ||
) |
Two dimensional midpoint displacement fractal.
For a tile where edges are to be filled by 1d fractals. Size must be a power of 2, array is (size + 1) * (size + 1) with the corners the control points.
void Mercator::HeightMap::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 z = 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).