# 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-2009 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; }
    00123
    00126         virtual SceneManager* getSceneManager() const { return mSceneManager; }
    00127
    00137         void setFilenameConvention(const String& prefix, const String& extension);
    00139         void setFilenamePrefix(const String& prefix);
    00141         void setFilenameExtension(const String& extension);
    00143         const String& getFilenamePrefix() const { return mFilenamePrefix; }
    00145         const String& getFilenameExtension() const { return mFilenameExtension; }
    00146
    00148         void setResourceGroup(const String& grp) { mResourceGroup = grp; }
    00150         const String& getResourceGroup() const { return mResourceGroup; }
    00164         virtual void defineTerrain(long x, long y);
    00165
    00176         virtual void defineTerrain(long x, long y, float constantHeight);
    00177
    00188         virtual void defineTerrain(long x, long y, const Terrain::ImportData* importData);
    00189
    00202         virtual void defineTerrain(long x, long y, const Image* img, const Terrain::LayerInstanceList* layers = 0);
    00203
    00216         virtual void defineTerrain(long x, long y, const float* pFloat, const Terrain::LayerInstanceList* layers = 0);
    00217
    00228         virtual void defineTerrain(long x, long y, const String& filename);
    00229
    00230
    00235         virtual void loadAllTerrains(bool synchronous = false);
    00236
    00243         virtual void loadTerrain(long x, long y, bool synchronous = false);
    00244
    00257         virtual void unloadTerrain(long x, long y);
    00258
    00265         virtual void removeTerrain(long x, long y);
    00266
    00269         void removeAllTerrains();
    00270
    00285         void saveAllTerrains(bool onlyIfModified, bool replaceManualFilenames = true);
    00286
    00289         struct _OgreTerrainExport TerrainSlotDefinition
    00290         {
    00292             String filename;
    00294             Terrain::ImportData* importData;
    00295
    00296             TerrainSlotDefinition() :importData(0) {}
    00297             ~TerrainSlotDefinition();
    00298
    00300             void useImportData();
    00302             void useFilename();
    00304             void freeImportData();
    00305         };
    00306
    00308         struct _OgreTerrainExport TerrainSlot : public TerrainAlloc
    00309         {
    00311             long x, y;
    00313             TerrainSlotDefinition def;
    00315             Terrain* instance;
    00316
    00317             TerrainSlot(long _x, long _y) : x(_x), y(_y), instance(0) {}
    00318             ~TerrainSlot();
    00319             void freeInstance();
    00320         };
    00321
    00331         virtual TerrainSlotDefinition* getTerrainDefinition(long x, long y) const;
    00332
    00338         virtual Terrain* getTerrain(long x, long y) const;
    00339
    00344         void freeTemporaryResources();
    00345
    00349         void update(bool synchronous = false);
    00350
    00354         void updateGeometry();
    00355
    00359         void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
    00360
    00363         struct _OgreTerrainExport RayResult
    00364         {
    00366             bool hit;
    00368             Terrain* terrain;
    00370             Vector3 position;
    00371
    00372             RayResult(bool _hit, Terrain* _terrain, const Vector3& _pos)
    00373                 : hit(_hit), terrain(_terrain), position(_pos) {}
    00374         };
    00375
    00383         float getHeightAtWorldPosition(Real x, Real y, Real z, Terrain** ppTerrain = 0);
    00384
    00392         float getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain = 0);
    00393
    00403         RayResult rayIntersects(const Ray& ray, Real distanceLimit = 0) const;
    00404
    00405         typedef vector<Terrain*>::type TerrainList;
    00415         void boxIntersects(const AxisAlignedBox& box, TerrainList* resultList) const;
    00425         void sphereIntersects(const Sphere& sphere, TerrainList* resultList) const;
    00426
    00431         void convertWorldPositionToTerrainSlot(const Vector3& pos, long *x, long *y) const;
    00432
    00437         void convertTerrainSlotToWorldPosition(long x, long y, Vector3* pos) const;
    00438
    00442         bool isDerivedDataUpdateInProgress() const;
    00443
    00445         typedef map<uint32, TerrainSlot*>::type TerrainSlotMap;
    00446         typedef MapIterator<TerrainSlotMap> TerrainIterator;
    00447         typedef ConstMapIterator<TerrainSlotMap> ConstTerrainIterator;
    00448
    00450         TerrainIterator getTerrainIterator();
    00452         ConstTerrainIterator getTerrainIterator() const;
    00453
    00455         bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00457         WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
    00459         bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00461         void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
    00462
    00464         uint32 packIndex(long x, long y) const;
    00465
    00467         void unpackIndex(uint32 key, long *x, long *y);
    00468
    00470         String generateFilename(long x, long y) const;
    00471
    00474         void saveGroupDefinition(const String& filename);
    00477         void saveGroupDefinition(StreamSerialiser& stream);
    00480         void loadGroupDefinition(const String& filename);
    00483         void loadGroupDefinition(StreamSerialiser& stream);
    00484
    00485
    00486         static const uint16 WORKQUEUE_LOAD_REQUEST;
    00487         static const uint32 CHUNK_ID;
    00488         static const uint16 CHUNK_VERSION;
    00489
    00490     protected:
    00491         SceneManager *mSceneManager;
    00492         Terrain::Alignment mAlignment;
    00493         uint16 mTerrainSize;
    00494         Real mTerrainWorldSize;
    00495         Terrain::ImportData mDefaultImportData;
    00496         Vector3 mOrigin;
    00497         TerrainSlotMap mTerrainSlots;
    00498         uint16 mWorkQueueChannel;
    00499         String mFilenamePrefix;
    00500         String mFilenameExtension;
    00501         String mResourceGroup;
    00502         Terrain::DefaultGpuBufferAllocator mBufferAllocator;
    00503
    00505         Vector3 getTerrainSlotPosition(long x, long y);
    00507         TerrainSlot* getTerrainSlot(long x, long y, bool createIfMissing);
    00508         TerrainSlot* getTerrainSlot(long x, long y) const;
    00509         void connectNeighbour(TerrainSlot* slot, long offsetx, long offsety);
    00510
    00511         void loadTerrainImpl(TerrainSlot* slot, bool synchronous);
    00512
    00514         struct LoadRequest
    00515         {
    00516             TerrainSlot* slot;
    00517             TerrainGroup* origin;
    00518             _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const LoadRequest& r)
    00519             { return o; }
    00520         };
    00521
    00522
    00523     };
    00524
    00525
    00529 }
    00530
    00531 #endif
    00532

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52