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