OGRE  1.8
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-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"
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; }
127  virtual void setTerrainWorldSize(Real newWorldSize);
130  virtual uint16 getTerrainSize() const { return mTerrainSize; }
136  virtual void setTerrainSize(uint16 newTerrainSize);
139  virtual SceneManager* getSceneManager() const { return mSceneManager; }
140 
150  void setFilenameConvention(const String& prefix, const String& extension);
152  void setFilenamePrefix(const String& prefix);
154  void setFilenameExtension(const String& extension);
156  const String& getFilenamePrefix() const { return mFilenamePrefix; }
158  const String& getFilenameExtension() const { return mFilenameExtension; }
159 
161  void setResourceGroup(const String& grp) { mResourceGroup = grp; }
163  const String& getResourceGroup() const { return mResourceGroup; }
177  virtual void defineTerrain(long x, long y);
178 
189  virtual void defineTerrain(long x, long y, float constantHeight);
190 
201  virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
202 
215  virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
216 
229  virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
230 
241  virtual void defineTerrain(long x, long y, const String& filename);
242 
243 
248  virtual void loadAllTerrains(bool synchronous = false);
249 
256  virtual void loadTerrain(long x, long y, bool synchronous = false);
257 
270  virtual void unloadTerrain(long x, long y);
271 
278  virtual void removeTerrain(long x, long y);
279 
282  void removeAllTerrains();
283 
298  void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
299 
303  {
308 
309  TerrainSlotDefinition() :importData(0) {}
311 
313  void useImportData();
315  void useFilename();
317  void freeImportData();
318  };
319 
322  {
324  long x, y;
329 
330  TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
331  ~TerrainSlot();
332  void freeInstance();
333  };
334 
344  virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
345 
351  virtual Terrain* getTerrain(long x, long y) const;
352 
357  void freeTemporaryResources();
358 
362  void update(bool synchronous = false);
363 
367  void updateGeometry();
368 
372  void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
373 
377  {
379  bool hit;
384 
385  RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
386  : hit(_hit), terrain(_terrain), position(_pos) {}
387  };
388 
396  float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
397 
405  float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
406 
416  RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
417 
428  void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
438  void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
439 
444  void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
445 
450  void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
451 
455  bool isDerivedDataUpdateInProgress() const;
456 
461 
463  TerrainIterator getTerrainIterator();
465  ConstTerrainIterator getTerrainIterator() const;
466 
468  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
470  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
472  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
474  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
475 
477  uint32 packIndex(long x, long y) const;
478 
480  void unpackIndex(uint32 key, long *x, long *y);
481 
483  String generateFilename(long x, long y) const;
484 
487  void saveGroupDefinition(const String& filename);
490  void saveGroupDefinition(StreamSerialiser& stream);
493  void loadGroupDefinition(const String& filename);
496  void loadGroupDefinition(StreamSerialiser& stream);
497 
498 
500  static const uint32 CHUNK_ID;
501  static const uint16 CHUNK_VERSION;
502 
503  protected:
516 
518  Vector3 getTerrainSlotPosition(long x, long y);
520  TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
521  TerrainSlot* getTerrainSlot(long x, long y) const;
522  void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
523 
524  void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
525 
527  struct LoadRequest
528  {
531  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
532  { return o; }
533  };
534 
535 
536  };
537 
538 
542 }
543 
544 #endif
545 
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:272
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:270
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.
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: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:271
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: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...