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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgreSceneQuery.h"
|
---|
27 | #include "OgreException.h"
|
---|
28 |
|
---|
29 | namespace Ogre {
|
---|
30 |
|
---|
31 | //-----------------------------------------------------------------------
|
---|
32 | SceneQuery::SceneQuery(SceneManager* mgr)
|
---|
33 | : mParentSceneMgr(mgr), mQueryMask(0xFFFFFFFF), mWorldFragmentType(SceneQuery::WFT_NONE)
|
---|
34 | {
|
---|
35 | }
|
---|
36 | //-----------------------------------------------------------------------
|
---|
37 | SceneQuery::~SceneQuery()
|
---|
38 | {
|
---|
39 | }
|
---|
40 | //-----------------------------------------------------------------------
|
---|
41 | void SceneQuery::setQueryMask(unsigned long mask)
|
---|
42 | {
|
---|
43 | mQueryMask = mask;
|
---|
44 | }
|
---|
45 | //-----------------------------------------------------------------------
|
---|
46 | unsigned long SceneQuery::getQueryMask(void) const
|
---|
47 | {
|
---|
48 | return mQueryMask;
|
---|
49 | }
|
---|
50 | //-----------------------------------------------------------------------
|
---|
51 | void SceneQuery::setWorldFragmentType(enum SceneQuery::WorldFragmentType wft)
|
---|
52 | {
|
---|
53 | // Check supported
|
---|
54 | if (mSupportedWorldFragments.find(wft) == mSupportedWorldFragments.end())
|
---|
55 | {
|
---|
56 | OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "This world fragment type is not supported.",
|
---|
57 | "SceneQuery::setWorldFragmentType");
|
---|
58 | }
|
---|
59 | mWorldFragmentType = wft;
|
---|
60 | }
|
---|
61 | //-----------------------------------------------------------------------
|
---|
62 | SceneQuery::WorldFragmentType
|
---|
63 | SceneQuery::getWorldFragmentType(void) const
|
---|
64 | {
|
---|
65 | return mWorldFragmentType;
|
---|
66 | }
|
---|
67 | //-----------------------------------------------------------------------
|
---|
68 | RegionSceneQuery::RegionSceneQuery(SceneManager* mgr)
|
---|
69 | :SceneQuery(mgr), mLastResult(NULL)
|
---|
70 | {
|
---|
71 | }
|
---|
72 | //-----------------------------------------------------------------------
|
---|
73 | RegionSceneQuery::~RegionSceneQuery()
|
---|
74 | {
|
---|
75 | clearResults();
|
---|
76 | }
|
---|
77 | //-----------------------------------------------------------------------
|
---|
78 | SceneQueryResult& RegionSceneQuery::getLastResults(void) const
|
---|
79 | {
|
---|
80 | assert(mLastResult);
|
---|
81 | return *mLastResult;
|
---|
82 | }
|
---|
83 | //-----------------------------------------------------------------------
|
---|
84 | void RegionSceneQuery::clearResults(void)
|
---|
85 | {
|
---|
86 | if (mLastResult)
|
---|
87 | {
|
---|
88 | delete mLastResult;
|
---|
89 | }
|
---|
90 | mLastResult = NULL;
|
---|
91 | }
|
---|
92 | //---------------------------------------------------------------------
|
---|
93 | SceneQueryResult&
|
---|
94 | RegionSceneQuery::execute(void)
|
---|
95 | {
|
---|
96 | clearResults();
|
---|
97 | mLastResult = new SceneQueryResult();
|
---|
98 | // Call callback version with self as listener
|
---|
99 | execute(this);
|
---|
100 | return *mLastResult;
|
---|
101 | }
|
---|
102 | //---------------------------------------------------------------------
|
---|
103 | bool RegionSceneQuery::
|
---|
104 | queryResult(MovableObject* obj)
|
---|
105 | {
|
---|
106 | // Add to internal list
|
---|
107 | mLastResult->movables.push_back(obj);
|
---|
108 | // Continue
|
---|
109 | return true;
|
---|
110 | }
|
---|
111 | //---------------------------------------------------------------------
|
---|
112 | bool RegionSceneQuery::queryResult(SceneQuery::WorldFragment* fragment)
|
---|
113 | {
|
---|
114 | // Add to internal list
|
---|
115 | mLastResult->worldFragments.push_back(fragment);
|
---|
116 | // Continue
|
---|
117 | return true;
|
---|
118 | }
|
---|
119 | //-----------------------------------------------------------------------
|
---|
120 | AxisAlignedBoxSceneQuery::AxisAlignedBoxSceneQuery(SceneManager* mgr)
|
---|
121 | : RegionSceneQuery(mgr)
|
---|
122 | {
|
---|
123 | }
|
---|
124 | //-----------------------------------------------------------------------
|
---|
125 | AxisAlignedBoxSceneQuery::~AxisAlignedBoxSceneQuery()
|
---|
126 | {
|
---|
127 | }
|
---|
128 | //-----------------------------------------------------------------------
|
---|
129 | void AxisAlignedBoxSceneQuery::setBox(const AxisAlignedBox& box)
|
---|
130 | {
|
---|
131 | mAABB = box;
|
---|
132 | }
|
---|
133 | //-----------------------------------------------------------------------
|
---|
134 | const AxisAlignedBox& AxisAlignedBoxSceneQuery::getBox(void) const
|
---|
135 | {
|
---|
136 | return mAABB;
|
---|
137 | }
|
---|
138 | //-----------------------------------------------------------------------
|
---|
139 | SphereSceneQuery::SphereSceneQuery(SceneManager* mgr)
|
---|
140 | : RegionSceneQuery(mgr)
|
---|
141 | {
|
---|
142 | }
|
---|
143 | //-----------------------------------------------------------------------
|
---|
144 | SphereSceneQuery::~SphereSceneQuery()
|
---|
145 | {
|
---|
146 | }
|
---|
147 | //-----------------------------------------------------------------------
|
---|
148 | void SphereSceneQuery::setSphere(const Sphere& sphere)
|
---|
149 | {
|
---|
150 | mSphere = sphere;
|
---|
151 | }
|
---|
152 | //-----------------------------------------------------------------------
|
---|
153 | const Sphere& SphereSceneQuery::getSphere() const
|
---|
154 | {
|
---|
155 | return mSphere;
|
---|
156 | }
|
---|
157 |
|
---|
158 | //-----------------------------------------------------------------------
|
---|
159 | PlaneBoundedVolumeListSceneQuery::PlaneBoundedVolumeListSceneQuery(SceneManager* mgr)
|
---|
160 | : RegionSceneQuery(mgr)
|
---|
161 | {
|
---|
162 | }
|
---|
163 | //-----------------------------------------------------------------------
|
---|
164 | PlaneBoundedVolumeListSceneQuery::~PlaneBoundedVolumeListSceneQuery()
|
---|
165 | {
|
---|
166 | }
|
---|
167 | //-----------------------------------------------------------------------
|
---|
168 | void PlaneBoundedVolumeListSceneQuery::setVolumes(const PlaneBoundedVolumeList& volumes)
|
---|
169 | {
|
---|
170 | mVolumes = volumes;
|
---|
171 | }
|
---|
172 | //-----------------------------------------------------------------------
|
---|
173 | const PlaneBoundedVolumeList& PlaneBoundedVolumeListSceneQuery::getVolumes() const
|
---|
174 | {
|
---|
175 | return mVolumes;
|
---|
176 | }
|
---|
177 |
|
---|
178 | //-----------------------------------------------------------------------
|
---|
179 | RaySceneQuery::RaySceneQuery(SceneManager* mgr) : SceneQuery(mgr)
|
---|
180 | {
|
---|
181 | mSortByDistance = false;
|
---|
182 | mMaxResults = 0;
|
---|
183 | mLastResult = NULL;
|
---|
184 | }
|
---|
185 | //-----------------------------------------------------------------------
|
---|
186 | RaySceneQuery::~RaySceneQuery()
|
---|
187 | {
|
---|
188 | clearResults();
|
---|
189 | }
|
---|
190 | //-----------------------------------------------------------------------
|
---|
191 | void RaySceneQuery::setRay(const Ray& ray)
|
---|
192 | {
|
---|
193 | mRay = ray;
|
---|
194 | }
|
---|
195 | //-----------------------------------------------------------------------
|
---|
196 | const Ray& RaySceneQuery::getRay(void) const
|
---|
197 | {
|
---|
198 | return mRay;
|
---|
199 | }
|
---|
200 | //-----------------------------------------------------------------------
|
---|
201 | void RaySceneQuery::setSortByDistance(bool sort, ushort maxresults)
|
---|
202 | {
|
---|
203 | mSortByDistance = sort;
|
---|
204 | mMaxResults = maxresults;
|
---|
205 | }
|
---|
206 | //-----------------------------------------------------------------------
|
---|
207 | bool RaySceneQuery::getSortByDistance(void) const
|
---|
208 | {
|
---|
209 | return mSortByDistance;
|
---|
210 | }
|
---|
211 | //-----------------------------------------------------------------------
|
---|
212 | ushort RaySceneQuery::getMaxResults(void) const
|
---|
213 | {
|
---|
214 | return mMaxResults;
|
---|
215 | }
|
---|
216 | //-----------------------------------------------------------------------
|
---|
217 | RaySceneQueryResult& RaySceneQuery::execute(void)
|
---|
218 | {
|
---|
219 | clearResults();
|
---|
220 | mLastResult = new RaySceneQueryResult();
|
---|
221 | // Call callback version with self as listener
|
---|
222 | this->execute(this);
|
---|
223 |
|
---|
224 | if (mSortByDistance)
|
---|
225 | {
|
---|
226 | // Perform sort
|
---|
227 | mLastResult->sort();
|
---|
228 |
|
---|
229 | if (mMaxResults && mLastResult->size() > mMaxResults)
|
---|
230 | {
|
---|
231 | // Constrain to maxresults
|
---|
232 | RaySceneQueryResult::iterator start;
|
---|
233 | int x = 0;
|
---|
234 | for(start = mLastResult->begin(); x < mMaxResults; ++x)
|
---|
235 | {
|
---|
236 | // Increment deletion start point
|
---|
237 | ++start;
|
---|
238 | }
|
---|
239 | // erase
|
---|
240 | mLastResult->erase(start, mLastResult->end());
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | return *mLastResult;
|
---|
245 |
|
---|
246 | }
|
---|
247 | //-----------------------------------------------------------------------
|
---|
248 | RaySceneQueryResult& RaySceneQuery::getLastResults(void) const
|
---|
249 | {
|
---|
250 | assert (mLastResult);
|
---|
251 | return *mLastResult;
|
---|
252 | }
|
---|
253 | //-----------------------------------------------------------------------
|
---|
254 | void RaySceneQuery::clearResults(void)
|
---|
255 | {
|
---|
256 | if (mLastResult)
|
---|
257 | {
|
---|
258 | delete mLastResult;
|
---|
259 | }
|
---|
260 | mLastResult = NULL;
|
---|
261 | }
|
---|
262 | //-----------------------------------------------------------------------
|
---|
263 | bool RaySceneQuery::queryResult(MovableObject* obj, Real distance)
|
---|
264 | {
|
---|
265 | // Add to internal list
|
---|
266 | RaySceneQueryResultEntry dets;
|
---|
267 | dets.distance = distance;
|
---|
268 | dets.movable = obj;
|
---|
269 | dets.worldFragment = NULL;
|
---|
270 | mLastResult->push_back(dets);
|
---|
271 | // Continue
|
---|
272 | return true;
|
---|
273 | }
|
---|
274 | //-----------------------------------------------------------------------
|
---|
275 | bool RaySceneQuery::queryResult(SceneQuery::WorldFragment* fragment, Real distance)
|
---|
276 | {
|
---|
277 | // Add to internal list
|
---|
278 | RaySceneQueryResultEntry dets;
|
---|
279 | dets.distance = distance;
|
---|
280 | dets.movable = NULL;
|
---|
281 | dets.worldFragment = fragment;
|
---|
282 | mLastResult->push_back(dets);
|
---|
283 | // Continue
|
---|
284 | return true;
|
---|
285 | }
|
---|
286 | //-----------------------------------------------------------------------
|
---|
287 | /*
|
---|
288 | PyramidSceneQuery::PyramidSceneQuery(SceneManager* mgr) : RegionSceneQuery(mgr)
|
---|
289 | {
|
---|
290 | }
|
---|
291 | //-----------------------------------------------------------------------
|
---|
292 | PyramidSceneQuery::~PyramidSceneQuery()
|
---|
293 | {
|
---|
294 | }
|
---|
295 | */
|
---|
296 | //-----------------------------------------------------------------------
|
---|
297 | IntersectionSceneQuery::IntersectionSceneQuery(SceneManager* mgr)
|
---|
298 | : SceneQuery(mgr), mLastResult(NULL)
|
---|
299 | {
|
---|
300 | }
|
---|
301 | //-----------------------------------------------------------------------
|
---|
302 | IntersectionSceneQuery::~IntersectionSceneQuery()
|
---|
303 | {
|
---|
304 | clearResults();
|
---|
305 | }
|
---|
306 | //-----------------------------------------------------------------------
|
---|
307 | IntersectionSceneQueryResult& IntersectionSceneQuery::getLastResults(void) const
|
---|
308 | {
|
---|
309 | assert(mLastResult);
|
---|
310 | return *mLastResult;
|
---|
311 | }
|
---|
312 | //-----------------------------------------------------------------------
|
---|
313 | void IntersectionSceneQuery::clearResults(void)
|
---|
314 | {
|
---|
315 | if (mLastResult)
|
---|
316 | {
|
---|
317 | delete mLastResult;
|
---|
318 | }
|
---|
319 | mLastResult = NULL;
|
---|
320 | }
|
---|
321 | //---------------------------------------------------------------------
|
---|
322 | IntersectionSceneQueryResult&
|
---|
323 | IntersectionSceneQuery::execute(void)
|
---|
324 | {
|
---|
325 | clearResults();
|
---|
326 | mLastResult = new IntersectionSceneQueryResult();
|
---|
327 | // Call callback version with self as listener
|
---|
328 | execute(this);
|
---|
329 | return *mLastResult;
|
---|
330 | }
|
---|
331 | //---------------------------------------------------------------------
|
---|
332 | bool IntersectionSceneQuery::
|
---|
333 | queryResult(MovableObject* first, MovableObject* second)
|
---|
334 | {
|
---|
335 | // Add to internal list
|
---|
336 | mLastResult->movables2movables.push_back(
|
---|
337 | SceneQueryMovableObjectPair(first, second)
|
---|
338 | );
|
---|
339 | // Continue
|
---|
340 | return true;
|
---|
341 | }
|
---|
342 | //---------------------------------------------------------------------
|
---|
343 | bool IntersectionSceneQuery::
|
---|
344 | queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment)
|
---|
345 | {
|
---|
346 | // Add to internal list
|
---|
347 | mLastResult->movables2world.push_back(
|
---|
348 | SceneQueryMovableObjectWorldFragmentPair(movable, fragment)
|
---|
349 | );
|
---|
350 | // Continue
|
---|
351 | return true;
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 |
|
---|
357 | }
|
---|
358 |
|
---|
359 |
|
---|
360 |
|
---|
361 |
|
---|