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:
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 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 16 2013 14:35:46