/src/ogre/OgreMain/src/OgreDefaultSceneQueries.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 | | #include "OgreStableHeaders.h" |
29 | | |
30 | | namespace Ogre { |
31 | | //--------------------------------------------------------------------- |
32 | | DefaultIntersectionSceneQuery::DefaultIntersectionSceneQuery(SceneManager* creator) |
33 | 0 | : IntersectionSceneQuery(creator) |
34 | 0 | { |
35 | 0 | } |
36 | | //--------------------------------------------------------------------- |
37 | | DefaultIntersectionSceneQuery::~DefaultIntersectionSceneQuery() |
38 | 0 | { |
39 | 0 | } |
40 | | //--------------------------------------------------------------------- |
41 | | void DefaultIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener) |
42 | 0 | { |
43 | | // Iterate over all movable types |
44 | 0 | const auto& factories = Root::getSingleton().getMovableObjectFactories(); |
45 | 0 | auto factIt = factories.begin(); |
46 | 0 | while(factIt != factories.end()) |
47 | 0 | { |
48 | 0 | const auto& objsA = mParentSceneMgr->getMovableObjects((factIt++)->first); |
49 | 0 | auto objItA = objsA.begin(); |
50 | 0 | while (objItA != objsA.end()) |
51 | 0 | { |
52 | 0 | MovableObject* a = (objItA++)->second; |
53 | | // skip entire section if type doesn't match |
54 | 0 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
55 | 0 | break; |
56 | | |
57 | | // Skip if a does not pass the mask |
58 | 0 | if (!(a->getQueryFlags() & mQueryMask) || !a->isInScene()) |
59 | 0 | continue; |
60 | | |
61 | | // Check against later objects in the same group |
62 | 0 | auto objItB = objItA; |
63 | 0 | while (objItB != objsA.end()) |
64 | 0 | { |
65 | 0 | MovableObject* b = (objItB++)->second; |
66 | | |
67 | | // Apply mask to b (both must pass) |
68 | 0 | if ((b->getQueryFlags() & mQueryMask) && b->isInScene()) |
69 | 0 | { |
70 | 0 | const AxisAlignedBox& box1 = a->getWorldBoundingBox(); |
71 | 0 | const AxisAlignedBox& box2 = b->getWorldBoundingBox(); |
72 | |
|
73 | 0 | if (box1.intersects(box2)) |
74 | 0 | { |
75 | 0 | if (!listener->queryResult(a, b)) return; |
76 | 0 | } |
77 | 0 | } |
78 | 0 | } |
79 | | // Check against later groups |
80 | 0 | auto factItLater = factIt; |
81 | 0 | while (factItLater != factories.end()) |
82 | 0 | { |
83 | 0 | for (const auto& objItC : |
84 | 0 | mParentSceneMgr->getMovableObjects((factItLater++)->first)) |
85 | 0 | { |
86 | 0 | MovableObject* c = objItC.second; |
87 | | // skip entire section if type doesn't match |
88 | 0 | if (!(c->getTypeFlags() & mQueryTypeMask)) |
89 | 0 | break; |
90 | | |
91 | | // Apply mask to c (both must pass) |
92 | 0 | if ((c->getQueryFlags() & mQueryMask) && c->isInScene()) |
93 | 0 | { |
94 | 0 | const AxisAlignedBox& box1 = a->getWorldBoundingBox(); |
95 | 0 | const AxisAlignedBox& box2 = c->getWorldBoundingBox(); |
96 | |
|
97 | 0 | if (box1.intersects(box2)) |
98 | 0 | { |
99 | 0 | if (!listener->queryResult(a, c)) return; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | } |
103 | |
|
104 | 0 | } |
105 | |
|
106 | 0 | } |
107 | | |
108 | |
|
109 | 0 | } |
110 | |
|
111 | 0 | } |
112 | | //--------------------------------------------------------------------- |
113 | | DefaultAxisAlignedBoxSceneQuery:: |
114 | | DefaultAxisAlignedBoxSceneQuery(SceneManager* creator) |
115 | 0 | : AxisAlignedBoxSceneQuery(creator) |
116 | 0 | { |
117 | 0 | } |
118 | | //--------------------------------------------------------------------- |
119 | | DefaultAxisAlignedBoxSceneQuery::~DefaultAxisAlignedBoxSceneQuery() |
120 | 0 | { |
121 | 0 | } |
122 | | //--------------------------------------------------------------------- |
123 | | void DefaultAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener) |
124 | 0 | { |
125 | | // Iterate over all movable types |
126 | 0 | for(const auto& factIt : Root::getSingleton().getMovableObjectFactories()) |
127 | 0 | { |
128 | 0 | for (const auto& objIt : mParentSceneMgr->getMovableObjects(factIt.first)) |
129 | 0 | { |
130 | 0 | MovableObject* a = objIt.second; |
131 | | // skip whole group if type doesn't match |
132 | 0 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
133 | 0 | break; |
134 | | |
135 | 0 | if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && |
136 | 0 | mAABB.intersects(a->getWorldBoundingBox())) |
137 | 0 | { |
138 | 0 | if (!listener->queryResult(a)) return; |
139 | 0 | } |
140 | 0 | } |
141 | 0 | } |
142 | 0 | } |
143 | | //--------------------------------------------------------------------- |
144 | | DefaultRaySceneQuery:: |
145 | 0 | DefaultRaySceneQuery(SceneManager* creator) : RaySceneQuery(creator) |
146 | 0 | { |
147 | 0 | } |
148 | | //--------------------------------------------------------------------- |
149 | | DefaultRaySceneQuery::~DefaultRaySceneQuery() |
150 | 0 | { |
151 | 0 | } |
152 | | //--------------------------------------------------------------------- |
153 | | void DefaultRaySceneQuery::execute(RaySceneQueryListener* listener) |
154 | 0 | { |
155 | | // Note that because we have no scene partitioning, we actually |
156 | | // perform a complete scene search even if restricted results are |
157 | | // requested; smarter scene manager queries can utilise the paritioning |
158 | | // of the scene in order to reduce the number of intersection tests |
159 | | // required to fulfil the query |
160 | | |
161 | | // Iterate over all movable types |
162 | 0 | for(const auto& factIt : Root::getSingleton().getMovableObjectFactories()) |
163 | 0 | { |
164 | 0 | for (const auto& objIt : mParentSceneMgr->getMovableObjects(factIt.first)) |
165 | 0 | { |
166 | 0 | MovableObject* a = objIt.second; |
167 | | // skip whole group if type doesn't match |
168 | 0 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
169 | 0 | break; |
170 | | |
171 | 0 | if ((a->getQueryFlags() & mQueryMask) && a->isInScene()) |
172 | 0 | { |
173 | | // Do ray / box test |
174 | 0 | std::pair<bool, Real> result = mRay.intersects(a->getWorldBoundingBox()); |
175 | |
|
176 | 0 | if (result.first) |
177 | 0 | { |
178 | 0 | if (!listener->queryResult(a, result.second)) return; |
179 | 0 | } |
180 | 0 | } |
181 | 0 | } |
182 | 0 | } |
183 | |
|
184 | 0 | } |
185 | | //--------------------------------------------------------------------- |
186 | | DefaultSphereSceneQuery:: |
187 | 0 | DefaultSphereSceneQuery(SceneManager* creator) : SphereSceneQuery(creator) |
188 | 0 | { |
189 | 0 | } |
190 | | //--------------------------------------------------------------------- |
191 | | DefaultSphereSceneQuery::~DefaultSphereSceneQuery() |
192 | 0 | { |
193 | 0 | } |
194 | | //--------------------------------------------------------------------- |
195 | | void DefaultSphereSceneQuery::execute(SceneQueryListener* listener) |
196 | 0 | { |
197 | | // Iterate over all movable types |
198 | 0 | for(const auto& factIt : Root::getSingleton().getMovableObjectFactories()) |
199 | 0 | { |
200 | 0 | for (const auto& objIt : mParentSceneMgr->getMovableObjects(factIt.first)) |
201 | 0 | { |
202 | 0 | MovableObject* a = objIt.second; |
203 | | // skip whole group if type doesn't match |
204 | 0 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
205 | 0 | break; |
206 | | // Skip unattached |
207 | 0 | if (!a->isInScene() || !(a->getQueryFlags() & mQueryMask)) |
208 | 0 | continue; |
209 | | |
210 | | // Do sphere / sphere test |
211 | 0 | if (mSphere.intersects(a->getWorldBoundingSphere())) |
212 | 0 | { |
213 | 0 | if (!listener->queryResult(a)) return; |
214 | 0 | } |
215 | 0 | } |
216 | 0 | } |
217 | 0 | } |
218 | | //--------------------------------------------------------------------- |
219 | | DefaultPlaneBoundedVolumeListSceneQuery:: |
220 | | DefaultPlaneBoundedVolumeListSceneQuery(SceneManager* creator) |
221 | 0 | : PlaneBoundedVolumeListSceneQuery(creator) |
222 | 0 | { |
223 | 0 | } |
224 | | //--------------------------------------------------------------------- |
225 | | DefaultPlaneBoundedVolumeListSceneQuery::~DefaultPlaneBoundedVolumeListSceneQuery() |
226 | 0 | { |
227 | 0 | } |
228 | | //--------------------------------------------------------------------- |
229 | | void DefaultPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) |
230 | 0 | { |
231 | | // Iterate over all movable types |
232 | 0 | for(const auto& factIt : Root::getSingleton().getMovableObjectFactories()) |
233 | 0 | { |
234 | 0 | for (const auto& objIt : mParentSceneMgr->getMovableObjects(factIt.first)) |
235 | 0 | { |
236 | 0 | MovableObject* a = objIt.second; |
237 | | // skip whole group if type doesn't match |
238 | 0 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
239 | 0 | break; |
240 | | |
241 | 0 | for (const auto& vol : mVolumes) |
242 | 0 | { |
243 | | // Do AABB / plane volume test |
244 | 0 | if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && |
245 | 0 | vol.intersects(a->getWorldBoundingBox())) |
246 | 0 | { |
247 | 0 | if (!listener->queryResult(a)) return; |
248 | 0 | break; |
249 | 0 | } |
250 | 0 | } |
251 | 0 | } |
252 | 0 | } |
253 | 0 | } |
254 | | } |