Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 (c) 2000-2005 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         uint32 mQueryMask;
00115         uint32 mQueryTypeMask;
00116         std::set<WorldFragmentType> mSupportedWorldFragments;
00117         WorldFragmentType mWorldFragmentType;
00118     
00119     public:
00121         SceneQuery(SceneManager* mgr);
00122         virtual ~SceneQuery();
00123 
00133         virtual void setQueryMask(uint32 mask);
00135         virtual uint32 getQueryMask(void) const;
00136 
00145         virtual void setQueryTypeMask(uint32 mask);
00147         virtual uint32 getQueryTypeMask(void) const;
00148 
00159         virtual void setWorldFragmentType(enum WorldFragmentType wft);
00160 
00162         virtual WorldFragmentType getWorldFragmentType(void) const;
00163 
00165         virtual const std::set<WorldFragmentType>* getSupportedWorldFragmentTypes(void) const
00166             {return &mSupportedWorldFragments;}
00167 
00168         
00169     };
00170 
00177     class _OgreExport SceneQueryListener
00178     {
00179     public:
00180         virtual ~SceneQueryListener() { }
00186         virtual bool queryResult(MovableObject* object) = 0;
00192         virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0;
00193 
00194     };
00195 
00196     typedef std::list<MovableObject*> SceneQueryResultMovableList;
00197     typedef std::list<SceneQuery::WorldFragment*> SceneQueryResultWorldFragmentList;
00199     struct _OgreExport SceneQueryResult
00200     {
00202         SceneQueryResultMovableList movables;
00204         SceneQueryResultWorldFragmentList worldFragments;
00205     };
00206 
00213     class _OgreExport RegionSceneQuery
00214         : public SceneQuery, public SceneQueryListener
00215     {
00216     protected:
00217         SceneQueryResult* mLastResult;
00218     public:
00220         RegionSceneQuery(SceneManager* mgr);
00221         virtual ~RegionSceneQuery();
00230         virtual SceneQueryResult& execute(void);
00231 
00239         virtual void execute(SceneQueryListener* listener) = 0;
00240         
00244         virtual SceneQueryResult& getLastResults(void) const;
00251         virtual void clearResults(void);
00252 
00254         bool queryResult(MovableObject* first);
00256         bool queryResult(SceneQuery::WorldFragment* fragment);
00257     };
00258 
00260     class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery
00261     {
00262     protected:
00263         AxisAlignedBox mAABB;
00264     public:
00265         AxisAlignedBoxSceneQuery(SceneManager* mgr);
00266         virtual ~AxisAlignedBoxSceneQuery();
00267 
00269         void setBox(const AxisAlignedBox& box);
00270 
00272         const AxisAlignedBox& getBox(void) const;
00273 
00274     };
00275 
00277     class _OgreExport SphereSceneQuery : public RegionSceneQuery
00278     {
00279     protected:
00280         Sphere mSphere;
00281     public:
00282         SphereSceneQuery(SceneManager* mgr);
00283         virtual ~SphereSceneQuery();
00285         void setSphere(const Sphere& sphere);
00286 
00288         const Sphere& getSphere() const;
00289 
00290     };
00291 
00294     class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery
00295     {
00296     protected:
00297         PlaneBoundedVolumeList mVolumes;
00298     public:
00299         PlaneBoundedVolumeListSceneQuery(SceneManager* mgr);
00300         virtual ~PlaneBoundedVolumeListSceneQuery();
00302         void setVolumes(const PlaneBoundedVolumeList& volumes);
00303 
00305         const PlaneBoundedVolumeList& getVolumes() const;
00306 
00307     };
00308 
00309 
00310     /*
00312     class _OgreExport PyramidSceneQuery : public RegionSceneQuery
00313     {
00314     public:
00315         PyramidSceneQuery(SceneManager* mgr);
00316         virtual ~PyramidSceneQuery();
00317     };
00318     */
00319 
00325     class _OgreExport RaySceneQueryListener 
00326     {
00327     public:
00328         virtual ~RaySceneQueryListener() { }
00335         virtual bool queryResult(MovableObject* obj, Real distance) = 0;
00336 
00343         virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0;
00344 
00345     };
00346       
00348     struct _OgreExport RaySceneQueryResultEntry
00349     {
00351         Real distance;
00353         MovableObject* movable;
00355         SceneQuery::WorldFragment* worldFragment;
00357         bool operator < (const RaySceneQueryResultEntry& rhs) const
00358         {
00359             return this->distance < rhs.distance;
00360         }
00361 
00362     };
00363     typedef std::vector<RaySceneQueryResultEntry> RaySceneQueryResult;
00364 
00366     class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener
00367     {
00368     protected:
00369         Ray mRay;
00370         bool mSortByDistance;
00371         ushort mMaxResults;
00372         RaySceneQueryResult mResult;
00373 
00374     public:
00375         RaySceneQuery(SceneManager* mgr);
00376         virtual ~RaySceneQuery();
00378         virtual void setRay(const Ray& ray);
00380         virtual const Ray& getRay(void) const;
00399         virtual void setSortByDistance(bool sort, ushort maxresults = 0);
00401         virtual bool getSortByDistance(void) const;
00404         virtual ushort getMaxResults(void) const;
00413         virtual RaySceneQueryResult& execute(void);
00414 
00422         virtual void execute(RaySceneQueryListener* listener) = 0;
00423 
00427         virtual RaySceneQueryResult& getLastResults(void);
00434         virtual void clearResults(void);
00435 
00437         bool queryResult(MovableObject* obj, Real distance);
00439         bool queryResult(SceneQuery::WorldFragment* fragment, Real distance);
00440 
00441 
00442 
00443 
00444     };
00445 
00451     class _OgreExport IntersectionSceneQueryListener 
00452     {
00453     public:
00454         virtual ~IntersectionSceneQueryListener() { }
00461         virtual bool queryResult(MovableObject* first, MovableObject* second) = 0;
00462 
00469         virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0;
00470 
00471         /* NB there are no results for world fragments intersecting other world fragments;
00472            it is assumed that world geometry is either static or at least that self-intersections
00473            are irrelevant or dealt with elsewhere (such as the custom scene manager) */
00474         
00475     
00476     };
00477         
00478     typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair;
00479     typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair;
00480     typedef std::list<SceneQueryMovableObjectPair> SceneQueryMovableIntersectionList;
00481     typedef std::list<SceneQueryMovableObjectWorldFragmentPair> SceneQueryMovableWorldFragmentIntersectionList;
00483     struct _OgreExport IntersectionSceneQueryResult
00484     {
00486         SceneQueryMovableIntersectionList movables2movables;
00488         SceneQueryMovableWorldFragmentIntersectionList movables2world;
00489         
00490         
00491 
00492     };
00493 
00502     class _OgreExport IntersectionSceneQuery
00503         : public SceneQuery, public IntersectionSceneQueryListener 
00504     {
00505     protected:
00506         IntersectionSceneQueryResult* mLastResult;
00507     public:
00508         IntersectionSceneQuery(SceneManager* mgr);
00509         virtual ~IntersectionSceneQuery();
00510 
00519         virtual IntersectionSceneQueryResult& execute(void);
00520 
00528         virtual void execute(IntersectionSceneQueryListener* listener) = 0;
00529 
00533         virtual IntersectionSceneQueryResult& getLastResults(void) const;
00540         virtual void clearResults(void);
00541 
00543         bool queryResult(MovableObject* first, MovableObject* second);
00545         bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment);
00546     };
00547     
00548 
00549 }
00550     
00551 
00552 
00553 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:49 2006