mercator  0.4.0
A terrain generation library for the Worldforge system.
Mercator::HeightMap Class Reference

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>

Inheritance diagram for Mercator::HeightMap:
Collaboration diagram for Mercator::HeightMap:

Public Member Functions

 HeightMap (int resolution)
 Construct an empty height map with the given resolution. More...
 
int getResolution () const
 Accessor for resolution of this segment. More...
 
float get (int x, int z) const
 Get the height at a relative integer position in the Segment. More...
 
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. More...
 
float getMin () const
 Accessor for the minimum height value in this Segment. More...
 
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...
 
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. More...
 
unsigned int getChannels () const
 Accessor for the number of data values per height point. More...
 
float * getData ()
 Accessor for a pointer to buffer containing data values. More...
 
const float * getData () const
 Accessor for a pointer to buffer containing data values. More...
 
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...
 

Protected Attributes

const unsigned int m_channels
 The number of data values per height point. More...
 
const unsigned int m_size
 The size of segment, m_res + 1. More...
 
std::vector< float > m_data
 Pointer to buffer containing data values. More...
 

Detailed Description

Class storing heightfield and other data for a single fixed size square area of terrain defined by four adjacent BasePoint objects.

Definition at line 21 of file HeightMap.h.

Constructor & Destructor Documentation

Mercator::HeightMap::HeightMap ( int  resolution)
explicit

Construct an empty height map with the given resolution.

Definition at line 104 of file HeightMap.cpp.

Member Function Documentation

void Mercator::Buffer< float >::allocate ( )
inlineinherited

Allocate the storage required by the buffer.

Allocate memory based on the size and number of channels required by the buffer.

Definition at line 76 of file Buffer.h.

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.

Definition at line 117 of file HeightMap.cpp.

References Mercator::BasePoint::FALLOFF, Mercator::BasePoint::height(), Mercator::BasePoint::roughness(), and Mercator::BasePoint::seed().

Referenced by Mercator::Segment::clearMods(), and fill2d().

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.

Definition at line 201 of file HeightMap.cpp.

References Mercator::QuadInterp::calc(), checkMaxMin(), Mercator::BasePoint::falloff(), Mercator::Buffer< float >::m_data, Mercator::Buffer< float >::m_size, Mercator::BasePoint::roughness(), and Mercator::BasePoint::seed().

Referenced by Mercator::Segment::populate().

float Mercator::HeightMap::get ( int  x,
int  z 
) const
inline

Get the height at a relative integer position in the Segment.

Definition at line 40 of file HeightMap.h.

Referenced by Mercator::Segment::get(), and Mercator::Segment::populateNormals().

unsigned int Mercator::Buffer< float >::getChannels ( ) const
inlineinherited

Accessor for the number of data values per height point.

Definition at line 58 of file Buffer.h.

float * Mercator::Buffer< float >::getData ( )
inlineinherited

Accessor for a pointer to buffer containing data values.

Definition at line 63 of file Buffer.h.

const float * Mercator::Buffer< float >::getData ( ) const
inlineinherited

Accessor for a pointer to buffer containing data values.

Definition at line 68 of file Buffer.h.

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).

Definition at line 380 of file HeightMap.cpp.

Referenced by Mercator::Segment::getHeightAndNormal().

float Mercator::HeightMap::getMax ( ) const
inline

Accessor for the maximum height value in this Segment.

Definition at line 49 of file HeightMap.h.

Referenced by Mercator::Segment::getMax().

float Mercator::HeightMap::getMin ( ) const
inline

Accessor for the minimum height value in this Segment.

Definition at line 51 of file HeightMap.h.

Referenced by Mercator::Segment::getMin().

int Mercator::HeightMap::getResolution ( ) const
inline

Accessor for resolution of this segment.

Definition at line 35 of file HeightMap.h.

unsigned int Mercator::Buffer< float >::getSize ( ) const
inlineinherited

Accessor for the size of segment, m_res + 1.

Definition at line 53 of file Buffer.h.

void Mercator::Buffer< float >::invalidate ( )
inlineinherited

De-allocate the storage for this buffer.

Free the storage allocate for this buffer.

Definition at line 90 of file Buffer.h.

bool Mercator::Buffer< float >::isValid ( ) const
inlineinherited

Determine if this buffer has valid allocated storage.

Returns
true if storage is allocated.

Definition at line 83 of file Buffer.h.

float & Mercator::Buffer< float >::operator() ( unsigned int  x,
unsigned int  y,
unsigned int  channel 
)
inlineinherited

Retrieve the data value at a given point.

Access the data value associated with given point in the segment in a given channel in this buffer.

Returns
a reference to the value at the point requested.

Definition at line 36 of file Buffer.h.

const float & Mercator::Buffer< float >::operator() ( unsigned int  x,
unsigned int  y,
unsigned int  channel 
) const
inlineinherited

Retrieve the data value at a given point.

Return the data value associated with given point in the segment in a given channel in this buffer.

Returns
the value at the point requested.

Definition at line 45 of file Buffer.h.

Member Data Documentation

const unsigned int Mercator::Buffer< float >::m_channels
protectedinherited

The number of data values per height point.

Definition at line 17 of file Buffer.h.

std::vector<float > Mercator::Buffer< float >::m_data
protectedinherited

Pointer to buffer containing data values.

Definition at line 21 of file Buffer.h.

Referenced by fill2d().

const unsigned int Mercator::Buffer< float >::m_size
protectedinherited

The size of segment, m_res + 1.

Definition at line 19 of file Buffer.h.

Referenced by fill2d().


The documentation for this class was generated from the following files: