00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __SceneQuery_H__ 00029 #define __SceneQuery_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreAxisAlignedBox.h" 00033 #include "OgreSphere.h" 00034 #include "OgreRay.h" 00035 #include "OgreRenderOperation.h" 00036 #include "OgrePlaneBoundedVolume.h" 00037 00038 namespace Ogre { 00039 00040 // forward declaration 00041 class SceneQueryListener; 00073 class _OgreExport SceneQuery : public SceneMgtAlloc 00074 { 00075 public: 00082 enum WorldFragmentType { 00084 WFT_NONE, 00086 WFT_PLANE_BOUNDED_REGION, 00088 WFT_SINGLE_INTERSECTION, 00090 WFT_CUSTOM_GEOMETRY, 00092 WFT_RENDER_OPERATION 00093 }; 00094 00108 struct WorldFragment { 00110 WorldFragmentType fragmentType; 00112 Vector3 singleIntersection; 00114 list<Plane>::type* planes; 00116 void* geometry; 00118 RenderOperation* renderOp; 00119 00120 }; 00121 protected: 00122 SceneManager* mParentSceneMgr; 00123 uint32 mQueryMask; 00124 uint32 mQueryTypeMask; 00125 set<WorldFragmentType>::type mSupportedWorldFragments; 00126 WorldFragmentType mWorldFragmentType; 00127 00128 public: 00130 SceneQuery(SceneManager* mgr); 00131 virtual ~SceneQuery(); 00132 00142 virtual void setQueryMask(uint32 mask); 00144 virtual uint32 getQueryMask(void) const; 00145 00154 virtual void setQueryTypeMask(uint32 mask); 00156 virtual uint32 getQueryTypeMask(void) const; 00157 00168 virtual void setWorldFragmentType(enum WorldFragmentType wft); 00169 00171 virtual WorldFragmentType getWorldFragmentType(void) const; 00172 00174 virtual const set<WorldFragmentType>::type* getSupportedWorldFragmentTypes(void) const 00175 {return &mSupportedWorldFragments;} 00176 00177 00178 }; 00179 00186 class _OgreExport SceneQueryListener 00187 { 00188 public: 00189 virtual ~SceneQueryListener() { } 00195 virtual bool queryResult(MovableObject* object) = 0; 00201 virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0; 00202 00203 }; 00204 00205 typedef list<MovableObject*>::type SceneQueryResultMovableList; 00206 typedef list<SceneQuery::WorldFragment*>::type SceneQueryResultWorldFragmentList; 00208 struct _OgreExport SceneQueryResult : public SceneMgtAlloc 00209 { 00211 SceneQueryResultMovableList movables; 00213 SceneQueryResultWorldFragmentList worldFragments; 00214 }; 00215 00222 class _OgreExport RegionSceneQuery 00223 : public SceneQuery, public SceneQueryListener 00224 { 00225 protected: 00226 SceneQueryResult* mLastResult; 00227 public: 00229 RegionSceneQuery(SceneManager* mgr); 00230 virtual ~RegionSceneQuery(); 00239 virtual SceneQueryResult& execute(void); 00240 00248 virtual void execute(SceneQueryListener* listener) = 0; 00249 00253 virtual SceneQueryResult& getLastResults(void) const; 00260 virtual void clearResults(void); 00261 00263 bool queryResult(MovableObject* first); 00265 bool queryResult(SceneQuery::WorldFragment* fragment); 00266 }; 00267 00269 class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery 00270 { 00271 protected: 00272 AxisAlignedBox mAABB; 00273 public: 00274 AxisAlignedBoxSceneQuery(SceneManager* mgr); 00275 virtual ~AxisAlignedBoxSceneQuery(); 00276 00278 void setBox(const AxisAlignedBox& box); 00279 00281 const AxisAlignedBox& getBox(void) const; 00282 00283 }; 00284 00286 class _OgreExport SphereSceneQuery : public RegionSceneQuery 00287 { 00288 protected: 00289 Sphere mSphere; 00290 public: 00291 SphereSceneQuery(SceneManager* mgr); 00292 virtual ~SphereSceneQuery(); 00294 void setSphere(const Sphere& sphere); 00295 00297 const Sphere& getSphere() const; 00298 00299 }; 00300 00303 class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery 00304 { 00305 protected: 00306 PlaneBoundedVolumeList mVolumes; 00307 public: 00308 PlaneBoundedVolumeListSceneQuery(SceneManager* mgr); 00309 virtual ~PlaneBoundedVolumeListSceneQuery(); 00311 void setVolumes(const PlaneBoundedVolumeList& volumes); 00312 00314 const PlaneBoundedVolumeList& getVolumes() const; 00315 00316 }; 00317 00318 00319 /* 00321 class _OgreExport PyramidSceneQuery : public RegionSceneQuery 00322 { 00323 public: 00324 PyramidSceneQuery(SceneManager* mgr); 00325 virtual ~PyramidSceneQuery(); 00326 }; 00327 */ 00328 00334 class _OgreExport RaySceneQueryListener 00335 { 00336 public: 00337 virtual ~RaySceneQueryListener() { } 00344 virtual bool queryResult(MovableObject* obj, Real distance) = 0; 00345 00352 virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0; 00353 00354 }; 00355 00357 struct _OgreExport RaySceneQueryResultEntry 00358 { 00360 Real distance; 00362 MovableObject* movable; 00364 SceneQuery::WorldFragment* worldFragment; 00366 bool operator < (const RaySceneQueryResultEntry& rhs) const 00367 { 00368 return this->distance < rhs.distance; 00369 } 00370 00371 }; 00372 typedef vector<RaySceneQueryResultEntry>::type RaySceneQueryResult; 00373 00375 class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener 00376 { 00377 protected: 00378 Ray mRay; 00379 bool mSortByDistance; 00380 ushort mMaxResults; 00381 RaySceneQueryResult mResult; 00382 00383 public: 00384 RaySceneQuery(SceneManager* mgr); 00385 virtual ~RaySceneQuery(); 00387 virtual void setRay(const Ray& ray); 00389 virtual const Ray& getRay(void) const; 00408 virtual void setSortByDistance(bool sort, ushort maxresults = 0); 00410 virtual bool getSortByDistance(void) const; 00413 virtual ushort getMaxResults(void) const; 00422 virtual RaySceneQueryResult& execute(void); 00423 00431 virtual void execute(RaySceneQueryListener* listener) = 0; 00432 00436 virtual RaySceneQueryResult& getLastResults(void); 00443 virtual void clearResults(void); 00444 00446 bool queryResult(MovableObject* obj, Real distance); 00448 bool queryResult(SceneQuery::WorldFragment* fragment, Real distance); 00449 00450 00451 00452 00453 }; 00454 00460 class _OgreExport IntersectionSceneQueryListener 00461 { 00462 public: 00463 virtual ~IntersectionSceneQueryListener() { } 00470 virtual bool queryResult(MovableObject* first, MovableObject* second) = 0; 00471 00478 virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0; 00479 00480 /* NB there are no results for world fragments intersecting other world fragments; 00481 it is assumed that world geometry is either static or at least that self-intersections 00482 are irrelevant or dealt with elsewhere (such as the custom scene manager) */ 00483 00484 00485 }; 00486 00487 typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair; 00488 typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair; 00489 typedef list<SceneQueryMovableObjectPair>::type SceneQueryMovableIntersectionList; 00490 typedef list<SceneQueryMovableObjectWorldFragmentPair>::type SceneQueryMovableWorldFragmentIntersectionList; 00492 struct _OgreExport IntersectionSceneQueryResult : public SceneMgtAlloc 00493 { 00495 SceneQueryMovableIntersectionList movables2movables; 00497 SceneQueryMovableWorldFragmentIntersectionList movables2world; 00498 00499 00500 00501 }; 00502 00511 class _OgreExport IntersectionSceneQuery 00512 : public SceneQuery, public IntersectionSceneQueryListener 00513 { 00514 protected: 00515 IntersectionSceneQueryResult* mLastResult; 00516 public: 00517 IntersectionSceneQuery(SceneManager* mgr); 00518 virtual ~IntersectionSceneQuery(); 00519 00528 virtual IntersectionSceneQueryResult& execute(void); 00529 00537 virtual void execute(IntersectionSceneQueryListener* listener) = 0; 00538 00542 virtual IntersectionSceneQueryResult& getLastResults(void) const; 00549 virtual void clearResults(void); 00550 00552 bool queryResult(MovableObject* first, MovableObject* second); 00554 bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment); 00555 }; 00556 00560 } 00561 00562 00563 00564 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:26 2012