Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreSceneQuery.h

Go to the documentation of this file.
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 #include "OgrePlaneBoundedVolume.h"
00034 
00035 namespace Ogre {
00036 
00037     // forward declaration
00038     class SceneQueryListener;
00064     class _OgreExport SceneQuery
00065     {
00066     public:
00073         enum WorldFragmentType {
00075             WFT_NONE,
00077             WFT_PLANE_BOUNDED_REGION,
00079             WFT_SINGLE_INTERSECTION,
00081             WFT_CUSTOM_GEOMETRY,
00083             WFT_RENDER_OPERATION
00084         };
00085 
00099         struct WorldFragment {
00101             WorldFragmentType fragmentType;
00103             Vector3 singleIntersection;
00105             std::list<Plane>* planes;
00107             void* geometry;
00109             RenderOperation* renderOp;
00110             
00111         };
00112     protected:
00113         SceneManager* mParentSceneMgr;
00114         unsigned long mQueryMask;
00115         std::set<WorldFragmentType> mSupportedWorldFragments;
00116         WorldFragmentType mWorldFragmentType;
00117     
00118     public:
00120         SceneQuery(SceneManager* mgr);
00121         virtual ~SceneQuery();
00122 
00132         virtual void setQueryMask(unsigned long mask);
00134         virtual unsigned long getQueryMask(void) const;
00135 
00146         virtual void setWorldFragmentType(enum WorldFragmentType wft);
00147 
00149         virtual WorldFragmentType getWorldFragmentType(void) const;
00150 
00152         virtual const std::set<WorldFragmentType>* getSupportedWorldFragmentTypes(void) const
00153             {return &mSupportedWorldFragments;}
00154 
00155         
00156     };
00157 
00164     class _OgreExport SceneQueryListener
00165     {
00166     public:
00172         virtual bool queryResult(MovableObject* object) = 0;
00178         virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0;
00179 
00180     };
00181 
00182     typedef std::list<MovableObject*> SceneQueryResultMovableList;
00183     typedef std::list<SceneQuery::WorldFragment*> SceneQueryResultWorldFragmentList;
00185     struct _OgreExport SceneQueryResult
00186     {
00188         SceneQueryResultMovableList movables;
00190         SceneQueryResultWorldFragmentList worldFragments;
00191     };
00192 
00199     class _OgreExport RegionSceneQuery
00200         : public SceneQuery, public SceneQueryListener
00201     {
00202     protected:
00203         SceneQueryResult* mLastResult;
00204     public:
00206         RegionSceneQuery(SceneManager* mgr);
00207         virtual ~RegionSceneQuery();
00216         virtual SceneQueryResult& execute(void);
00217 
00225         virtual void execute(SceneQueryListener* listener) = 0;
00226         
00230         virtual SceneQueryResult& getLastResults(void) const;
00237         virtual void clearResults(void);
00238 
00240         bool queryResult(MovableObject* first);
00242         bool queryResult(SceneQuery::WorldFragment* fragment);
00243     };
00244 
00246     class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery
00247     {
00248     protected:
00249         AxisAlignedBox mAABB;
00250     public:
00251         AxisAlignedBoxSceneQuery(SceneManager* mgr);
00252         virtual ~AxisAlignedBoxSceneQuery();
00253 
00255         void setBox(const AxisAlignedBox& box);
00256 
00258         const AxisAlignedBox& getBox(void) const;
00259 
00260     };
00261 
00263     class _OgreExport SphereSceneQuery : public RegionSceneQuery
00264     {
00265     protected:
00266         Sphere mSphere;
00267     public:
00268         SphereSceneQuery(SceneManager* mgr);
00269         virtual ~SphereSceneQuery();
00271         void setSphere(const Sphere& sphere);
00272 
00274         const Sphere& getSphere() const;
00275 
00276     };
00277 
00280     class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery
00281     {
00282     protected:
00283         PlaneBoundedVolumeList mVolumes;
00284     public:
00285         PlaneBoundedVolumeListSceneQuery(SceneManager* mgr);
00286         virtual ~PlaneBoundedVolumeListSceneQuery();
00288         void setVolumes(const PlaneBoundedVolumeList& volumes);
00289 
00291         const PlaneBoundedVolumeList& getVolumes() const;
00292 
00293     };
00294 
00295 
00296     /*
00298     class _OgreExport PyramidSceneQuery : public RegionSceneQuery
00299     {
00300     public:
00301         PyramidSceneQuery(SceneManager* mgr);
00302         virtual ~PyramidSceneQuery();
00303     };
00304     */
00305 
00311     class _OgreExport RaySceneQueryListener 
00312     {
00313     public:
00320         virtual bool queryResult(MovableObject* obj, Real distance) = 0;
00321 
00328         virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0;
00329 
00330     };
00331       
00333     struct _OgreExport RaySceneQueryResultEntry
00334     {
00336         Real distance;
00338         MovableObject* movable;
00340         SceneQuery::WorldFragment* worldFragment;
00342         bool operator < (const RaySceneQueryResultEntry& rhs) const
00343         {
00344             return this->distance < rhs.distance;
00345         }
00346 
00347     };
00348     typedef std::list<RaySceneQueryResultEntry> RaySceneQueryResult;
00349 
00351     class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener
00352     {
00353     protected:
00354         Ray mRay;
00355         bool mSortByDistance;
00356         ushort mMaxResults;
00357         RaySceneQueryResult* mLastResult;
00358 
00359     public:
00360         RaySceneQuery(SceneManager* mgr);
00361         virtual ~RaySceneQuery();
00363         void setRay(const Ray& ray);
00365         const Ray& getRay(void) const;
00384         void setSortByDistance(bool sort, ushort maxresults = 0);
00386         bool getSortByDistance(void) const;
00389         ushort getMaxResults(void) const;
00398         virtual RaySceneQueryResult& execute(void);
00399 
00407         virtual void execute(RaySceneQueryListener* listener) = 0;
00408 
00412         virtual RaySceneQueryResult& getLastResults(void) const;
00419         virtual void clearResults(void);
00420 
00422         bool queryResult(MovableObject* obj, Real distance);
00424         bool queryResult(SceneQuery::WorldFragment* fragment, Real distance);
00425 
00426 
00427 
00428 
00429     };
00430 
00436     class _OgreExport IntersectionSceneQueryListener 
00437     {
00438     public:
00445         virtual bool queryResult(MovableObject* first, MovableObject* second) = 0;
00446 
00453         virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0;
00454 
00455         /* NB there are no results for world fragments intersecting other world fragments;
00456            it is assumed that world geometry is either static or at least that self-intersections
00457            are irrelevant or dealt with elsewhere (such as the custom scene manager) */
00458         
00459     
00460     };
00461         
00462     typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair;
00463     typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair;
00464     typedef std::list<SceneQueryMovableObjectPair> SceneQueryMovableIntersectionList;
00465     typedef std::list<SceneQueryMovableObjectWorldFragmentPair> SceneQueryMovableWorldFragmentIntersectionList;
00467     struct _OgreExport IntersectionSceneQueryResult
00468     {
00470         SceneQueryMovableIntersectionList movables2movables;
00472         SceneQueryMovableWorldFragmentIntersectionList movables2world;
00473         
00474         
00475 
00476     };
00477 
00486     class _OgreExport IntersectionSceneQuery
00487         : public SceneQuery, public IntersectionSceneQueryListener 
00488     {
00489     protected:
00490         IntersectionSceneQueryResult* mLastResult;
00491     public:
00492         IntersectionSceneQuery(SceneManager* mgr);
00493         virtual ~IntersectionSceneQuery();
00494 
00503         virtual IntersectionSceneQueryResult& execute(void);
00504 
00512         virtual void execute(IntersectionSceneQueryListener* listener) = 0;
00513 
00517         virtual IntersectionSceneQueryResult& getLastResults(void) const;
00524         virtual void clearResults(void);
00525 
00527         bool queryResult(MovableObject* first, MovableObject* second);
00529         bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment);
00530     };
00531     
00532 
00533 }
00534     
00535 
00536 
00537 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:45 2004