OGRE  1.9
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"
37 
38 namespace Ogre
39 {
72  {
73  public:
80  TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize,
81  Real terrainWorldSize);
88  virtual ~TerrainGroup();
89 
107  virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
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; }
159  const String& getFilenameExtension() const { return mFilenameExtension; }
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 
283  void removeAllTerrains();
284 
299  void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
300 
304  {
309 
310  TerrainSlotDefinition() :importData(0) {}
312 
314  void useImportData();
316  void useFilename();
318  void freeImportData();
319  };
320 
323  {
325  long x, y;
330 
331  TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
332  virtual ~TerrainSlot();
333  void freeInstance();
334  };
335 
345  virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
346 
352  virtual Terrain* getTerrain(long x, long y) const;
353 
358  void freeTemporaryResources();
359 
363  void update(bool synchronous = false);
364 
368  void updateGeometry();
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 
456  bool isDerivedDataUpdateInProgress() const;
457 
462 
464  TerrainIterator getTerrainIterator();
466  ConstTerrainIterator getTerrainIterator() const;
467 
469  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
471  WorkQueue::Response* handleRequest(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);
491  void saveGroupDefinition(StreamSerialiser& stream);
494  void loadGroupDefinition(const String& filename);
497  void loadGroupDefinition(StreamSerialiser& stream);
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 
509  void setAutoUpdateLod(TerrainAutoUpdateLod* updater);
511  void autoUpdateLod(long x, long y, bool synchronous, const Any &data);
512  void autoUpdateLodAll(bool synchronous, const Any &data);
513 
514  protected:
528 
530  Vector3 getTerrainSlotPosition(long x, long y);
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 
539  struct LoadRequest
540  {
544  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
545  { return o; }
546  };
547 
548 
549  };
550 
551 
555 }
556 
557 #endif
558 
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
Vector3 position
Position at which the intersection occurred.
unsigned char uint8
Definition: OgrePlatform.h:346
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:324
float Real
Software floating point type.
const String & getFilenamePrefix() const
unsigned int uint32
Definition: OgrePlatform.h:344
static const uint32 CHUNK_ID
Variant type that can hold Any other type.
Definition: OgreAny.h:56
std::vector< T, A > type
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
vector< LayerInstance >::type LayerInstanceList
Definition: OgreTerrain.h:308
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
General purpose request structure.
Definition: OgreWorkQueue.h:83
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:311
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:51
Interface definition for a handler of responses.
Class representing an image file.
Definition: OgreImage.h:61
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:572
_StringBase String
unsigned short uint16
Definition: OgrePlatform.h:345
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:70
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