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-2013 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 #include "OgreHeaderPrefix.h"
00038 
00039 namespace Ogre {
00040 
00041     // forward declaration
00042     class SceneQueryListener;
00074     class _OgreExport SceneQuery : public SceneMgtAlloc
00075     {
00076     public:
00083         enum WorldFragmentType {
00085             WFT_NONE,
00087             WFT_PLANE_BOUNDED_REGION,
00089             WFT_SINGLE_INTERSECTION,
00091             WFT_CUSTOM_GEOMETRY,
00093             WFT_RENDER_OPERATION
00094         };
00095 
00109         struct WorldFragment {
00111             WorldFragmentType fragmentType;
00113             Vector3 singleIntersection;
00115             list<Plane>::type* planes;
00117             void* geometry;
00119             RenderOperation* renderOp;
00120             
00121         };
00122     protected:
00123         SceneManager* mParentSceneMgr;
00124         uint32 mQueryMask;
00125         uint32 mQueryTypeMask;
00126         set<WorldFragmentType>::type mSupportedWorldFragments;
00127         WorldFragmentType mWorldFragmentType;
00128     
00129     public:
00131         SceneQuery(SceneManager* mgr);
00132         virtual ~SceneQuery();
00133 
00143         virtual void setQueryMask(uint32 mask);
00145         virtual uint32 getQueryMask(void) const;
00146 
00155         virtual void setQueryTypeMask(uint32 mask);
00157         virtual uint32 getQueryTypeMask(void) const;
00158 
00169         virtual void setWorldFragmentType(enum WorldFragmentType wft);
00170 
00172         virtual WorldFragmentType getWorldFragmentType(void) const;
00173 
00175         virtual const set<WorldFragmentType>::type* getSupportedWorldFragmentTypes(void) const
00176             {return &mSupportedWorldFragments;}
00177 
00178         
00179     };
00180 
00187     class _OgreExport SceneQueryListener
00188     {
00189     public:
00190         virtual ~SceneQueryListener() { }
00196         virtual bool queryResult(MovableObject* object) = 0;
00202         virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0;
00203 
00204     };
00205 
00206     typedef list<MovableObject*>::type SceneQueryResultMovableList;
00207     typedef list<SceneQuery::WorldFragment*>::type SceneQueryResultWorldFragmentList;
00209     struct _OgreExport SceneQueryResult : public SceneMgtAlloc
00210     {
00212         SceneQueryResultMovableList movables;
00214         SceneQueryResultWorldFragmentList worldFragments;
00215     };
00216 
00223     class _OgreExport RegionSceneQuery
00224         : public SceneQuery, public SceneQueryListener
00225     {
00226     protected:
00227         SceneQueryResult* mLastResult;
00228     public:
00230         RegionSceneQuery(SceneManager* mgr);
00231         virtual ~RegionSceneQuery();
00240         virtual SceneQueryResult& execute(void);
00241 
00249         virtual void execute(SceneQueryListener* listener) = 0;
00250         
00254         virtual SceneQueryResult& getLastResults(void) const;
00261         virtual void clearResults(void);
00262 
00264         bool queryResult(MovableObject* first);
00266         bool queryResult(SceneQuery::WorldFragment* fragment);
00267     };
00268 
00270     class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery
00271     {
00272     protected:
00273         AxisAlignedBox mAABB;
00274     public:
00275         AxisAlignedBoxSceneQuery(SceneManager* mgr);
00276         virtual ~AxisAlignedBoxSceneQuery();
00277 
00279         void setBox(const AxisAlignedBox& box);
00280 
00282         const AxisAlignedBox& getBox(void) const;
00283 
00284     };
00285 
00287     class _OgreExport SphereSceneQuery : public RegionSceneQuery
00288     {
00289     protected:
00290         Sphere mSphere;
00291     public:
00292         SphereSceneQuery(SceneManager* mgr);
00293         virtual ~SphereSceneQuery();
00295         void setSphere(const Sphere& sphere);
00296 
00298         const Sphere& getSphere() const;
00299 
00300     };
00301 
00304     class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery
00305     {
00306     protected:
00307         PlaneBoundedVolumeList mVolumes;
00308     public:
00309         PlaneBoundedVolumeListSceneQuery(SceneManager* mgr);
00310         virtual ~PlaneBoundedVolumeListSceneQuery();
00312         void setVolumes(const PlaneBoundedVolumeList& volumes);
00313 
00315         const PlaneBoundedVolumeList& getVolumes() const;
00316 
00317     };
00318 
00319 
00320     /*
00322     class _OgreExport PyramidSceneQuery : public RegionSceneQuery
00323     {
00324     public:
00325         PyramidSceneQuery(SceneManager* mgr);
00326         virtual ~PyramidSceneQuery();
00327     };
00328     */
00329 
00335     class _OgreExport RaySceneQueryListener 
00336     {
00337     public:
00338         virtual ~RaySceneQueryListener() { }
00345         virtual bool queryResult(MovableObject* obj, Real distance) = 0;
00346 
00353         virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0;
00354 
00355     };
00356       
00358     struct _OgreExport RaySceneQueryResultEntry
00359     {
00361         Real distance;
00363         MovableObject* movable;
00365         SceneQuery::WorldFragment* worldFragment;
00367         bool operator < (const RaySceneQueryResultEntry& rhs) const
00368         {
00369             return this->distance < rhs.distance;
00370         }
00371 
00372     };
00373     typedef vector<RaySceneQueryResultEntry>::type RaySceneQueryResult;
00374 
00376     class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener
00377     {
00378     protected:
00379         Ray mRay;
00380         bool mSortByDistance;
00381         ushort mMaxResults;
00382         RaySceneQueryResult mResult;
00383 
00384     public:
00385         RaySceneQuery(SceneManager* mgr);
00386         virtual ~RaySceneQuery();
00388         virtual void setRay(const Ray& ray);
00390         virtual const Ray& getRay(void) const;
00409         virtual void setSortByDistance(bool sort, ushort maxresults = 0);
00411         virtual bool getSortByDistance(void) const;
00414         virtual ushort getMaxResults(void) const;
00423         virtual RaySceneQueryResult& execute(void);
00424 
00432         virtual void execute(RaySceneQueryListener* listener) = 0;
00433 
00437         virtual RaySceneQueryResult& getLastResults(void);
00444         virtual void clearResults(void);
00445 
00447         bool queryResult(MovableObject* obj, Real distance);
00449         bool queryResult(SceneQuery::WorldFragment* fragment, Real distance);
00450 
00451 
00452 
00453 
00454     };
00455 
00461     class _OgreExport IntersectionSceneQueryListener 
00462     {
00463     public:
00464         virtual ~IntersectionSceneQueryListener() { }
00471         virtual bool queryResult(MovableObject* first, MovableObject* second) = 0;
00472 
00479         virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0;
00480 
00481         /* NB there are no results for world fragments intersecting other world fragments;
00482            it is assumed that world geometry is either static or at least that self-intersections
00483            are irrelevant or dealt with elsewhere (such as the custom scene manager) */
00484         
00485     
00486     };
00487         
00488     typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair;
00489     typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair;
00490     typedef list<SceneQueryMovableObjectPair>::type SceneQueryMovableIntersectionList;
00491     typedef list<SceneQueryMovableObjectWorldFragmentPair>::type SceneQueryMovableWorldFragmentIntersectionList;
00493     struct _OgreExport IntersectionSceneQueryResult : public SceneMgtAlloc
00494     {
00496         SceneQueryMovableIntersectionList movables2movables;
00498         SceneQueryMovableWorldFragmentIntersectionList movables2world;
00499         
00500         
00501 
00502     };
00503 
00512     class _OgreExport IntersectionSceneQuery
00513         : public SceneQuery, public IntersectionSceneQueryListener 
00514     {
00515     protected:
00516         IntersectionSceneQueryResult* mLastResult;
00517     public:
00518         IntersectionSceneQuery(SceneManager* mgr);
00519         virtual ~IntersectionSceneQuery();
00520 
00529         virtual IntersectionSceneQueryResult& execute(void);
00530 
00538         virtual void execute(IntersectionSceneQueryListener* listener) = 0;
00539 
00543         virtual IntersectionSceneQueryResult& getLastResults(void) const;
00550         virtual void clearResults(void);
00551 
00553         bool queryResult(MovableObject* first, MovableObject* second);
00555         bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment);
00556     };
00557     
00561 }
00562     
00563 #include "OgreHeaderSuffix.h"
00564 
00565 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45