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_TerrainAutoUpdateLod_H__ 30 #define __Ogre_TerrainAutoUpdateLod_H__ 31 32 #include "OgreTerrainPrerequisites.h" 33 #include "OgreTerrain.h" 34 35 namespace Ogre 36 { 37 /** \addtogroup Optional Components 38 * @{ 39 */ 40 /** \addtogroup Terrain 41 * Some details on the terrain auto load 42 * @{ 43 */ 44 45 /** Terrain automatic LOD loading 46 @par 47 This set of classes is used for automatic change of terrain LOD level. Base is TerrainAutoUpdateLod interface with just 48 one public method autoUpdateLod. This method gets called by terrain whenever user thinks something has 49 changed(typically in application's main loop) what could affect terrain's LOD level. It is designed in such a way 50 so user can use whatever algorithm he likes to change terrain's LOD level. For example see TerrainAutoUpdateLod 51 implementation TerrainAutoUpdateLodByDistance. 52 It is also used as a null object for auto-LOD-updating. 53 */ 54 class _OgreTerrainExport TerrainAutoUpdateLod : public TerrainAlloc 55 { 56 public: ~TerrainAutoUpdateLod()57 virtual ~TerrainAutoUpdateLod() {} 58 /** Method to be called to change terrain's LOD level. 59 @param terrain Instance of Terrain which LOD level is going to be changed 60 @param synchronous Run this as part of main thread or in background 61 @param data Any user specific data. 62 */ 63 virtual void autoUpdateLod(Terrain *terrain, bool synchronous, const Any &data) = 0; 64 virtual uint32 getStrategyId() = 0; 65 }; 66 67 // other Strategy's id start from 2 68 enum TerrainAutoUpdateLodStrategy 69 { 70 NONE = 0, 71 BY_DISTANCE = 1 72 }; 73 74 /** Class implementing TerrainAutoUpdateLod interface. It does LOD level increase/decrease according to camera's 75 distance to Terrain. 76 */ 77 class _OgreTerrainExport TerrainAutoUpdateLodByDistance : public TerrainAutoUpdateLod 78 { 79 public: 80 virtual void autoUpdateLod(Terrain *terrain, bool synchronous, const Any &data); getStrategyId()81 virtual uint32 getStrategyId() { return BY_DISTANCE; } 82 83 protected: 84 /** Modifies Terrain's LOD level according to it's distance from camera. 85 @param holdDistance How far ahead of terrain's LOD level change this LOD level should be loaded. 86 */ 87 void autoUpdateLodByDistance(Terrain *terrain, bool synchronous, const Real holdDistance); 88 /// Traverse Terrain's QuadTree and calculate what LOD level is needed. 89 int traverseTreeByDistance(TerrainQuadTreeNode *node, const Camera *cam, Real cFactor, const Real holdDistance); 90 }; 91 92 class _OgreTerrainExport TerrainAutoUpdateLodFactory 93 { 94 public: getAutoUpdateLod(uint32 strategy)95 static TerrainAutoUpdateLod* getAutoUpdateLod( uint32 strategy ) 96 { 97 switch(strategy) 98 { 99 case BY_DISTANCE: 100 return OGRE_NEW TerrainAutoUpdateLodByDistance; 101 case NONE: 102 default: 103 return 0; 104 } 105 return 0; 106 } 107 }; 108 /** @} */ 109 /** @} */ 110 } 111 112 #endif 113