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-2013 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:
521  TerrainSlotMap mTerrainSlots;
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 
Terrain::Alignment mAlignment
const String & getFilenameExtension() const
Vector3 position
Position at which the intersection occurred.
Slot for a terrain instance, together with its definition.
vector< LayerInstance >::type LayerInstanceList
Definition: OgreTerrain.h:308
virtual uint16 getTerrainSize() const
Retrieve the size of each terrain instance in number of vertices down one side.
unsigned int uint
virtual const Vector3 & getOrigin() const
Retrieve the centre position of the grid of terrain.
std::vector< T, A > type
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:70
MapIterator< TerrainSlotMap > TerrainIterator
Terrain automatic LOD loading.
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
bool hit
Whether an intersection occurred.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
void setResourceGroup(const String &grp)
Set the resource group in which files will be located.
Concrete IteratorWrapper for const access to the underlying key-value container.
virtual Terrain::ImportData & getDefaultImportSettings()
Retrieve a shared structure which will provide the base settings for all terrains created via this gr...
Structure for holding the load request.
static const uint16 WORKQUEUE_LOAD_REQUEST
float Real
Software floating point type.
Terrain::ImportData * importData
Import data, if this is to be defined based on importing.
SceneManager * mSceneManager
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
Variant type that can hold Any other type.
Definition: OgreAny.h:56
virtual Real getTerrainWorldSize() const
Retrieve the world size of each terrain instance.
Terrain * instance
Actual terrain instance.
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
const String & getFilenamePrefix() const
General purpose request structure.
Definition: OgreWorkQueue.h:83
const String & getResourceGroup() const
Get the resource group in which files will be located.
virtual Terrain::Alignment getAlignment() const
Retrieve the alignment of the grid of terrain (cannot be modified after construction).
Result from a terrain ray intersection with the terrain group.
Helper class to assist you in managing multiple terrain instances that are connected to each other...
General purpose response structure.
unsigned char uint8
Definition: OgrePlatform.h:361
Terrain::DefaultGpuBufferAllocator mBufferAllocator
TerrainSlotDefinition def
Definition used to load the terrain.
static const uint16 CHUNK_VERSION
#define _OgreTerrainExport
Alignment
The alignment of the terrain.
Definition: OgreTerrain.h:311
_StringBase String
TerrainAutoUpdateLod * mAutoUpdateLod
vector< Terrain * >::type TerrainList
Terrain * terrain
Which terrain instance was hit, if any.
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const LoadRequest &r)
virtual SceneManager * getSceneManager() const
Retrieve the SceneManager being used for this group.
Utility class providing helper methods for reading / writing structured data held in a DataStream...
RayResult(bool _hit, Terrain *_terrain, const Vector3 &_pos)
String filename
Filename, if this is to be loaded from a file.
unsigned int uint32
Definition: OgrePlatform.h:359
Class representing an image file.
Definition: OgreImage.h:61
map< uint32, TerrainSlot * >::type TerrainSlotMap
Packed map, signed 16 bits for each axis from -32767 to +32767.
Interface definition for a handler of responses.
static const uint32 CHUNK_ID
Structure encapsulating import data that you may use to bootstrap the terrain without loading from a ...
Definition: OgreTerrain.h:324
Definition of how to populate a &#39;slot&#39; in the terrain group.
TerrainSlotMap mTerrainSlots
Terrain::ImportData mDefaultImportData
A 3D box aligned with the x/y/z axes.
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Standard implementation of a buffer allocator which re-uses buffers.
Definition: OgreTerrain.h:572
Interface definition for a handler of requests.
unsigned short uint16
Definition: OgrePlatform.h:360
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Representation of a ray in space, i.e.
Definition: OgreRay.h:46

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.