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