OgreTerrainGroup.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __Ogre_TerrainGroup_H__
00030 #define __Ogre_TerrainGroup_H__
00031 
00032 #include "OgreTerrainPrerequisites.h"
00033 #include "OgreTerrain.h"
00034 #include "OgreWorkQueue.h"
00035 #include "OgreIteratorWrappers.h"
00036 #include "OgreTerrainAutoUpdateLod.h"
00037 
00038 namespace Ogre
00039 {
00070     class _OgreTerrainExport TerrainGroup : public WorkQueue::RequestHandler, 
00071         public WorkQueue::ResponseHandler, public TerrainAlloc
00072     {
00073     public:
00080         TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize, 
00081             Real terrainWorldSize);
00087         TerrainGroup(SceneManager* sm);
00088         virtual ~TerrainGroup();
00089 
00107         virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
00108 
00111         virtual void setOrigin(const Vector3& pos);
00112 
00115         virtual const Vector3& getOrigin() const { return mOrigin; }
00116 
00119         virtual Terrain::Alignment getAlignment() const { return mAlignment; }
00120 
00123         virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
00128         virtual void setTerrainWorldSize(Real newWorldSize);
00131         virtual uint16 getTerrainSize() const { return mTerrainSize; }
00137         virtual void setTerrainSize(uint16 newTerrainSize);
00140         virtual SceneManager* getSceneManager() const { return mSceneManager; }
00141 
00151         void setFilenameConvention(const String& prefix, const String& extension);
00153         void setFilenamePrefix(const String& prefix);
00155         void setFilenameExtension(const String& extension);
00157         const String& getFilenamePrefix() const { return mFilenamePrefix; }
00159         const String& getFilenameExtension() const { return mFilenameExtension; }
00160 
00162         void setResourceGroup(const String& grp) { mResourceGroup = grp; }
00164         const String& getResourceGroup() const { return mResourceGroup; }
00178         virtual void defineTerrain(long x, long y);
00179 
00190         virtual void defineTerrain(long x, long y, float constantHeight);
00191 
00202         virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
00203 
00216         virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
00217 
00230         virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
00231 
00242         virtual void defineTerrain(long x, long y, const String& filename);
00243 
00244 
00249         virtual void loadAllTerrains(bool synchronous = false);
00250         
00257         virtual void loadTerrain(long x, long y, bool synchronous = false);
00258         
00271         virtual void unloadTerrain(long x, long y);
00272 
00279         virtual void removeTerrain(long x, long y);
00280 
00283         void removeAllTerrains();
00284 
00299         void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
00300         
00303         struct _OgreTerrainExport TerrainSlotDefinition
00304         {
00306             String filename;
00308             Terrain::ImportData* importData;
00309 
00310             TerrainSlotDefinition() :importData(0) {}
00311             ~TerrainSlotDefinition();
00312 
00314             void useImportData();
00316             void useFilename();
00318             void freeImportData();
00319         };
00320 
00322         struct _OgreTerrainExport TerrainSlot : public TerrainAlloc
00323         {
00325             long x, y;
00327             TerrainSlotDefinition def;
00329             Terrain* instance;
00330 
00331             TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
00332             virtual ~TerrainSlot();
00333             void freeInstance();
00334         };
00335         
00345         virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
00346         
00352         virtual Terrain* getTerrain(long x, long y) const;
00353 
00358         void freeTemporaryResources();
00359 
00363         void update(bool synchronous = false);
00364 
00368         void updateGeometry();
00369 
00373         void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
00374         
00377         struct _OgreTerrainExport RayResult
00378         {
00380             bool hit;
00382             Terrain* terrain;
00384             Vector3 position;
00385 
00386             RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
00387                 : hit(_hit), terrain(_terrain), position(_pos) {}
00388         };
00389         
00397         float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
00398 
00406         float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
00407 
00417         RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const; 
00418         
00419         typedef vector<Terrain*>::type TerrainList; 
00429         void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
00439         void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
00440         
00445         void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
00446 
00451         void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
00452         
00456         bool isDerivedDataUpdateInProgress() const;
00457 
00459         typedef map<uint32, TerrainSlot*>::type TerrainSlotMap;
00460         typedef MapIterator<TerrainSlotMap> TerrainIterator;
00461         typedef ConstMapIterator<TerrainSlotMap> ConstTerrainIterator;
00462 
00464         TerrainIterator getTerrainIterator();
00466         ConstTerrainIterator getTerrainIterator() const;
00467 
00469         bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
00471         WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
00473         bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
00475         void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
00476 
00478         uint32 packIndex(long x, long y) const;
00479         
00481         void unpackIndex(uint32 key, long *x, long *y);
00482 
00484         String generateFilename(long x, long y) const;
00485 
00488         void saveGroupDefinition(const String& filename);
00491         void saveGroupDefinition(StreamSerialiser& stream);
00494         void loadGroupDefinition(const String& filename);
00497         void loadGroupDefinition(StreamSerialiser& stream);
00498 
00499 
00500         static const uint16 WORKQUEUE_LOAD_REQUEST;
00501         static const uint32 CHUNK_ID;
00502         static const uint16 CHUNK_VERSION;
00503 
00505         void increaseLodLevel(long x, long y, bool synchronous = false);
00507         void decreaseLodLevel(long x, long y);
00508 
00509         void setAutoUpdateLod(TerrainAutoUpdateLod* updater);
00511         void autoUpdateLod(long x, long y, bool synchronous, const Any &data);
00512         void autoUpdateLodAll(bool synchronous, const Any &data);
00513 
00514     protected:
00515         SceneManager *mSceneManager;
00516         Terrain::Alignment mAlignment;
00517         uint16 mTerrainSize;
00518         Real mTerrainWorldSize;
00519         Terrain::ImportData mDefaultImportData;
00520         Vector3 mOrigin;
00521         TerrainSlotMap mTerrainSlots;
00522         uint16 mWorkQueueChannel;
00523         String mFilenamePrefix;
00524         String mFilenameExtension;
00525         String mResourceGroup;
00526         TerrainAutoUpdateLod *mAutoUpdateLod;
00527         Terrain::DefaultGpuBufferAllocator mBufferAllocator;
00528         
00530         Vector3 getTerrainSlotPosition(long x, long y);
00532         TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
00533         TerrainSlot* getTerrainSlot(long x, long y) const;
00534         void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
00535 
00536         void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
00537 
00539         struct LoadRequest
00540         {
00541             TerrainSlot* slot;
00542             TerrainGroup* origin;
00543             static uint loadingTaskNum;
00544             _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
00545             { return o; }       
00546         };
00547         
00548 
00549     };
00550 
00551 
00555 }
00556 
00557 #endif
00558 

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 Mon Jul 27 2020 13:40:48