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-2012 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
    00037 namespace Ogre
    00038 {
    00069     class _OgreTerrainExport TerrainGroup : public WorkQueue::RequestHandler,
    00070         public WorkQueue::ResponseHandler, public TerrainAlloc
    00071     {
    00072     public:
    00079         TerrainGroup(SceneManager* sm, Terrain::Alignment align, uint16 terrainSize,
    00080             Real terrainWorldSize);
    00086         TerrainGroup(SceneManager* sm);
    00087         virtual ~TerrainGroup();
    00088
    00106         virtual Terrain::ImportData& getDefaultImportSettings() { return mDefaultImportData; }
    00107
    00110         virtual void setOrigin(const Vector3& pos);
    00111
    00114         virtual const Vector3& getOrigin() const { return mOrigin; }
    00115
    00118         virtual Terrain::Alignment getAlignment() const { return mAlignment; }
    00119
    00122         virtual Real getTerrainWorldSize() const { return mTerrainWorldSize; }
    00127         virtual void setTerrainWorldSize(Real newWorldSize);
    00130         virtual uint16 getTerrainSize() const { return mTerrainSize; }
    00136         virtual void setTerrainSize(uint16 newTerrainSize);
    00139         virtual SceneManager* getSceneManager() const { return mSceneManager; }
    00140
    00150         void setFilenameConvention(const String& prefix, const String& extension);
    00152         void setFilenamePrefix(const String& prefix);
    00154         void setFilenameExtension(const String& extension);
    00156         const String& getFilenamePrefix() const { return mFilenamePrefix; }
    00158         const String& getFilenameExtension() const { return mFilenameExtension; }
    00159
    00161         void setResourceGroup(const String& grp) { mResourceGroup = grp; }
    00163         const String& getResourceGroup() const { return mResourceGroup; }
    00177         virtual void defineTerrain(long x, long y);
    00178
    00189         virtual void defineTerrain(long x, long y, float constantHeight);
    00190
    00201         virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
    00202
    00215         virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
    00216
    00229         virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
    00230
    00241         virtual void defineTerrain(long x, long y, const String& filename);
    00242
    00243
    00248         virtual void loadAllTerrains(bool synchronous = false);
    00249
    00256         virtual void loadTerrain(long x, long y, bool synchronous = false);
    00257
    00270         virtual void unloadTerrain(long x, long y);
    00271
    00278         virtual void removeTerrain(long x, long y);
    00279
    00282         void removeAllTerrains();
    00283
    00298         void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
    00299
    00302         struct _OgreTerrainExport TerrainSlotDefinition
    00303         {
    00305             String filename;
    00307             Terrain::ImportData* importData;
    00308
    00309             TerrainSlotDefinition() :importData(0) {}
    00310             ~TerrainSlotDefinition();
    00311
    00313             void useImportData();
    00315             void useFilename();
    00317             void freeImportData();
    00318         };
    00319
    00321         struct _OgreTerrainExport TerrainSlot : public TerrainAlloc
    00322         {
    00324             long x, y;
    00326             TerrainSlotDefinition def;
    00328             Terrain* instance;
    00329
    00330             TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
    00331             ~TerrainSlot();
    00332             void freeInstance();
    00333         };
    00334
    00344         virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
    00345
    00351         virtual Terrain* getTerrain(long x, long y) const;
    00352
    00357         void freeTemporaryResources();
    00358
    00362         void update(bool synchronous = false);
    00363
    00367         void updateGeometry();
    00368
    00372         void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
    00373
    00376         struct _OgreTerrainExport RayResult
    00377         {
    00379             bool hit;
    00381             Terrain* terrain;
    00383             Vector3 position;
    00384
    00385             RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
    00386                 : hit(_hit), terrain(_terrain), position(_pos) {}
    00387         };
    00388
    00396         float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
    00397
    00405         float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
    00406
    00416         RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
    00417
    00418         typedef vector<Terrain*>::type TerrainList;
    00428         void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
    00438         void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
    00439
    00444         void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
    00445
    00450         void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
    00451
    00455         bool isDerivedDataUpdateInProgress() const;
    00456
    00458         typedef map<uint32, TerrainSlot*>::type TerrainSlotMap;
    00459         typedef MapIterator<TerrainSlotMap> TerrainIterator;
    00460         typedef ConstMapIterator<TerrainSlotMap> ConstTerrainIterator;
    00461
    00463         TerrainIterator getTerrainIterator();
    00465         ConstTerrainIterator getTerrainIterator() const;
    00466
    00468         bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00470         WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00472         bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00474         void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00475
    00477         uint32 packIndex(long x, long y) const;
    00478
    00480         void unpackIndex(uint32 key, long *x, long *y);
    00481
    00483         String generateFilename(long x, long y) const;
    00484
    00487         void saveGroupDefinition(const String& filename);
    00490         void saveGroupDefinition(StreamSerialiser& stream);
    00493         void loadGroupDefinition(const String& filename);
    00496         void loadGroupDefinition(StreamSerialiser& stream);
    00497
    00498
    00499         static const uint16 WORKQUEUE_LOAD_REQUEST;
    00500         static const uint32 CHUNK_ID;
    00501         static const uint16 CHUNK_VERSION;
    00502
    00503     protected:
    00504         SceneManager *mSceneManager;
    00505         Terrain::Alignment mAlignment;
    00506         uint16 mTerrainSize;
    00507         Real mTerrainWorldSize;
    00508         Terrain::ImportData mDefaultImportData;
    00509         Vector3 mOrigin;
    00510         TerrainSlotMap mTerrainSlots;
    00511         uint16 mWorkQueueChannel;
    00512         String mFilenamePrefix;
    00513         String mFilenameExtension;
    00514         String mResourceGroup;
    00515         Terrain::DefaultGpuBufferAllocator mBufferAllocator;
    00516
    00518         Vector3 getTerrainSlotPosition(long x, long y);
    00520         TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
    00521         TerrainSlot* getTerrainSlot(long x, long y) const;
    00522         void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
    00523
    00524         void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
    00525
    00527         struct LoadRequest
    00528         {
    00529             TerrainSlot* slot;
    00530             TerrainGroup* origin;
    00531             _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
    00532             { return o; }
    00533         };
    00534
    00535
    00536     };
    00537
    00538
    00542 }
    00543
    00544 #endif
    00545

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24