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-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | #include "OgreSceneManager.h" |
---|
31 | #include "OgreEntity.h" |
---|
32 | #include "OgreRoot.h" |
---|
33 | |
---|
34 | namespace Ogre { |
---|
35 | //--------------------------------------------------------------------- |
---|
36 | DefaultIntersectionSceneQuery::DefaultIntersectionSceneQuery(SceneManager* creator) |
---|
37 | : IntersectionSceneQuery(creator) |
---|
38 | { |
---|
39 | // No world geometry results supported |
---|
40 | mSupportedWorldFragments.insert(SceneQuery::WFT_NONE); |
---|
41 | } |
---|
42 | //--------------------------------------------------------------------- |
---|
43 | DefaultIntersectionSceneQuery::~DefaultIntersectionSceneQuery() |
---|
44 | { |
---|
45 | } |
---|
46 | //--------------------------------------------------------------------- |
---|
47 | void DefaultIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener) |
---|
48 | { |
---|
49 | // Iterate over all movable types |
---|
50 | Root::MovableObjectFactoryIterator factIt = |
---|
51 | Root::getSingleton().getMovableObjectFactoryIterator(); |
---|
52 | while(factIt.hasMoreElements()) |
---|
53 | { |
---|
54 | SceneManager::MovableObjectIterator objItA = |
---|
55 | mParentSceneMgr->getMovableObjectIterator( |
---|
56 | factIt.getNext()->getType()); |
---|
57 | while (objItA.hasMoreElements()) |
---|
58 | { |
---|
59 | MovableObject* a = objItA.getNext(); |
---|
60 | // skip entire section if type doesn't match |
---|
61 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
---|
62 | break; |
---|
63 | |
---|
64 | // Skip if a does not pass the mask |
---|
65 | if (!(a->getQueryFlags() & mQueryMask) || |
---|
66 | !a->isInScene()) |
---|
67 | continue; |
---|
68 | |
---|
69 | // Check against later objects in the same group |
---|
70 | SceneManager::MovableObjectIterator objItB = objItA; |
---|
71 | while (objItB.hasMoreElements()) |
---|
72 | { |
---|
73 | MovableObject* b = objItB.getNext(); |
---|
74 | |
---|
75 | // Apply mask to b (both must pass) |
---|
76 | if ((b->getQueryFlags() & mQueryMask) && |
---|
77 | b->isInScene()) |
---|
78 | { |
---|
79 | const AxisAlignedBox& box1 = a->getWorldBoundingBox(); |
---|
80 | const AxisAlignedBox& box2 = b->getWorldBoundingBox(); |
---|
81 | |
---|
82 | if (box1.intersects(box2)) |
---|
83 | { |
---|
84 | if (!listener->queryResult(a, b)) return; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | // Check against later groups |
---|
89 | Root::MovableObjectFactoryIterator factItLater = factIt; |
---|
90 | while (factItLater.hasMoreElements()) |
---|
91 | { |
---|
92 | SceneManager::MovableObjectIterator objItC = |
---|
93 | mParentSceneMgr->getMovableObjectIterator( |
---|
94 | factItLater.getNext()->getType()); |
---|
95 | while (objItC.hasMoreElements()) |
---|
96 | { |
---|
97 | MovableObject* c = objItC.getNext(); |
---|
98 | // skip entire section if type doesn't match |
---|
99 | if (!(c->getTypeFlags() & mQueryTypeMask)) |
---|
100 | break; |
---|
101 | |
---|
102 | // Apply mask to c (both must pass) |
---|
103 | if ((c->getQueryFlags() & mQueryMask) && |
---|
104 | c->isInScene()) |
---|
105 | { |
---|
106 | const AxisAlignedBox& box1 = a->getWorldBoundingBox(); |
---|
107 | const AxisAlignedBox& box2 = c->getWorldBoundingBox(); |
---|
108 | |
---|
109 | if (box1.intersects(box2)) |
---|
110 | { |
---|
111 | if (!listener->queryResult(a, c)) return; |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|
124 | //--------------------------------------------------------------------- |
---|
125 | DefaultAxisAlignedBoxSceneQuery:: |
---|
126 | DefaultAxisAlignedBoxSceneQuery(SceneManager* creator) |
---|
127 | : AxisAlignedBoxSceneQuery(creator) |
---|
128 | { |
---|
129 | // No world geometry results supported |
---|
130 | mSupportedWorldFragments.insert(SceneQuery::WFT_NONE); |
---|
131 | } |
---|
132 | //--------------------------------------------------------------------- |
---|
133 | DefaultAxisAlignedBoxSceneQuery::~DefaultAxisAlignedBoxSceneQuery() |
---|
134 | { |
---|
135 | } |
---|
136 | //--------------------------------------------------------------------- |
---|
137 | void DefaultAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener) |
---|
138 | { |
---|
139 | // Iterate over all movable types |
---|
140 | Root::MovableObjectFactoryIterator factIt = |
---|
141 | Root::getSingleton().getMovableObjectFactoryIterator(); |
---|
142 | while(factIt.hasMoreElements()) |
---|
143 | { |
---|
144 | SceneManager::MovableObjectIterator objItA = |
---|
145 | mParentSceneMgr->getMovableObjectIterator( |
---|
146 | factIt.getNext()->getType()); |
---|
147 | while (objItA.hasMoreElements()) |
---|
148 | { |
---|
149 | MovableObject* a = objItA.getNext(); |
---|
150 | // skip whole group if type doesn't match |
---|
151 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
---|
152 | break; |
---|
153 | |
---|
154 | if ((a->getQueryFlags() & mQueryMask) && |
---|
155 | a->isInScene() && |
---|
156 | mAABB.intersects(a->getWorldBoundingBox())) |
---|
157 | { |
---|
158 | if (!listener->queryResult(a)) return; |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | //--------------------------------------------------------------------- |
---|
164 | DefaultRaySceneQuery:: |
---|
165 | DefaultRaySceneQuery(SceneManager* creator) : RaySceneQuery(creator) |
---|
166 | { |
---|
167 | // No world geometry results supported |
---|
168 | mSupportedWorldFragments.insert(SceneQuery::WFT_NONE); |
---|
169 | } |
---|
170 | //--------------------------------------------------------------------- |
---|
171 | DefaultRaySceneQuery::~DefaultRaySceneQuery() |
---|
172 | { |
---|
173 | } |
---|
174 | //--------------------------------------------------------------------- |
---|
175 | void DefaultRaySceneQuery::execute(RaySceneQueryListener* listener) |
---|
176 | { |
---|
177 | // Note that becuase we have no scene partitioning, we actually |
---|
178 | // perform a complete scene search even if restricted results are |
---|
179 | // requested; smarter scene manager queries can utilise the paritioning |
---|
180 | // of the scene in order to reduce the number of intersection tests |
---|
181 | // required to fulfil the query |
---|
182 | |
---|
183 | // Iterate over all movable types |
---|
184 | Root::MovableObjectFactoryIterator factIt = |
---|
185 | Root::getSingleton().getMovableObjectFactoryIterator(); |
---|
186 | while(factIt.hasMoreElements()) |
---|
187 | { |
---|
188 | SceneManager::MovableObjectIterator objItA = |
---|
189 | mParentSceneMgr->getMovableObjectIterator( |
---|
190 | factIt.getNext()->getType()); |
---|
191 | while (objItA.hasMoreElements()) |
---|
192 | { |
---|
193 | MovableObject* a = objItA.getNext(); |
---|
194 | // skip whole group if type doesn't match |
---|
195 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
---|
196 | break; |
---|
197 | |
---|
198 | if( (a->getQueryFlags() & mQueryMask) && |
---|
199 | a->isInScene()) |
---|
200 | { |
---|
201 | // Do ray / box test |
---|
202 | std::pair<bool, Real> result = |
---|
203 | mRay.intersects(a->getWorldBoundingBox()); |
---|
204 | |
---|
205 | if (result.first) |
---|
206 | { |
---|
207 | if (!listener->queryResult(a, result.second)) return; |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | } |
---|
214 | //--------------------------------------------------------------------- |
---|
215 | DefaultSphereSceneQuery:: |
---|
216 | DefaultSphereSceneQuery(SceneManager* creator) : SphereSceneQuery(creator) |
---|
217 | { |
---|
218 | // No world geometry results supported |
---|
219 | mSupportedWorldFragments.insert(SceneQuery::WFT_NONE); |
---|
220 | } |
---|
221 | //--------------------------------------------------------------------- |
---|
222 | DefaultSphereSceneQuery::~DefaultSphereSceneQuery() |
---|
223 | { |
---|
224 | } |
---|
225 | //--------------------------------------------------------------------- |
---|
226 | void DefaultSphereSceneQuery::execute(SceneQueryListener* listener) |
---|
227 | { |
---|
228 | Sphere testSphere; |
---|
229 | |
---|
230 | // Iterate over all movable types |
---|
231 | Root::MovableObjectFactoryIterator factIt = |
---|
232 | Root::getSingleton().getMovableObjectFactoryIterator(); |
---|
233 | while(factIt.hasMoreElements()) |
---|
234 | { |
---|
235 | SceneManager::MovableObjectIterator objItA = |
---|
236 | mParentSceneMgr->getMovableObjectIterator( |
---|
237 | factIt.getNext()->getType()); |
---|
238 | while (objItA.hasMoreElements()) |
---|
239 | { |
---|
240 | MovableObject* a = objItA.getNext(); |
---|
241 | // skip whole group if type doesn't match |
---|
242 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
---|
243 | break; |
---|
244 | // Skip unattached |
---|
245 | if (!a->isInScene() || |
---|
246 | !(a->getQueryFlags() & mQueryMask)) |
---|
247 | continue; |
---|
248 | |
---|
249 | // Do sphere / sphere test |
---|
250 | testSphere.setCenter(a->getParentNode()->_getDerivedPosition()); |
---|
251 | testSphere.setRadius(a->getBoundingRadius()); |
---|
252 | if (mSphere.intersects(testSphere)) |
---|
253 | { |
---|
254 | if (!listener->queryResult(a)) return; |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | //--------------------------------------------------------------------- |
---|
260 | DefaultPlaneBoundedVolumeListSceneQuery:: |
---|
261 | DefaultPlaneBoundedVolumeListSceneQuery(SceneManager* creator) |
---|
262 | : PlaneBoundedVolumeListSceneQuery(creator) |
---|
263 | { |
---|
264 | // No world geometry results supported |
---|
265 | mSupportedWorldFragments.insert(SceneQuery::WFT_NONE); |
---|
266 | } |
---|
267 | //--------------------------------------------------------------------- |
---|
268 | DefaultPlaneBoundedVolumeListSceneQuery::~DefaultPlaneBoundedVolumeListSceneQuery() |
---|
269 | { |
---|
270 | } |
---|
271 | //--------------------------------------------------------------------- |
---|
272 | void DefaultPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) |
---|
273 | { |
---|
274 | // Iterate over all movable types |
---|
275 | Root::MovableObjectFactoryIterator factIt = |
---|
276 | Root::getSingleton().getMovableObjectFactoryIterator(); |
---|
277 | while(factIt.hasMoreElements()) |
---|
278 | { |
---|
279 | SceneManager::MovableObjectIterator objItA = |
---|
280 | mParentSceneMgr->getMovableObjectIterator( |
---|
281 | factIt.getNext()->getType()); |
---|
282 | while (objItA.hasMoreElements()) |
---|
283 | { |
---|
284 | MovableObject* a = objItA.getNext(); |
---|
285 | // skip whole group if type doesn't match |
---|
286 | if (!(a->getTypeFlags() & mQueryTypeMask)) |
---|
287 | break; |
---|
288 | |
---|
289 | PlaneBoundedVolumeList::iterator pi, piend; |
---|
290 | piend = mVolumes.end(); |
---|
291 | for (pi = mVolumes.begin(); pi != piend; ++pi) |
---|
292 | { |
---|
293 | PlaneBoundedVolume& vol = *pi; |
---|
294 | // Do AABB / plane volume test |
---|
295 | if ((a->getQueryFlags() & mQueryMask) && |
---|
296 | a->isInScene() && |
---|
297 | vol.intersects(a->getWorldBoundingBox())) |
---|
298 | { |
---|
299 | if (!listener->queryResult(a)) return; |
---|
300 | break; |
---|
301 | } |
---|
302 | } |
---|
303 | } |
---|
304 | } |
---|
305 | } |
---|
306 | } |
---|