#include <Terrain.h>
Public Types | |
typedef WFMath::AxisBox< 2 > | Rect |
Bounding box. | |
typedef std::map< int, BasePoint > | Pointcolumn |
STL map to store sparse array of BasePoints. | |
typedef std::map< int, Segment * > | Segmentcolumn |
STL map to store sparse array of Segment pointers. | |
typedef std::map< int, Pointcolumn > | Pointstore |
STL map to store sparse array of BasePoint columns. | |
typedef std::map< int, Segmentcolumn > | Segmentstore |
STL map to store sparse array of Segment pointer columns. | |
typedef std::map< int, Shader * > | Shaderstore |
STL map to store sparse array of Shader pointers. | |
typedef std::map< Area *, Rect > | Areastore |
STL map to store area modifiers. | |
typedef std::map< TerrainMod *, Rect > | TerrainModstore |
STL map to store height modifiers. | |
Public Member Functions | |
Terrain (unsigned int options=DEFAULT, unsigned int resolution=defaultResolution) | |
Construct a new Terrain object with optional options and resolution. | |
~Terrain () | |
Desctruct Terrain object, deleting contained objects. | |
float | get (float x, float y) const |
Get the height value at a given coordinate x,y. | |
bool | getHeightAndNormal (float x, float y, float &, WFMath::Vector< 3 > &) const |
Get an accurate height and normal vector at a given coordinate x,y. | |
bool | getBasePoint (int x, int y, BasePoint &z) const |
Get the BasePoint at a given base point coordinate. | |
void | setBasePoint (int x, int y, const BasePoint &z) |
Set the BasePoint value at a given base point coordinate. | |
void | setBasePoint (int x, int y, float z) |
Set the height of the basepoint at x,y to z. | |
Segment * | getSegment (float x, float y) const |
Get a pointer to the segment which contains the coord x,y. | |
Segment * | getSegment (int x, int y) const |
Get the Segment at a given base point coordinate. | |
const int | getResolution () const |
Accessor for base point resolution. | |
const Segmentstore & | getTerrain () const |
Accessor for 2D sparse array of Segment pointers. | |
const Pointstore & | getPoints () const |
Accessor for 2D sparse array of BasePoint objects. | |
const Shaderstore & | getShaders () const |
Accessor for list of Shader pointers. | |
void | addShader (Shader *t, int id) |
Add a new Shader to the list for this terrain. | |
TerrainMod * | addMod (const TerrainMod &t) |
Add a modifier to the terrain. | |
void | updateMod (TerrainMod *mod) |
void | removeMod (TerrainMod *mod) |
void | addArea (Area *a) |
Add an area modifier to the terrain. | |
void | updateArea (Area *a) |
Apply changes to an area modifier to the terrain. | |
void | removeArea (Area *a) |
Remove an area modifier from the terrain. | |
Static Public Attributes | |
static const unsigned int | DEFAULT = 0x0000 |
value provided for no flags set. | |
static const unsigned int | SHADED = 0x0001 |
set if shaders are going to be used on this terrain. | |
static const float | defaultLevel = 8 |
Height value used when no data is available. | |
Private Member Functions | |
void | addSurfaces (Segment &) |
Add the required Surface objects to a Segment. | |
void | shadeSurfaces (Segment &) |
Populate the Surface objects associated with a Segment. | |
bool | isShaded () const |
Determine whether this terrain object has shading enabled. | |
Private Attributes | |
const unsigned int | m_options |
Bitset of option flags controlling various aspects of terrain. | |
const int | m_res |
BasePoint resolution, or distance between adjacent points. | |
Pointstore | m_basePoints |
2D spatial container with all BasePoints. | |
Segmentstore | m_segments |
2D spatial container with pointers to all Segments. | |
Shaderstore | m_shaders |
List of shaders to be applied to terrain. | |
Areastore | m_areas |
List of areas modifiers to be applied to the terrain. | |
TerrainModstore | m_mods |
List of height modifiers to be applied to the terrain. |
All the data includes:
Mercator::Terrain::Terrain | ( | unsigned int | options = DEFAULT , |
|
unsigned int | resolution = defaultResolution | |||
) | [explicit] |
Construct a new Terrain object with optional options and resolution.
options | a bitfield of option flags. Defaults to no flags set.
| |
resolution | the spacing between adjacent base points. Defaults to 64. |
Mercator::Terrain::~Terrain | ( | ) |
Desctruct Terrain object, deleting contained objects.
All Segment objects are deleted, but Shader objects are not yet deleted. Probably need to be fixed.
References m_segments.
void Mercator::Terrain::addSurfaces | ( | Segment & | seg | ) | [private] |
Add the required Surface objects to a Segment.
If shading is enabled, each Segment has a set of Surface objects corresponding to the Shader objects available for this terrain. This function creates the necessary Surface objects, and adds them to the list in the Segment object. At this point the Segment is not yet populated with heightfield data, so the Surface cannot be populated. A newly constructed surface does not allocate its buffer memory, so there is very little overhead to creating it.
References Mercator::Segment::getSurfaces(), and m_shaders.
Referenced by setBasePoint().
void Mercator::Terrain::shadeSurfaces | ( | Segment & | seg | ) | [private] |
Populate the Surface objects associated with a Segment.
This is called after a Segment has been populated with heightfield data. The actual responsibility for populating the Surface objects is in Segment::populateSurfaces().
References Mercator::Segment::populateSurfaces().
bool Mercator::Terrain::isShaded | ( | ) | const [inline, private] |
Determine whether this terrain object has shading enabled.
References m_options, and SHADED.
Referenced by setBasePoint().
float Mercator::Terrain::get | ( | float | x, | |
float | y | |||
) | const |
Get the height value at a given coordinate x,y.
This is a convenience function provided to quickly get a height value at a given point. It always succeeds, as if no height data is available it just returns the default value. If a Segment does exist in the right place and is populated, the coords within that Segment are determined, and the heightfield queried. This function does not cause any data to be populated, and does not attempt to do any interpolation to get an accurate height figure. For more accurate results see Terrain::getHeightAndNormal.
References defaultLevel, Mercator::Segment::get(), getSegment(), Mercator::Segment::isValid(), and m_res.
bool Mercator::Terrain::getHeightAndNormal | ( | float | x, | |
float | y, | |||
float & | h, | |||
WFMath::Vector< 3 > & | n | |||
) | const |
Get an accurate height and normal vector at a given coordinate x,y.
This is a more expensive function that Terrain::get() for getting an accurate height value and surface normal at a given point. The main body of functionality is in the Segment::getHeightAndNormal() function called from here. The height and normal are interpolated based on a model where each tile of the heightfield comprises two triangles. If no heightfield data is available for the given location, this function returns false, and no data is returned.
x | coordinate of point to be returned. | |
y | coordinate of point to be returned. | |
h | reference to variable which will be used to store the resulting height value. | |
n | reference to variable which will be used to store the resulting normal value. |
References Mercator::Segment::getHeightAndNormal(), getSegment(), Mercator::Segment::isValid(), and m_res.
bool Mercator::Terrain::getBasePoint | ( | int | x, | |
int | y, | |||
BasePoint & | z | |||
) | const |
Get the BasePoint at a given base point coordinate.
Get the BasePoint value for the given coordinate on the base point grid.
x | coordinate on the base point grid. | |
y | coordinate on the base point grid. | |
z | reference to varaible which will be used to store the BasePoint data. |
References m_basePoints.
Referenced by setBasePoint().
void Mercator::Terrain::setBasePoint | ( | int | x, | |
int | y, | |||
const BasePoint & | z | |||
) |
Set the BasePoint value at a given base point coordinate.
Set the BasePoint value for the given coordinate on the base point grid. If inserting this BasePoint completes the set of points required to define one or more Segment objects which were not yet defined, new Segment objects are created. If this replaces a point for one or more Segment objects that were already defined, the contents of those Segment objects are invalidated.
x | coordinate on the base point grid. | |
y | coordinate on the base point grid. | |
z | BasePoint value to be used at the given coordinate. |
References Mercator::Segment::addArea(), Mercator::Segment::addMod(), addSurfaces(), Mercator::Segment::clipToSegment(), getBasePoint(), Mercator::Segment::getControlPoints(), getSegment(), Mercator::BasePoint::height(), isShaded(), m_areas, m_basePoints, m_mods, m_res, m_segments, Mercator::Segment::setCornerPoint(), and Mercator::Segment::setMinMax().
Referenced by setBasePoint().
Segment* Mercator::Terrain::getSegment | ( | float | x, | |
float | y | |||
) | const [inline] |
Get a pointer to the segment which contains the coord x,y.
References m_res.
Referenced by addArea(), addMod(), get(), getHeightAndNormal(), removeArea(), setBasePoint(), and updateArea().
Segment * Mercator::Terrain::getSegment | ( | int | x, | |
int | y | |||
) | const |
Get the Segment at a given base point coordinate.
Get the Segment pointer for the given coordinate on the base point grid. The Segment in question may not have been populated with heightfield or surface data.
x | coordinate on the base point grid. | |
y | coordinate on the base point grid. |
References m_segments.
void Mercator::Terrain::addShader | ( | Shader * | t, | |
int | id | |||
) |
Add a new Shader to the list for this terrain.
As each shader is added, surfaces are added to all existing segments to store the result of the shader.
References Mercator::Shader::checkIntersect(), Mercator::Segment::getSurfaces(), m_segments, m_shaders, and Mercator::Shader::newSurface().
TerrainMod * Mercator::Terrain::addMod | ( | const TerrainMod & | t | ) |
Add a modifier to the terrain.
Add a new TerrainMod object to the terrain, which defines a modification to the terrain heightfield or surface data. The segments are responsible for storing the TerrainMod objects, so the apropriate Segment objects are found and the TerrainMode is passed to each in turn.
t | reference to the TerrainMod object to be applied. |
References Mercator::Segment::addMod(), Mercator::TerrainMod::bbox(), Mercator::TerrainMod::clone(), getSegment(), m_mods, and m_res.
void Mercator::Terrain::addArea | ( | Area * | area | ) |
Add an area modifier to the terrain.
Add a new Area object to the terrain, which defines a modification to the surface.
References Mercator::Segment::addArea(), Mercator::Area::bbox(), Mercator::Area::checkIntersects(), getSegment(), Mercator::Segment::getSurfaces(), m_areas, m_res, and m_shaders.
void Mercator::Terrain::removeArea | ( | Area * | area | ) |
Remove an area modifier from the terrain.
Remove an existing Area object from the terrain, and mark all the affected terrain surfaces as invalid.
References Mercator::Area::bbox(), Mercator::Area::checkIntersects(), getSegment(), Mercator::Segment::getSurfaces(), m_areas, m_res, m_shaders, and Mercator::Segment::removeArea().