- Main Page
- Namespaces
- Classes
- Files
- Directories
- 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __SceneQuery_H__
    00030 #define __SceneQuery_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreAxisAlignedBox.h"
    00034 #include "OgreSphere.h"
    00035 #include "OgreRay.h"
    00036 #include "OgreRenderOperation.h"
    00037 #include "OgrePlaneBoundedVolume.h"
    00038
    00039 namespace Ogre {
    00040
    00041     // forward declaration
    00042     class SceneQueryListener;
    00068     class _OgreExport SceneQuery
    00069     {
    00070     public:
    00077         enum WorldFragmentType {
    00079             WFT_NONE,
    00081             WFT_PLANE_BOUNDED_REGION,
    00083             WFT_SINGLE_INTERSECTION,
    00085             WFT_CUSTOM_GEOMETRY,
    00087             WFT_RENDER_OPERATION
    00088         };
    00089
    00103         struct WorldFragment {
    00105             WorldFragmentType fragmentType;
    00107             Vector3 singleIntersection;
    00109             std::list<Plane>* planes;
    00111             void* geometry;
    00113             RenderOperation* renderOp;
    00114
    00115         };
    00116     protected:
    00117         SceneManager* mParentSceneMgr;
    00118         uint32 mQueryMask;
    00119         uint32 mQueryTypeMask;
    00120         std::set<WorldFragmentType> mSupportedWorldFragments;
    00121         WorldFragmentType mWorldFragmentType;
    00122
    00123     public:
    00125         SceneQuery(SceneManager* mgr);
    00126         virtual ~SceneQuery();
    00127
    00137         virtual void setQueryMask(uint32 mask);
    00139         virtual uint32 getQueryMask(void) const;
    00140
    00149         virtual void setQueryTypeMask(uint32 mask);
    00151         virtual uint32 getQueryTypeMask(void) const;
    00152
    00163         virtual void setWorldFragmentType(enum WorldFragmentType wft);
    00164
    00166         virtual WorldFragmentType getWorldFragmentType(void) const;
    00167
    00169         virtual const std::set<WorldFragmentType>* getSupportedWorldFragmentTypes(void) const
    00170             {return &mSupportedWorldFragments;}
    00171
    00172
    00173     };
    00174
    00181     class _OgreExport SceneQueryListener
    00182     {
    00183     public:
    00184         virtual ~SceneQueryListener() { }
    00190         virtual bool queryResult(MovableObject* object) = 0;
    00196         virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0;
    00197
    00198     };
    00199
    00200     typedef std::list<MovableObject*> SceneQueryResultMovableList;
    00201     typedef std::list<SceneQuery::WorldFragment*> SceneQueryResultWorldFragmentList;
    00203     struct _OgreExport SceneQueryResult
    00204     {
    00206         SceneQueryResultMovableList movables;
    00208         SceneQueryResultWorldFragmentList worldFragments;
    00209     };
    00210
    00217     class _OgreExport RegionSceneQuery
    00218         : public SceneQuery, public SceneQueryListener
    00219     {
    00220     protected:
    00221         SceneQueryResult* mLastResult;
    00222     public:
    00224         RegionSceneQuery(SceneManager* mgr);
    00225         virtual ~RegionSceneQuery();
    00234         virtual SceneQueryResult& execute(void);
    00235
    00243         virtual void execute(SceneQueryListener* listener) = 0;
    00244
    00248         virtual SceneQueryResult& getLastResults(void) const;
    00255         virtual void clearResults(void);
    00256
    00258         bool queryResult(MovableObject* first);
    00260         bool queryResult(SceneQuery::WorldFragment* fragment);
    00261     };
    00262
    00264     class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery
    00265     {
    00266     protected:
    00267         AxisAlignedBox mAABB;
    00268     public:
    00269         AxisAlignedBoxSceneQuery(SceneManager* mgr);
    00270         virtual ~AxisAlignedBoxSceneQuery();
    00271
    00273         void setBox(const AxisAlignedBox& box);
    00274
    00276         const AxisAlignedBox& getBox(void) const;
    00277
    00278     };
    00279
    00281     class _OgreExport SphereSceneQuery : public RegionSceneQuery
    00282     {
    00283     protected:
    00284         Sphere mSphere;
    00285     public:
    00286         SphereSceneQuery(SceneManager* mgr);
    00287         virtual ~SphereSceneQuery();
    00289         void setSphere(const Sphere& sphere);
    00290
    00292         const Sphere& getSphere() const;
    00293
    00294     };
    00295
    00298     class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery
    00299     {
    00300     protected:
    00301         PlaneBoundedVolumeList mVolumes;
    00302     public:
    00303         PlaneBoundedVolumeListSceneQuery(SceneManager* mgr);
    00304         virtual ~PlaneBoundedVolumeListSceneQuery();
    00306         void setVolumes(const PlaneBoundedVolumeList& volumes);
    00307
    00309         const PlaneBoundedVolumeList& getVolumes() const;
    00310
    00311     };
    00312
    00313
    00314     /*
    00316     class _OgreExport PyramidSceneQuery : public RegionSceneQuery
    00317     {
    00318     public:
    00319         PyramidSceneQuery(SceneManager* mgr);
    00320         virtual ~PyramidSceneQuery();
    00321     };
    00322     */
    00323
    00329     class _OgreExport RaySceneQueryListener
    00330     {
    00331     public:
    00332         virtual ~RaySceneQueryListener() { }
    00339         virtual bool queryResult(MovableObject* obj, Real distance) = 0;
    00340
    00347         virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0;
    00348
    00349     };
    00350
    00352     struct _OgreExport RaySceneQueryResultEntry
    00353     {
    00355         Real distance;
    00357         MovableObject* movable;
    00359         SceneQuery::WorldFragment* worldFragment;
    00361         bool operator < (const RaySceneQueryResultEntry& rhs) const
    00362         {
    00363             return this->distance < rhs.distance;
    00364         }
    00365
    00366     };
    00367     typedef std::vector<RaySceneQueryResultEntry> RaySceneQueryResult;
    00368
    00370     class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener
    00371     {
    00372     protected:
    00373         Ray mRay;
    00374         bool mSortByDistance;
    00375         ushort mMaxResults;
    00376         RaySceneQueryResult mResult;
    00377
    00378     public:
    00379         RaySceneQuery(SceneManager* mgr);
    00380         virtual ~RaySceneQuery();
    00382         virtual void setRay(const Ray& ray);
    00384         virtual const Ray& getRay(void) const;
    00403         virtual void setSortByDistance(bool sort, ushort maxresults = 0);
    00405         virtual bool getSortByDistance(void) const;
    00408         virtual ushort getMaxResults(void) const;
    00417         virtual RaySceneQueryResult& execute(void);
    00418
    00426         virtual void execute(RaySceneQueryListener* listener) = 0;
    00427
    00431         virtual RaySceneQueryResult& getLastResults(void);
    00438         virtual void clearResults(void);
    00439
    00441         bool queryResult(MovableObject* obj, Real distance);
    00443         bool queryResult(SceneQuery::WorldFragment* fragment, Real distance);
    00444
    00445
    00446
    00447
    00448     };
    00449
    00455     class _OgreExport IntersectionSceneQueryListener
    00456     {
    00457     public:
    00458         virtual ~IntersectionSceneQueryListener() { }
    00465         virtual bool queryResult(MovableObject* first, MovableObject* second) = 0;
    00466
    00473         virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0;
    00474
    00475         /* NB there are no results for world fragments intersecting other world fragments;
    00476            it is assumed that world geometry is either static or at least that self-intersections
    00477            are irrelevant or dealt with elsewhere (such as the custom scene manager) */
    00478
    00479
    00480     };
    00481
    00482     typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair;
    00483     typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair;
    00484     typedef std::list<SceneQueryMovableObjectPair> SceneQueryMovableIntersectionList;
    00485     typedef std::list<SceneQueryMovableObjectWorldFragmentPair> SceneQueryMovableWorldFragmentIntersectionList;
    00487     struct _OgreExport IntersectionSceneQueryResult
    00488     {
    00490         SceneQueryMovableIntersectionList movables2movables;
    00492         SceneQueryMovableWorldFragmentIntersectionList movables2world;
    00493
    00494
    00495
    00496     };
    00497
    00506     class _OgreExport IntersectionSceneQuery
    00507         : public SceneQuery, public IntersectionSceneQueryListener
    00508     {
    00509     protected:
    00510         IntersectionSceneQueryResult* mLastResult;
    00511     public:
    00512         IntersectionSceneQuery(SceneManager* mgr);
    00513         virtual ~IntersectionSceneQuery();
    00514
    00523         virtual IntersectionSceneQueryResult& execute(void);
    00524
    00532         virtual void execute(IntersectionSceneQueryListener* listener) = 0;
    00533
    00537         virtual IntersectionSceneQueryResult& getLastResults(void) const;
    00544         virtual void clearResults(void);
    00545
    00547         bool queryResult(MovableObject* first, MovableObject* second);
    00549         bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment);
    00550     };
    00551
    00552
    00553 }
    00554
    00555
    00556
    00557 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:56 2008