OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 {
71  {
72  public:
79  TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize,
80  Real terrainWorldSize);
87  virtual ~TerrainGroup();
88 
106  virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
107 
110  virtual void setOrigin(const Vector3& pos);
111 
114  virtual const Vector3& getOrigin() const { return mOrigin; }
115 
118  virtual Terrain::Alignment getAlignment() const { return mAlignment; }
119 
122  virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
123 
126  virtual SceneManager* getSceneManager() const { return mSceneManager; }
127 
137  void setFilenameConvention(const String& prefix, const String& extension);
139  void setFilenamePrefix(const String& prefix);
141  void setFilenameExtension(const String& extension);
143  const String& getFilenamePrefix() const { return mFilenamePrefix; }
145  const String& getFilenameExtension() const { return mFilenameExtension; }
146 
148  void setResourceGroup(const String& grp) { mResourceGroup = grp; }
150  const String& getResourceGroup() const { return mResourceGroup; }
164  virtual void defineTerrain(long x, long y);
165 
176  virtual void defineTerrain(long x, long y, float constantHeight);
177 
188  virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
189 
202  virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
203 
216  virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
217 
228  virtual void defineTerrain(long x, long y, const String& filename);
229 
230 
235  virtual void loadAllTerrains(bool synchronous = false);
236 
243  virtual void loadTerrain(long x, long y, bool synchronous = false);
244 
257  virtual void unloadTerrain(long x, long y);
258 
265  virtual void removeTerrain(long x, long y);
266 
269  void removeAllTerrains();
270 
285  void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
286 
290  {
295 
296  TerrainSlotDefinition() :importData(0) {}
298 
300  void useImportData();
302  void useFilename();
304  void freeImportData();
305  };
306 
309  {
311  long x, y;
316 
317  TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
318  ~TerrainSlot();
319  void freeInstance();
320  };
321 
331  virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
332 
338  virtual Terrain* getTerrain(long x, long y) const;
339 
344  void freeTemporaryResources();
345 
349  void update(bool synchronous = false);
350 
354  void updateGeometry();
355 
359  void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
360 
364  {
366  bool hit;
371 
372  RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
373  : hit(_hit), terrain(_terrain), position(_pos) {}
374  };
375 
383  float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
384 
392  float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
393 
403  RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
404 
415  void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
425  void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
426 
431  void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
432 
437  void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
438 
442  bool isDerivedDataUpdateInProgress() const;
443 
448 
450  TerrainIterator getTerrainIterator();
452  ConstTerrainIterator getTerrainIterator() const;
453 
455  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
457  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
459  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
461  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
462 
464  uint32 packIndex(long x, long y) const;
465 
467  void unpackIndex(uint32 key, long *x, long *y);
468 
470  String generateFilename(long x, long y) const;
471 
474  void saveGroupDefinition(const String& filename);
477  void saveGroupDefinition(StreamSerialiser& stream);
480  void loadGroupDefinition(const String& filename);
483  void loadGroupDefinition(StreamSerialiser& stream);
484 
485 
487  static const uint32 CHUNK_ID;
488  static const uint16 CHUNK_VERSION;
489 
490  protected:
503 
505  Vector3 getTerrainSlotPosition(long x, long y);
507  TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
508  TerrainSlot* getTerrainSlot(long x, long y) const;
509  void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
510 
511  void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
512 
514  struct LoadRequest
515  {
518  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
519  { return o; }
520  };
521 
522 
523  };
524 
525 
529 }
530 
531 #endif
532 
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:248
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:318
float Real
Software floating point type.
const String & getFilenamePrefix() const
unsigned int uint32
Definition: OgrePlatform.h:246
static const uint32 CHUNK_ID
std::vector< T, A > type
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:261
vector< LayerInstance >::type LayerInstanceList
Definition: OgreTerrain.h:302
ConstMapIterator< TerrainSlotMap > ConstTerrainIterator
General purpose request structure.
Definition: OgreWorkQueue.h:82
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.
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.
Alignment
The alignment of the terrain.
Definition: OgreTerrain.h:305
Utility class providing helper methods for reading / writing structured data held in a DataStream...
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.
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:566
_StringBase String
unsigned short uint16
Definition: OgrePlatform.h:247
Slot for a terrain instance, together with its definition.
virtual Real getTerrainWorldSize() const
Retrieve the world size of each terrain instance (cannot be modified after construction).
Interface to a general purpose request / response style background work queue.
Definition: OgreWorkQueue.h:69
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...