OGRE 14.3
Object-Oriented Graphics Rendering Engine
|
Helper class to assist you in managing multiple terrain instances that are connected to each other. More...
#include <OgreTerrainGroup.h>
Classes | |
struct | RayResult |
Result from a terrain ray intersection with the terrain group. More... | |
struct | TerrainSlot |
Slot for a terrain instance, together with its definition. More... | |
struct | TerrainSlotDefinition |
Definition of how to populate a 'slot' in the terrain group. More... | |
Public Types | |
typedef ConstMapIterator< TerrainSlotMap > | ConstTerrainIterator |
typedef MapIterator< TerrainSlotMap > | TerrainIterator |
typedef std::vector< Terrain * > | TerrainList |
typedef std::map< uint32, TerrainSlot * > | TerrainSlotMap |
Packed map, signed 16 bits for each axis from -32767 to +32767. | |
Public Member Functions | |
TerrainGroup (SceneManager *sm) | |
Alternate constructor. | |
TerrainGroup (SceneManager *sm, Terrain::Alignment align, uint16 terrainSize, Real terrainWorldSize) | |
Constructor. | |
virtual | ~TerrainGroup () |
void | autoUpdateLod (long x, long y, bool synchronous, const Any &data) |
Automatically checks if terrain's LOD level needs to be updated. | |
void | autoUpdateLodAll (bool synchronous, const Any &data) |
void | boxIntersects (const AxisAlignedBox &box, TerrainList *resultList) const |
Test intersection of a box with the terrain. | |
void | convertTerrainSlotToWorldPosition (long x, long y, Vector3 *pos) const |
Convert a slot location to a world position at the centre. | |
void | convertWorldPositionToTerrainSlot (const Vector3 &pos, long *x, long *y) const |
Convert a world position to terrain slot coordinates. | |
void | decreaseLodLevel (long x, long y) |
Removes terrain's highest LOD level. | |
virtual void | defineTerrain (long x, long y) |
Define a 'slot' in the terrain grid - in this case to be loaded from a generated file name. | |
virtual void | defineTerrain (long x, long y, const float *pFloat, const Terrain::LayerInstanceList *layers=0) |
Define the content of a 'slot' in the terrain grid. | |
virtual void | defineTerrain (long x, long y, const Image *img, const Terrain::LayerInstanceList *layers=0) |
Define the content of a 'slot' in the terrain grid. | |
virtual void | defineTerrain (long x, long y, const String &filename) |
Define the content of a 'slot' in the terrain grid. | |
virtual void | defineTerrain (long x, long y, const Terrain::ImportData *importData) |
Define the content of a 'slot' in the terrain grid. | |
virtual void | defineTerrain (long x, long y, float constantHeight) |
Define a 'slot' in the terrain grid - in this case a flat terrain. | |
void | freeTemporaryResources () |
Free as many resources as possible for optimal run-time memory use for all terrain tiles. | |
String | generateFilename (long x, long y) const |
Generate a file name based on the current naming convention. | |
virtual Terrain::Alignment | getAlignment () const |
Retrieve the alignment of the grid of terrain (cannot be modified after construction). | |
virtual Terrain::ImportData & | getDefaultImportSettings () |
Retrieve a shared structure which will provide the base settings for all terrains created via this group. | |
const String & | getFilenameExtension () const |
const String & | getFilenamePrefix () const |
float | getHeightAtWorldPosition (const Vector3 &pos, Terrain **ppTerrain=0) |
Get the height data for a given world position (projecting the point down on to the terrain). | |
float | getHeightAtWorldPosition (Real x, Real y, Real z, Terrain **ppTerrain=0) |
Get the height data for a given world position (projecting the point down on to the terrain underneath). | |
size_t | getNumTerrainPrepareRequests () const |
Get the number of terrains that are still waiting for the Terrain::prepare() to be called. | |
virtual const Vector3 & | getOrigin () const |
Retrieve the centre position of the grid of terrain. | |
const String & | getResourceGroup () const |
Get the resource group in which files will be located. | |
virtual SceneManager * | getSceneManager () const |
Retrieve the SceneManager being used for this group. | |
virtual Terrain * | getTerrain (long x, long y) const |
Get the terrain instance at a given slot, if loaded. | |
virtual TerrainSlotDefinition * | getTerrainDefinition (long x, long y) const |
Get the definition of a slot in the terrain. | |
TerrainIterator | getTerrainIterator () |
ConstTerrainIterator | getTerrainIterator () const |
virtual uint16 | getTerrainSize () const |
Retrieve the size of each terrain instance in number of vertices down one side. | |
const TerrainSlotMap & | getTerrainSlots () const |
Get the defined terrains. | |
virtual Real | getTerrainWorldSize () const |
Retrieve the world size of each terrain instance. | |
void | increaseLodLevel (long x, long y, bool synchronous=false) |
Loads terrain's next LOD level. | |
bool | isDerivedDataUpdateInProgress () const |
Calls Terrain::isDerivedDataUpdateInProgress on each loaded instance and returns true if any of them are undergoing a derived update. | |
virtual void | loadAllTerrains (bool synchronous=false) |
Load any terrain instances that have been defined but not loaded yet. | |
void | loadGroupDefinition (const String &filename) |
Load the group definition only in native form from a file. | |
void | loadGroupDefinition (StreamSerialiser &stream) |
Load the group definition only in native form from a serializing stream. | |
void | loadLegacyTerrain (const ConfigFile &cfg, long x=0, long y=0, bool synchronous=true) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | loadLegacyTerrain (const String &cfgFilename, long x=0, long y=0, bool synchronous=true) |
Load a terrain.cfg as used by the terrain scene manager into a single terrain slot. | |
virtual void | loadTerrain (long x, long y, bool synchronous=false) |
Load a specific terrain slot based on the definition that has already been supplied. | |
uint32 | packIndex (long x, long y) const |
Convert coordinates to a packed integer index. | |
RayResult | rayIntersects (const Ray &ray, Real distanceLimit=0) const |
Test for intersection of a given ray with any terrain in the group. | |
void | removeAllTerrains () |
Remove all terrain instances. | |
virtual void | removeTerrain (long x, long y) |
Remove a specific terrain slot. | |
void | saveAllTerrains (bool onlyIfModified, bool replaceManualFilenames=true) |
Save all terrain instances using the assigned file names, or via the filename convention. | |
void | saveGroupDefinition (const String &filename) |
Save the group data only in native form to a file. | |
void | saveGroupDefinition (StreamSerialiser &stream) |
Save the group data only in native form to a serializing stream. | |
void | setAutoUpdateLod (TerrainAutoUpdateLod *updater) |
void | setFilenameConvention (const String &prefix, const String &extension) |
Set the naming convention for file names in this terrain group. | |
void | setFilenameExtension (const String &extension) |
void | setFilenamePrefix (const String &prefix) |
virtual void | setOrigin (const Vector3 &pos) |
Define the centre position of the grid of terrain. | |
void | setResourceGroup (const String &grp) |
Set the resource group in which files will be located. | |
virtual void | setTerrainSize (uint16 newTerrainSize) |
Set the size of each terrain instance in number of vertices down one side. | |
virtual void | setTerrainWorldSize (Real newWorldSize) |
Set the world size of terrain. | |
void | sphereIntersects (const Sphere &sphere, TerrainList *resultList) const |
Test intersection of a sphere with the terrain. | |
virtual void | unloadTerrain (long x, long y) |
Unload a specific terrain slot. | |
void | unpackIndex (uint32 key, long *x, long *y) |
Convert a packed integer index to coordinates. | |
void | update (bool synchronous=false) |
Trigger the update process for all terrain instances. | |
void | updateDerivedData (bool synchronous=false, uint8 typeMask=0xFF) |
Updates derived data for all terrains (LOD, lighting) to reflect changed height data. | |
void | updateGeometry () |
Performs an update on all terrain geometry. | |
Static Public Attributes | |
static const uint32 | CHUNK_ID |
static const uint16 | CHUNK_VERSION |
Helper class to assist you in managing multiple terrain instances that are connected to each other.
This class makes it easy to specify the same options for a group of terrain instances and have them positioned relative to each other and associated via each other's neighbour connections. You can do all this manually but this class just makes things easier, so that you only have to specify most options once.
typedef std::vector<Terrain*> Ogre::TerrainGroup::TerrainList |
typedef std::map<uint32, TerrainSlot*> Ogre::TerrainGroup::TerrainSlotMap |
Packed map, signed 16 bits for each axis from -32767 to +32767.
Ogre::TerrainGroup::TerrainGroup | ( | SceneManager * | sm, |
Terrain::Alignment | align, | ||
uint16 | terrainSize, | ||
Real | terrainWorldSize | ||
) |
Constructor.
sm | The SceneManager which will parent the terrain instances. |
align | The alignment that all terrain instances will use |
terrainSize | The size of each terrain down one edge in vertices (2^n+1) |
terrainWorldSize | The world size of each terrain instance |
Ogre::TerrainGroup::TerrainGroup | ( | SceneManager * | sm | ) |
Alternate constructor.
You can ONLY use this constructor if you subsequently call loadGroupDefinition or loadLegacyTerrain to populate the rest.
|
virtual |
|
inlinevirtual |
Retrieve a shared structure which will provide the base settings for all terrains created via this group.
All neighbouring terrains should have the same basic settings (particularly the size parameters) - to avoid having to set the terrain import information more than once, you can retrieve the standard settings for this group here and modify them to your needs. Once you've done that you can use the shortcut methods in this class to create new terrain instances using these base settings (plus any per-instance settings you might want to use).
Define the centre position of the grid of terrain.
Retrieve the centre position of the grid of terrain.
|
inlinevirtual |
Retrieve the alignment of the grid of terrain (cannot be modified after construction).
Retrieve the world size of each terrain instance.
Set the world size of terrain.
newWorldSize | the new world size of each terrain instance |
Retrieve the size of each terrain instance in number of vertices down one side.
Set the size of each terrain instance in number of vertices down one side.
newTerrainSize | the new map size of each terrain instance |
|
inlinevirtual |
Retrieve the SceneManager being used for this group.
Set the naming convention for file names in this terrain group.
You can more easily generate file names for saved / loaded terrain slots if you define a naming prefix. When you call saveAllTerrains(), all the terrain instances currently loaded will be saved to a file named <prefix>_<index>.<extension>, where <index> is given by packing the x and y coordinates of the entry into a 32-bit index (
Set the resource group in which files will be located.
Get the resource group in which files will be located.
Define a 'slot' in the terrain grid - in this case to be loaded from a generated file name.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
Define a 'slot' in the terrain grid - in this case a flat terrain.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
constantHeight | The constant, uniform height that you want the terrain to start at |
|
virtual |
Define the content of a 'slot' in the terrain grid.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
importData | Import data - this data is copied during the call so you may destroy your copy afterwards. |
|
virtual |
Define the content of a 'slot' in the terrain grid.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
img | Heightfield image - this data is copied during the call so you may destroy your copy afterwards. |
layers | Optional texture layers to use (if not supplied, default import data layers will be used) - this data is copied during the call so you may destroy your copy afterwards. |
|
virtual |
Define the content of a 'slot' in the terrain grid.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
pFloat | Heights array |
layers | Optional texture layers to use (if not supplied, default import data layers will be used) - this data is copied during the call so you may destroy your copy afterwards. |
Define the content of a 'slot' in the terrain grid.
At this stage the terrain instance isn't actually present in the grid, you're merely expressing an intention for it to take its place there once it's loaded. The reason we do it like this is to support background preparation of this terrain instance.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
filename | The name of a file which fully defines the terrain (as written by Terrain::save). Size settings from all files must agree. |
Load any terrain instances that have been defined but not loaded yet.
synchronous | Whether we should force this to happen entirely in the primary thread |
Load a specific terrain slot based on the definition that has already been supplied.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
synchronous | Whether we should force this to happen entirely in the primary thread |
void Ogre::TerrainGroup::loadLegacyTerrain | ( | const String & | cfgFilename, |
long | x = 0 , |
||
long | y = 0 , |
||
bool | synchronous = true |
||
) |
Load a terrain.cfg as used by the terrain scene manager into a single terrain slot.
automatically configures the SM2Profile if it is used.
cfgFilename | .cfg file that specifices what textures/scale/mipmaps/etc to use. |
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
synchronous | Whether we should force this to happen entirely in the primary thread |
void Ogre::TerrainGroup::loadLegacyTerrain | ( | const ConfigFile & | cfg, |
long | x = 0 , |
||
long | y = 0 , |
||
bool | synchronous = true |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Unload a specific terrain slot.
This destroys the Terrain instance but retains the slot definition (so it would be reloaded next time you call loadAllTerrains() if you did not remove it beforehand).
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
Remove a specific terrain slot.
This destroys any Terrain instance at this position and also removes the definition, so it essentially no longer exists.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
void Ogre::TerrainGroup::removeAllTerrains | ( | ) |
Remove all terrain instances.
void Ogre::TerrainGroup::saveAllTerrains | ( | bool | onlyIfModified, |
bool | replaceManualFilenames = true |
||
) |
Save all terrain instances using the assigned file names, or via the filename convention.
onlyIfModified | If true, only terrains that have been modified since load(), or since the last save(), will be saved. You want to set this to true if you loaded the terrain from these same files, but false if you defined them using some other input data since the files wouldn't exist. |
replaceManualFilenames | If true, replaces any manually defined filenames in the TerrainSlotDefinition with the generated names from the convention. This is recommended since it makes everything more consistent, although you might want to use manual filenames in the original definition to import previously separate data. |
|
virtual |
Get the definition of a slot in the terrain.
Definitions exist before the actual instances to allow background loading.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
Get the terrain instance at a given slot, if loaded.
x,y | The coordinates of the terrain slot relative to the centre slot (signed). |
void Ogre::TerrainGroup::freeTemporaryResources | ( | ) |
Free as many resources as possible for optimal run-time memory use for all terrain tiles.
Trigger the update process for all terrain instances.
void Ogre::TerrainGroup::updateGeometry | ( | ) |
Performs an update on all terrain geometry.
Updates derived data for all terrains (LOD, lighting) to reflect changed height data.
float Ogre::TerrainGroup::getHeightAtWorldPosition | ( | Real | x, |
Real | y, | ||
Real | z, | ||
Terrain ** | ppTerrain = 0 |
||
) |
Get the height data for a given world position (projecting the point down on to the terrain underneath).
x,y,z | Position in world space. Positions will be clamped to the edge of the terrain |
ppTerrain | Pointer to a pointer to a terrain which will be completed with the terrain that was found to resolve this query, or null if none were |
float Ogre::TerrainGroup::getHeightAtWorldPosition | ( | const Vector3 & | pos, |
Terrain ** | ppTerrain = 0 |
||
) |
Get the height data for a given world position (projecting the point down on to the terrain).
pos | Position in world space. Positions will be clamped to the edge of the terrain |
ppTerrain | Pointer to a pointer to a terrain which will be completed with the terrain that was found to resolve this query, or null if none were |
Test for intersection of a given ray with any terrain in the group.
If the ray hits a terrain, the point of intersection and terrain instance is returned.
ray | The ray to test for intersection |
distanceLimit | The distance from the ray origin at which we will stop looking, 0 indicates no limit |
void Ogre::TerrainGroup::boxIntersects | ( | const AxisAlignedBox & | box, |
TerrainList * | resultList | ||
) | const |
Test intersection of a box with the terrain.
Tests an AABB for overlap with a terrain bounding box. Note that this does not mean that the box touches the terrain itself, just the bounding box for the terrain. You can use this to get region results for further testing or use (e.g. painting areas).
box | The AABB you want to test in world units |
resultList | Pointer to a list of terrain pointers which will be updated to include just the terrains that overlap |
void Ogre::TerrainGroup::sphereIntersects | ( | const Sphere & | sphere, |
TerrainList * | resultList | ||
) | const |
Test intersection of a sphere with the terrain.
Tests a sphere for overlap with a terrain bounding box. Note that this does not mean that the sphere touches the terrain itself, just the bounding box for the terrain. You can use this to get region results for further testing or use (e.g. painting areas).
sphere | The sphere you want to test in world units |
resultList | Pointer to a list of terrain pointers which will be updated to include just the terrains that overlap |
void Ogre::TerrainGroup::convertWorldPositionToTerrainSlot | ( | const Vector3 & | pos, |
long * | x, | ||
long * | y | ||
) | const |
Convert a world position to terrain slot coordinates.
pos | The world position |
x,y | Pointers to the coordinates to be completed. |
Convert a slot location to a world position at the centre.
x,y | The slot coordinates |
pos | Pointer to the world position to be completed |
bool Ogre::TerrainGroup::isDerivedDataUpdateInProgress | ( | ) | const |
Calls Terrain::isDerivedDataUpdateInProgress on each loaded instance and returns true if any of them are undergoing a derived update.
TerrainIterator Ogre::TerrainGroup::getTerrainIterator | ( | ) |
ConstTerrainIterator Ogre::TerrainGroup::getTerrainIterator | ( | ) | const |
|
inline |
Get the defined terrains.
Convert coordinates to a packed integer index.
Convert a packed integer index to coordinates.
Generate a file name based on the current naming convention.
Save the group data only in native form to a file.
void Ogre::TerrainGroup::saveGroupDefinition | ( | StreamSerialiser & | stream | ) |
Save the group data only in native form to a serializing stream.
Load the group definition only in native form from a file.
void Ogre::TerrainGroup::loadGroupDefinition | ( | StreamSerialiser & | stream | ) |
Load the group definition only in native form from a serializing stream.
Loads terrain's next LOD level.
void Ogre::TerrainGroup::setAutoUpdateLod | ( | TerrainAutoUpdateLod * | updater | ) |
Automatically checks if terrain's LOD level needs to be updated.
size_t Ogre::TerrainGroup::getNumTerrainPrepareRequests | ( | ) | const |
Get the number of terrains that are still waiting for the Terrain::prepare() to be called.