OGRE  1.9.0
OgreTerrainGroup.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __Ogre_TerrainGroup_H__
30#define __Ogre_TerrainGroup_H__
31
33#include "OgreTerrain.h"
34#include "OgreWorkQueue.h"
37
38namespace Ogre
39{
47
72 {
73 public:
81 Real terrainWorldSize);
88 virtual ~TerrainGroup();
89
108
111 virtual void setOrigin(const Vector3& pos);
112
115 virtual const Vector3& getOrigin() const { return mOrigin; }
116
119 virtual Terrain::Alignment getAlignment() const { return mAlignment; }
120
123 virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
128 virtual void setTerrainWorldSize(Real newWorldSize);
131 virtual uint16 getTerrainSize() const { return mTerrainSize; }
137 virtual void setTerrainSize(uint16 newTerrainSize);
140 virtual SceneManager* getSceneManager() const { return mSceneManager; }
141
151 void setFilenameConvention(const String& prefix, const String& extension);
153 void setFilenamePrefix(const String& prefix);
155 void setFilenameExtension(const String& extension);
157 const String& getFilenamePrefix() const { return mFilenamePrefix; }
160
162 void setResourceGroup(const String& grp) { mResourceGroup = grp; }
164 const String& getResourceGroup() const { return mResourceGroup; }
178 virtual void defineTerrain(long x, long y);
179
190 virtual void defineTerrain(long x, long y, float constantHeight);
191
202 virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
203
216 virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
217
230 virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
231
242 virtual void defineTerrain(long x, long y, const String& filename);
243
244
249 virtual void loadAllTerrains(bool synchronous = false);
250
257 virtual void loadTerrain(long x, long y, bool synchronous = false);
258
271 virtual void unloadTerrain(long x, long y);
272
279 virtual void removeTerrain(long x, long y);
280
284
299 void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
300
320
323 {
325 long x, y;
330
331 TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
332 virtual ~TerrainSlot();
334 };
335
345 virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
346
352 virtual Terrain* getTerrain(long x, long y) const;
353
359
363 void update(bool synchronous = false);
364
369
373 void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
374
378 {
380 bool hit;
385
386 RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
387 : hit(_hit), terrain(_terrain), position(_pos) {}
388 };
389
397 float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
398
406 float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
407
417 RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
418
429 void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
439 void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
440
445 void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
446
451 void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
452
457
462
467
469 bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
473 bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
475 void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
476
478 uint32 packIndex(long x, long y) const;
479
481 void unpackIndex(uint32 key, long *x, long *y);
482
484 String generateFilename(long x, long y) const;
485
488 void saveGroupDefinition(const String& filename);
494 void loadGroupDefinition(const String& filename);
498
499
501 static const uint32 CHUNK_ID;
502 static const uint16 CHUNK_VERSION;
503
505 void increaseLodLevel(long x, long y, bool synchronous = false);
507 void decreaseLodLevel(long x, long y);
508
511 void autoUpdateLod(long x, long y, bool synchronous, const Any &data);
512 void autoUpdateLodAll(bool synchronous, const Any &data);
513
514 protected:
528
532 TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
533 TerrainSlot* getTerrainSlot(long x, long y) const;
534 void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
535
536 void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
537
540 {
544 _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
545 { return o; }
546 };
547
548
549 };
550
551
554
555}
556
557#endif
558
#define _OgreTerrainExport
Variant type that can hold Any other type.
Definition OgreAny.h:57
A 3D box aligned with the x/y/z axes.
Concrete IteratorWrapper for const access to the underlying key-value container.
Class representing an image file.
Definition OgreImage.h:62
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Representation of a ray in space, i.e.
Definition OgreRay.h:47
Manages the organisation and rendering of a 'scene' i.e.
A sphere primitive, mostly used for bounds checking.
Definition OgreSphere.h:52
Utility class providing helper methods for reading / writing structured data held in a DataStream.
Terrain automatic LOD loading.
bool canHandleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
WorkQueue::RequestHandler override.
void unpackIndex(uint32 key, long *x, long *y)
Convert a packed integer index to coordinates.
void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames=true)
Save all terrain instances using the assigned file names, or via the filename convention.
void convertTerrainSlotToWorldPosition(long x, long y, Vector3 *pos) const
Convert a slot location to a world position at the centre.
void updateGeometry()
Performs an update on all terrain geometry.
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.
MapIterator< TerrainSlotMap > TerrainIterator
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 underneat...
void sphereIntersects(const Sphere &sphere, TerrainList *resultList) const
Test intersection of a sphere with the terrain.
virtual Terrain * getTerrain(long x, long y) const
Get the terrain instance at a given slot, if loaded.
static const uint16 CHUNK_VERSION
TerrainGroup(SceneManager *sm)
Alternate constructor.
virtual Real getTerrainWorldSize() const
Retrieve the world size of each terrain instance.
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.
void boxIntersects(const AxisAlignedBox &box, TerrainList *resultList) const
Test intersection of a box with the terrain.
void saveGroupDefinition(const String &filename)
Save the group data only in native form to a file.
virtual void defineTerrain(long x, long y, const String &filename)
Define the content of a 'slot' in the terrain grid.
void loadGroupDefinition(const String &filename)
Load the group definition only in native form from a file.
ConstTerrainIterator getTerrainIterator() const
Get an iterator over the defined terrains (const)
void increaseLodLevel(long x, long y, bool synchronous=false)
Loads terrain's next LOD level.
void decreaseLodLevel(long x, long y)
Removes terrain's highest LOD level.
virtual void defineTerrain(long x, long y, float constantHeight)
Define a 'slot' in the terrain grid - in this case a flat terrain.
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).
virtual void setTerrainWorldSize(Real newWorldSize)
Set the world size of terrain.
void autoUpdateLodAll(bool synchronous, const Any &data)
TerrainSlotMap mTerrainSlots
void convertWorldPositionToTerrainSlot(const Vector3 &pos, long *x, long *y) const
Convert a world position to terrain slot coordinates.
virtual Terrain::ImportData & getDefaultImportSettings()
Retrieve a shared structure which will provide the base settings for all terrains created via this gr...
Terrain::ImportData mDefaultImportData
void handleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
WorkQueue::ResponseHandler override.
virtual void defineTerrain(long x, long y, const Terrain::ImportData *importData)
Define the content of a 'slot' in the terrain grid.
TerrainSlot * getTerrainSlot(long x, long y) const
void saveGroupDefinition(StreamSerialiser &stream)
Save the group data only in native form to a serializing stream.
void freeTemporaryResources()
Free as many resources as possible for optimal run-time memory use for all terrain tiles.
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
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.
const String & getFilenameExtension() const
void setFilenameExtension(const String &extension)
virtual uint16 getTerrainSize() const
Retrieve the size of each terrain instance in number of vertices down one side.
TerrainGroup(SceneManager *sm, Terrain::Alignment align, uint16 terrainSize, Real terrainWorldSize)
Constructor.
String generateFilename(long x, long y) const
Generate a file name based on the current naming convention.
virtual SceneManager * getSceneManager() const
Retrieve the SceneManager being used for this group.
Terrain::Alignment mAlignment
virtual ~TerrainGroup()
static const uint16 WORKQUEUE_LOAD_REQUEST
Vector3 getTerrainSlotPosition(long x, long y)
Get the position of a terrain instance.
bool isDerivedDataUpdateInProgress() const
Calls Terrain::isDerivedDataUpdateInProgress on each loaded instance and returns true if any of them ...
const String & getFilenamePrefix() const
void loadTerrainImpl(TerrainSlot *slot, bool synchronous)
virtual void loadTerrain(long x, long y, bool synchronous=false)
Load a specific terrain slot based on the definition that has already been supplied.
void setFilenamePrefix(const String &prefix)
SceneManager * mSceneManager
virtual Terrain::Alignment getAlignment() const
Retrieve the alignment of the grid of terrain (cannot be modified after construction).
void loadGroupDefinition(StreamSerialiser &stream)
Load the group definition only in native form from a serializing stream.
TerrainIterator getTerrainIterator()
Get an iterator over the defined terrains.
void setResourceGroup(const String &grp)
Set the resource group in which files will be located.
map< uint32, TerrainSlot * >::type TerrainSlotMap
Packed map, signed 16 bits for each axis from -32767 to +32767.
virtual const Vector3 & getOrigin() const
Retrieve the centre position of the grid of terrain.
void setAutoUpdateLod(TerrainAutoUpdateLod *updater)
virtual void setOrigin(const Vector3 &pos)
Define the centre position of the grid of terrain.
void update(bool synchronous=false)
Trigger the update process for all terrain instances.
TerrainSlot * getTerrainSlot(long x, long y, bool createIfMissing)
Retrieve a slot, potentially allocate one.
virtual void removeTerrain(long x, long y)
Remove a specific terrain slot.
void setFilenameConvention(const String &prefix, const String &extension)
Set the naming convention for file names in this terrain group.
void autoUpdateLod(long x, long y, bool synchronous, const Any &data)
Automatically checks if terrain's LOD level needs to be updated.
WorkQueue::Response * handleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
WorkQueue::RequestHandler override.
const String & getResourceGroup() const
Get the resource group in which files will be located.
virtual void loadAllTerrains(bool synchronous=false)
Load any terrain instances that have been defined but not loaded yet.
RayResult rayIntersects(const Ray &ray, Real distanceLimit=0) const
Test for intersection of a given ray with any terrain in the group.
Terrain::DefaultGpuBufferAllocator mBufferAllocator
bool canHandleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
WorkQueue::ResponseHandler override.
virtual TerrainSlotDefinition * getTerrainDefinition(long x, long y) const
Get the definition of a slot in the terrain.
virtual void setTerrainSize(uint16 newTerrainSize)
Set the size of each terrain instance in number of vertices down one side.
TerrainAutoUpdateLod * mAutoUpdateLod
uint32 packIndex(long x, long y) const
Convert coordinates to a packed integer index.
void connectNeighbour(TerrainSlot *slot, long offsetx, long offsety)
static const uint32 CHUNK_ID
void updateDerivedData(bool synchronous=false, uint8 typeMask=0xFF)
Updates derived data for all terrains (LOD, lighting) to reflect changed height data.
vector< Terrain * >::type TerrainList
virtual void unloadTerrain(long x, long y)
Unload a specific terrain slot.
void removeAllTerrains()
Remove all terrain instances.
Standard implementation of a buffer allocator which re-uses buffers.
The main containing class for a chunk of terrain.
vector< LayerInstance >::type LayerInstanceList
Alignment
The alignment of the terrain.
Standard 3-dimensional vector.
Definition OgreVector3.h:52
Interface definition for a handler of requests.
General purpose request structure.
Interface definition for a handler of responses.
Interface to a general purpose request / response style background work queue.
unsigned char uint8
float Real
Software floating point type.
unsigned short uint16
unsigned int uint
unsigned int uint32
GeneralAllocatedObject TerrainAlloc
_StringBase String
Structure for holding the load request.
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const LoadRequest &r)
Result from a terrain ray intersection with the terrain group.
Vector3 position
Position at which the intersection occurred.
RayResult(bool _hit, Terrain *_terrain, const Vector3 &_pos)
bool hit
Whether an intersection occurred.
Terrain * terrain
Which terrain instance was hit, if any.
Definition of how to populate a 'slot' in the terrain group.
Terrain::ImportData * importData
Import data, if this is to be defined based on importing.
void useImportData()
Set to use import data.
void useFilename()
Set to use file name.
String filename
Filename, if this is to be loaded from a file.
void freeImportData()
Destroy temp import resources.
Slot for a terrain instance, together with its definition.
long x
The coordinates of the terrain slot relative to the centre slot (signed).
Terrain * instance
Actual terrain instance.
TerrainSlotDefinition def
Definition used to load the terrain.
Structure encapsulating import data that you may use to bootstrap the terrain without loading from a ...
General purpose response structure.
std::map< K, V, P, A > type
std::vector< T, A > type