/src/ogre/OgreMain/src/OgreLodStrategy.cpp
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 | | #include "OgreStableHeaders.h" |
30 | | #include "OgreLodStrategy.h" |
31 | | |
32 | | namespace Ogre { |
33 | | //----------------------------------------------------------------------- |
34 | | LodStrategy::LodStrategy(const String& name) |
35 | 4 | : mName(name) |
36 | 4 | { } |
37 | | //----------------------------------------------------------------------- |
38 | | LodStrategy::~LodStrategy() |
39 | 0 | { } |
40 | | //----------------------------------------------------------------------- |
41 | | Real LodStrategy::transformUserValue(Real userValue) const |
42 | 231 | { |
43 | | // No transformation by default |
44 | 231 | return userValue; |
45 | 231 | } |
46 | | //----------------------------------------------------------------------- |
47 | | Real LodStrategy::getValue(const MovableObject *movableObject, const Camera *camera) const |
48 | 0 | { |
49 | | // Just return implementation with LOD camera |
50 | 0 | return getValueImpl(movableObject, camera->getLodCamera()); |
51 | 0 | } |
52 | | //----------------------------------------------------------------------- |
53 | | void LodStrategy::assertSorted(const Mesh::LodValueList &values) const |
54 | 0 | { |
55 | 0 | assert(isSorted(values) && "The LOD values must be sorted"); |
56 | 0 | } |
57 | | //--------------------------------------------------------------------- |
58 | | bool LodStrategy::isSortedAscending(const Mesh::LodValueList& values) |
59 | 0 | { |
60 | 0 | Mesh::LodValueList::const_iterator it = values.begin(); |
61 | 0 | Real prev = (*it); |
62 | 0 | for (++it; it != values.end(); ++it) |
63 | 0 | { |
64 | 0 | Real cur = (*it); |
65 | 0 | if (cur < prev) |
66 | 0 | return false; |
67 | 0 | prev = cur; |
68 | 0 | } |
69 | | |
70 | 0 | return true; |
71 | 0 | } |
72 | | //--------------------------------------------------------------------- |
73 | | bool LodStrategy::isSortedDescending(const Mesh::LodValueList& values) |
74 | 0 | { |
75 | 0 | Mesh::LodValueList::const_iterator it = values.begin(); |
76 | 0 | Real prev = (*it); |
77 | 0 | for (++it; it != values.end(); ++it) |
78 | 0 | { |
79 | 0 | Real cur = (*it); |
80 | 0 | if (cur > prev) |
81 | 0 | return false; |
82 | 0 | prev = cur; |
83 | 0 | } |
84 | | |
85 | 0 | return true; |
86 | 0 | } |
87 | | //--------------------------------------------------------------------- |
88 | | void LodStrategy::sortAscending(Mesh::MeshLodUsageList& meshLodUsageList) |
89 | 0 | { |
90 | | // Perform standard sort |
91 | 0 | std::sort(meshLodUsageList.begin(), meshLodUsageList.end(), |
92 | 0 | [](const MeshLodUsage& mesh1, const MeshLodUsage& mesh2) { return mesh1.value < mesh2.value; }); |
93 | 0 | } |
94 | | //--------------------------------------------------------------------- |
95 | | void LodStrategy::sortDescending(Mesh::MeshLodUsageList& meshLodUsageList) |
96 | 0 | { |
97 | | // Perform standard sort |
98 | 0 | std::sort(meshLodUsageList.begin(), meshLodUsageList.end(), |
99 | 0 | [](const MeshLodUsage& mesh1, const MeshLodUsage& mesh2) { return mesh1.value > mesh2.value; }); |
100 | 0 | } |
101 | | //--------------------------------------------------------------------- |
102 | | ushort LodStrategy::getIndexAscending(Real value, const Mesh::MeshLodUsageList& meshLodUsageList) |
103 | 0 | { |
104 | 0 | ushort index = 0; |
105 | 0 | for (auto& m : meshLodUsageList) |
106 | 0 | { |
107 | 0 | if (m.value > value) |
108 | 0 | { |
109 | 0 | return index ? index - 1 : 0; |
110 | 0 | } |
111 | 0 | ++index; |
112 | 0 | } |
113 | | |
114 | | // If we fall all the way through, use the highest value |
115 | 0 | return static_cast<ushort>(meshLodUsageList.size() - 1); |
116 | 0 | } |
117 | | //--------------------------------------------------------------------- |
118 | | ushort LodStrategy::getIndexDescending(Real value, const Mesh::MeshLodUsageList& meshLodUsageList) |
119 | 0 | { |
120 | 0 | ushort index = 0; |
121 | 0 | for (auto& m : meshLodUsageList) |
122 | 0 | { |
123 | 0 | if (m.value < value) |
124 | 0 | { |
125 | 0 | return index ? index - 1 : 0; |
126 | 0 | } |
127 | 0 | ++index; |
128 | 0 | } |
129 | | |
130 | | // If we fall all the way through, use the highest value |
131 | 0 | return static_cast<ushort>(meshLodUsageList.size() - 1); |
132 | 0 | } |
133 | | //--------------------------------------------------------------------- |
134 | | ushort LodStrategy::getIndexAscending(Real value, const Material::LodValueList& materialLodValueList) |
135 | 0 | { |
136 | 0 | unsigned short index = 0; |
137 | 0 | for (auto& m : materialLodValueList) |
138 | 0 | { |
139 | 0 | if (m > value) |
140 | 0 | { |
141 | 0 | return index ? index - 1 : 0; |
142 | 0 | } |
143 | 0 | ++index; |
144 | 0 | } |
145 | | |
146 | | // If we fall all the way through, use the highest value |
147 | 0 | return static_cast<ushort>(materialLodValueList.size() - 1); |
148 | 0 | } |
149 | | //--------------------------------------------------------------------- |
150 | | ushort LodStrategy::getIndexDescending(Real value, const Material::LodValueList& materialLodValueList) |
151 | 0 | { |
152 | 0 | unsigned short index = 0; |
153 | 0 | for (auto& m : materialLodValueList) |
154 | 0 | { |
155 | 0 | if (m < value) |
156 | 0 | { |
157 | 0 | return index ? index - 1 : 0; |
158 | 0 | } |
159 | 0 | ++index; |
160 | 0 | } |
161 | | |
162 | | // If we fall all the way through, use the highest value |
163 | 0 | return static_cast<ushort>(materialLodValueList.size() - 1); |
164 | 0 | } |
165 | | } // namespace |