OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTerrainGroup.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __Ogre_TerrainGroup_H__
30 #define __Ogre_TerrainGroup_H__
31 
33 #include "OgreTerrain.h"
34 #include "OgreWorkQueue.h"
35 #include "OgreIteratorWrappers.h"
36 
37 namespace Ogre
38 {
39  class TerrainAutoUpdateLod;
40 
73  {
74  public:
81  TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize,
82  Real terrainWorldSize);
89  virtual ~TerrainGroup();
90 
108  virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
109 
112  virtual void setOrigin(const Vector3& pos);
113 
116  virtual const Vector3& getOrigin() const { return mOrigin; }
117 
120  virtual Terrain::Alignment getAlignment() const { return mAlignment; }
121 
124  virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
129  virtual void setTerrainWorldSize(Real newWorldSize);
132  virtual uint16 getTerrainSize() const { return mTerrainSize; }
138  virtual void setTerrainSize(uint16 newTerrainSize);
141  virtual SceneManager* getSceneManager() const { return mSceneManager; }
142 
152  void setFilenameConvention(const String& prefix, const String& extension);
154  void setFilenamePrefix(const String& prefix);
156  void setFilenameExtension(const String& extension);
158  const String& getFilenamePrefix() const { return mFilenamePrefix; }
160  const String& getFilenameExtension() const { return mFilenameExtension; }
161 
163  void setResourceGroup(const String& grp) { mResourceGroup = grp; }
165  const String& getResourceGroup() const { return mResourceGroup; }
179  virtual void defineTerrain(long x, long y);
180 
191  virtual void defineTerrain(long x, long y, float constantHeight);
192 
203  virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
204 
217  virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
218 
231  virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
232 
243  virtual void defineTerrain(long x, long y, const String& filename);
244 
245 
250  virtual void loadAllTerrains(bool synchronous = false);
251 
258  virtual void loadTerrain(long x, long y, bool synchronous = false);
259 
272  virtual void unloadTerrain(long x, long y);
273 
280  virtual void removeTerrain(long x, long y);
281 
284  void removeAllTerrains();
285 
300  void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
301 
305  {
310 
311  TerrainSlotDefinition() :importData(0) {}
313 
315  void useImportData();
317  void useFilename();
319  void freeImportData();
320  };
321 
324  {
326  long x, y;
331 
332  TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
333  virtual ~TerrainSlot();
334  void freeInstance();
335  };
336 
346  virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
347 
353  virtual Terrain* getTerrain(long x, long y) const;
354 
359  void freeTemporaryResources();
360 
364  void update(bool synchronous = false);
365 
369  void updateGeometry();
370 
374  void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
375 
379  {
381  bool hit;
386 
387  RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
388  : hit(_hit), terrain(_terrain), position(_pos) {}
389  };
390 
398  float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
399 
407  float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
408 
418  RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
419 
430  void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
440  void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
441 
446  void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
447 
452  void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
453 
457  bool isDerivedDataUpdateInProgress() const;
458 
463 
465  TerrainIterator getTerrainIterator();
467  ConstTerrainIterator getTerrainIterator() const;
468 
470  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
472  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
474  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
476  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
477 
479  uint32 packIndex(long x, long y) const;
480 
482  void unpackIndex(uint32 key, long *x, long *y);
483 
485  String generateFilename(long x, long y) const;
486 
489  void saveGroupDefinition(const String& filename);
492  void saveGroupDefinition(StreamSerialiser& stream);
495  void loadGroupDefinition(const String& filename);
498  void loadGroupDefinition(StreamSerialiser& stream);
499 
500 
502  static const uint32 CHUNK_ID;
503  static const uint16 CHUNK_VERSION;
504 
506  void increaseLodLevel(long x, long y, bool synchronous = false);
508  void decreaseLodLevel(long x, long y);
509 
510  void setAutoUpdateLod(TerrainAutoUpdateLod* updater);
512  void autoUpdateLod(long x, long y, bool synchronous, const Any &data);
513  void autoUpdateLodAll(bool synchronous, const Any &data);
514 
515  protected:
529 
531  Vector3 getTerrainSlotPosition(long x, long y);
533  TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
534  TerrainSlot* getTerrainSlot(long x, long y) const;
535  void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
536 
537  void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
538 
540  struct LoadRequest
541  {
545  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
546  { return o; }
547  };
548 
549 
550  };
551 
552 
556 }
557 
558 #endif
559 
Representation of a ray in space, i.e.
Definition: OgreRay.h:45
Vector3 position
Position at which the intersection occurred.
unsigned char uint8
Definition: OgrePlatform.h:422
virtual const Vector3 & getOrigin() const
Retrieve the centre position of the grid of terrain.
Structure encapsulating import data that you may use to bootstrap the terrain without loading from a ...
Definition: OgreTerrain.h:327
float Real
Software floating point type.
const String & getFilenamePrefix() const
unsigned int uint32
Definition: OgrePlatform.h:420
static const uint32 CHUNK_ID
Variant type that can hold Any other type.
Definition: OgreAny.h:54
std::vector< T, A > type
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:265
vector< LayerInstance >::type LayerInstanceList
Definition: OgreTerrain.h:311
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
General purpose request structure.
Definition: OgreWorkQueue.h:84
SceneManager * mSceneManager
General purpose response structure.
Definition of how to populate a 'slot' in the terrain group.
Manages the organisation and rendering of a 'scene' i.e.
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const LoadRequest &r)
Terrain::ImportData mDefaultImportData
A 3D box aligned with the x/y/z axes.
void setResourceGroup(const String &grp)
Set the resource group in which files will be located.
const String & getFilenameExtension() const
virtual SceneManager * getSceneManager() const
Retrieve the SceneManager being used for this group.
static const uint16 WORKQUEUE_LOAD_REQUEST
Terrain::Alignment mAlignment
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Structure for holding the load request.
virtual uint16 getTerrainSize() const
Retrieve the size of each terrain instance in number of vertices down one side.
bool hit
Whether an intersection occurred.
Terrain * instance
Actual terrain instance.
MapIterator< TerrainSlotMap > TerrainIterator
Terrain::DefaultGpuBufferAllocator mBufferAllocator
static const uint16 CHUNK_VERSION
Terrain * terrain
Which terrain instance was hit, if any.
Interface definition for a handler of requests.
RayResult(bool _hit, Terrain *_terrain, const Vector3 &_pos)
String filename
Filename, if this is to be loaded from a file.
virtual Terrain::Alignment getAlignment() const
Retrieve the alignment of the grid of terrain (cannot be modified after construction).
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
TerrainSlotDefinition def
Definition used to load the terrain.
Terrain::ImportData * importData
Import data, if this is to be defined based on importing.
#define _OgreTerrainExport
Alignment
The alignment of the terrain.
Definition: OgreTerrain.h:314
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Terrain automatic LOD loading.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
Interface definition for a handler of responses.
Class representing an image file.
Definition: OgreImage.h:60
Result from a terrain ray intersection with the terrain group.
TerrainAutoUpdateLod * mAutoUpdateLod
virtual Terrain::ImportData & getDefaultImportSettings()
Retrieve a shared structure which will provide the base settings for all terrains created via this gr...
Concrete IteratorWrapper for const access to the underlying key-value container.
map< uint32, TerrainSlot * >::type TerrainSlotMap
Packed map, signed 16 bits for each axis from -32767 to +32767.
Standard implementation of a buffer allocator which re-uses buffers.
Definition: OgreTerrain.h:575
_StringBase String
Definition: OgreCommon.h:53
unsigned short uint16
Definition: OgrePlatform.h:421
Slot for a terrain instance, together with its definition.
virtual Real getTerrainWorldSize() const
Retrieve the world size of each terrain instance.
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:71
const String & getResourceGroup() const
Get the resource group in which files will be located.
TerrainSlotMap mTerrainSlots
vector< Terrain * >::type TerrainList
Helper class to assist you in managing multiple terrain instances that are connected to each other...
unsigned int uint