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 © 2000-2003 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef __SceneQuery_H__ 00026 #define __SceneQuery_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 #include "OgreAxisAlignedBox.h" 00030 #include "OgreSphere.h" 00031 #include "OgreRay.h" 00032 #include "OgreRenderOperation.h" 00033 00034 namespace Ogre { 00035 00036 // forward declaration 00037 class SceneQueryListener; 00063 class _OgreExport SceneQuery 00064 { 00065 public: 00072 enum WorldFragmentType { 00074 WFT_NONE, 00076 WFT_PLANE_BOUNDED_REGION, 00078 WFT_SINGLE_INTERSECTION, 00080 WFT_CUSTOM_GEOMETRY, 00082 WFT_RENDER_OPERATION 00083 }; 00084 00098 struct WorldFragment { 00100 WorldFragmentType fragmentType; 00102 Vector3 singleIntersection; 00104 std::list<Plane>* planes; 00106 void* geometry; 00108 RenderOperation* renderOp; 00109 00110 }; 00111 protected: 00112 SceneManager* mParentSceneMgr; 00113 unsigned long mQueryMask; 00114 std::set<WorldFragmentType> mSupportedWorldFragments; 00115 WorldFragmentType mWorldFragmentType; 00116 00117 public: 00119 SceneQuery(SceneManager* mgr); 00120 virtual ~SceneQuery(); 00121 00131 virtual void setQueryMask(unsigned long mask); 00133 virtual unsigned long getQueryMask(void) const; 00134 00145 virtual void setWorldFragmentType(enum WorldFragmentType wft); 00146 00148 virtual WorldFragmentType getWorldFragmentType(void) const; 00149 00151 virtual const std::set<WorldFragmentType>* getSupportedWorldFragmentTypes(void) const 00152 {return &mSupportedWorldFragments;} 00153 00154 00155 }; 00156 00163 class _OgreExport SceneQueryListener 00164 { 00165 public: 00171 virtual bool queryResult(MovableObject* object) = 0; 00177 virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0; 00178 00179 }; 00180 00181 typedef std::list<MovableObject*> SceneQueryResultMovableList; 00182 typedef std::list<SceneQuery::WorldFragment*> SceneQueryResultWorldFragmentList; 00184 struct _OgreExport SceneQueryResult 00185 { 00187 SceneQueryResultMovableList movables; 00189 SceneQueryResultWorldFragmentList worldFragments; 00190 }; 00191 00198 class _OgreExport RegionSceneQuery 00199 : public SceneQuery, public SceneQueryListener 00200 { 00201 protected: 00202 SceneQueryResult* mLastResult; 00203 public: 00205 RegionSceneQuery(SceneManager* mgr); 00206 virtual ~RegionSceneQuery(); 00215 virtual SceneQueryResult& execute(void); 00216 00224 virtual void execute(SceneQueryListener* listener) = 0; 00225 00229 virtual SceneQueryResult& getLastResults(void) const; 00236 virtual void clearResults(void); 00237 00239 bool queryResult(MovableObject* first); 00241 bool queryResult(SceneQuery::WorldFragment* fragment); 00242 }; 00243 00245 class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery 00246 { 00247 protected: 00248 AxisAlignedBox mAABB; 00249 public: 00250 AxisAlignedBoxSceneQuery(SceneManager* mgr); 00251 virtual ~AxisAlignedBoxSceneQuery(); 00252 00254 void setBox(const AxisAlignedBox& box); 00255 00257 const AxisAlignedBox& getBox(void) const; 00258 00259 }; 00260 00262 class _OgreExport SphereSceneQuery : public RegionSceneQuery 00263 { 00264 protected: 00265 Sphere mSphere; 00266 public: 00267 SphereSceneQuery(SceneManager* mgr); 00268 virtual ~SphereSceneQuery(); 00270 void setSphere(const Sphere& sphere); 00271 00273 const Sphere& getSphere() const; 00274 00275 }; 00276 00277 /* 00279 class _OgreExport PyramidSceneQuery : public RegionSceneQuery 00280 { 00281 public: 00282 PyramidSceneQuery(SceneManager* mgr); 00283 virtual ~PyramidSceneQuery(); 00284 }; 00285 */ 00286 00292 class _OgreExport RaySceneQueryListener 00293 { 00294 public: 00301 virtual bool queryResult(MovableObject* obj, Real distance) = 0; 00302 00309 virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0; 00310 00311 }; 00312 00314 struct _OgreExport RaySceneQueryResultEntry 00315 { 00317 Real distance; 00319 MovableObject* movable; 00321 SceneQuery::WorldFragment* worldFragment; 00323 bool operator < (const RaySceneQueryResultEntry& rhs) const 00324 { 00325 return this->distance < rhs.distance; 00326 } 00327 00328 }; 00329 typedef std::list<RaySceneQueryResultEntry> RaySceneQueryResult; 00330 00332 class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener 00333 { 00334 protected: 00335 Ray mRay; 00336 bool mSortByDistance; 00337 ushort mMaxResults; 00338 RaySceneQueryResult* mLastResult; 00339 00340 public: 00341 RaySceneQuery(SceneManager* mgr); 00342 virtual ~RaySceneQuery(); 00344 void setRay(const Ray& ray); 00346 const Ray& getRay(void) const; 00365 void setSortByDistance(bool sort, ushort maxresults = 0); 00367 bool getSortByDistance(void) const; 00370 ushort getMaxResults(void) const; 00379 virtual RaySceneQueryResult& execute(void); 00380 00388 virtual void execute(RaySceneQueryListener* listener) = 0; 00389 00393 virtual RaySceneQueryResult& getLastResults(void) const; 00400 virtual void clearResults(void); 00401 00403 bool queryResult(MovableObject* obj, Real distance); 00405 bool queryResult(SceneQuery::WorldFragment* fragment, Real distance); 00406 00407 00408 00409 00410 }; 00411 00417 class _OgreExport IntersectionSceneQueryListener 00418 { 00419 public: 00426 virtual bool queryResult(MovableObject* first, MovableObject* second) = 0; 00427 00434 virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0; 00435 00436 /* NB there are no results for world fragments intersecting other world fragments; 00437 it is assumed that world geometry is either static or at least that self-intersections 00438 are irrelevant or dealt with elsewhere (such as the custom scene manager) */ 00439 00440 00441 }; 00442 00443 typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair; 00444 typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair; 00445 typedef std::list<SceneQueryMovableObjectPair> SceneQueryMovableIntersectionList; 00446 typedef std::list<SceneQueryMovableObjectWorldFragmentPair> SceneQueryMovableWorldFragmentIntersectionList; 00448 struct _OgreExport IntersectionSceneQueryResult 00449 { 00451 SceneQueryMovableIntersectionList movables2movables; 00453 SceneQueryMovableWorldFragmentIntersectionList movables2world; 00454 00455 00456 00457 }; 00458 00467 class _OgreExport IntersectionSceneQuery 00468 : public SceneQuery, public IntersectionSceneQueryListener 00469 { 00470 protected: 00471 IntersectionSceneQueryResult* mLastResult; 00472 public: 00473 IntersectionSceneQuery(SceneManager* mgr); 00474 virtual ~IntersectionSceneQuery(); 00475 00484 virtual IntersectionSceneQueryResult& execute(void); 00485 00493 virtual void execute(IntersectionSceneQueryListener* listener) = 0; 00494 00498 virtual IntersectionSceneQueryResult& getLastResults(void) const; 00505 virtual void clearResults(void); 00506 00508 bool queryResult(MovableObject* first, MovableObject* second); 00510 bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment); 00511 }; 00512 00513 00514 } 00515 00516 00517 00518 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:27 2004