# 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         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:
    00167         virtual ~SceneQueryListener() { }
    00173         virtual bool queryResult(MovableObject* object) = 0;
    00179         virtual bool queryResult(SceneQuery::WorldFragment* fragment) = 0;
    00180
    00181     };
    00182
    00183     typedef std::list<MovableObject*> SceneQueryResultMovableList;
    00184     typedef std::list<SceneQuery::WorldFragment*> SceneQueryResultWorldFragmentList;
    00186     struct _OgreExport SceneQueryResult
    00187     {
    00189         SceneQueryResultMovableList movables;
    00191         SceneQueryResultWorldFragmentList worldFragments;
    00192     };
    00193
    00200     class _OgreExport RegionSceneQuery
    00201         : public SceneQuery, public SceneQueryListener
    00202     {
    00203     protected:
    00204         SceneQueryResult* mLastResult;
    00205     public:
    00207         RegionSceneQuery(SceneManager* mgr);
    00208         virtual ~RegionSceneQuery();
    00217         virtual SceneQueryResult& execute(void);
    00218
    00226         virtual void execute(SceneQueryListener* listener) = 0;
    00227
    00231         virtual SceneQueryResult& getLastResults(void) const;
    00238         virtual void clearResults(void);
    00239
    00241         bool queryResult(MovableObject* first);
    00243         bool queryResult(SceneQuery::WorldFragment* fragment);
    00244     };
    00245
    00247     class _OgreExport AxisAlignedBoxSceneQuery : public RegionSceneQuery
    00248     {
    00249     protected:
    00250         AxisAlignedBox mAABB;
    00251     public:
    00252         AxisAlignedBoxSceneQuery(SceneManager* mgr);
    00253         virtual ~AxisAlignedBoxSceneQuery();
    00254
    00256         void setBox(const AxisAlignedBox& box);
    00257
    00259         const AxisAlignedBox& getBox(void) const;
    00260
    00261     };
    00262
    00264     class _OgreExport SphereSceneQuery : public RegionSceneQuery
    00265     {
    00266     protected:
    00267         Sphere mSphere;
    00268     public:
    00269         SphereSceneQuery(SceneManager* mgr);
    00270         virtual ~SphereSceneQuery();
    00272         void setSphere(const Sphere& sphere);
    00273
    00275         const Sphere& getSphere() const;
    00276
    00277     };
    00278
    00281     class _OgreExport PlaneBoundedVolumeListSceneQuery : public RegionSceneQuery
    00282     {
    00283     protected:
    00284         PlaneBoundedVolumeList mVolumes;
    00285     public:
    00286         PlaneBoundedVolumeListSceneQuery(SceneManager* mgr);
    00287         virtual ~PlaneBoundedVolumeListSceneQuery();
    00289         void setVolumes(const PlaneBoundedVolumeList& volumes);
    00290
    00292         const PlaneBoundedVolumeList& getVolumes() const;
    00293
    00294     };
    00295
    00296
    00297     /*
    00299     class _OgreExport PyramidSceneQuery : public RegionSceneQuery
    00300     {
    00301     public:
    00302         PyramidSceneQuery(SceneManager* mgr);
    00303         virtual ~PyramidSceneQuery();
    00304     };
    00305     */
    00306
    00312     class _OgreExport RaySceneQueryListener
    00313     {
    00314     public:
    00315         virtual ~RaySceneQueryListener() { }
    00322         virtual bool queryResult(MovableObject* obj, Real distance) = 0;
    00323
    00330         virtual bool queryResult(SceneQuery::WorldFragment* fragment, Real distance) = 0;
    00331
    00332     };
    00333
    00335     struct _OgreExport RaySceneQueryResultEntry
    00336     {
    00338         Real distance;
    00340         MovableObject* movable;
    00342         SceneQuery::WorldFragment* worldFragment;
    00344         bool operator < (const RaySceneQueryResultEntry& rhs) const
    00345         {
    00346             return this->distance < rhs.distance;
    00347         }
    00348
    00349     };
    00350     typedef std::list<RaySceneQueryResultEntry> RaySceneQueryResult;
    00351
    00353     class _OgreExport RaySceneQuery : public SceneQuery, public RaySceneQueryListener
    00354     {
    00355     protected:
    00356         Ray mRay;
    00357         bool mSortByDistance;
    00358         ushort mMaxResults;
    00359         RaySceneQueryResult* mLastResult;
    00360
    00361     public:
    00362         RaySceneQuery(SceneManager* mgr);
    00363         virtual ~RaySceneQuery();
    00365         virtual void setRay(const Ray& ray);
    00367         virtual const Ray& getRay(void) const;
    00386         virtual void setSortByDistance(bool sort, ushort maxresults = 0);
    00388         virtual bool getSortByDistance(void) const;
    00391         virtual ushort getMaxResults(void) const;
    00400         virtual RaySceneQueryResult& execute(void);
    00401
    00409         virtual void execute(RaySceneQueryListener* listener) = 0;
    00410
    00414         virtual RaySceneQueryResult& getLastResults(void) const;
    00421         virtual void clearResults(void);
    00422
    00424         bool queryResult(MovableObject* obj, Real distance);
    00426         bool queryResult(SceneQuery::WorldFragment* fragment, Real distance);
    00427
    00428
    00429
    00430
    00431     };
    00432
    00438     class _OgreExport IntersectionSceneQueryListener
    00439     {
    00440     public:
    00441         virtual ~IntersectionSceneQueryListener() { }
    00448         virtual bool queryResult(MovableObject* first, MovableObject* second) = 0;
    00449
    00456         virtual bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment) = 0;
    00457
    00458         /* NB there are no results for world fragments intersecting other world fragments;
    00459            it is assumed that world geometry is either static or at least that self-intersections
    00460            are irrelevant or dealt with elsewhere (such as the custom scene manager) */
    00461
    00462
    00463     };
    00464
    00465     typedef std::pair<MovableObject*, MovableObject*> SceneQueryMovableObjectPair;
    00466     typedef std::pair<MovableObject*, SceneQuery::WorldFragment*> SceneQueryMovableObjectWorldFragmentPair;
    00467     typedef std::list<SceneQueryMovableObjectPair> SceneQueryMovableIntersectionList;
    00468     typedef std::list<SceneQueryMovableObjectWorldFragmentPair> SceneQueryMovableWorldFragmentIntersectionList;
    00470     struct _OgreExport IntersectionSceneQueryResult
    00471     {
    00473         SceneQueryMovableIntersectionList movables2movables;
    00475         SceneQueryMovableWorldFragmentIntersectionList movables2world;
    00476
    00477
    00478
    00479     };
    00480
    00489     class _OgreExport IntersectionSceneQuery
    00490         : public SceneQuery, public IntersectionSceneQueryListener
    00491     {
    00492     protected:
    00493         IntersectionSceneQueryResult* mLastResult;
    00494     public:
    00495         IntersectionSceneQuery(SceneManager* mgr);
    00496         virtual ~IntersectionSceneQuery();
    00497
    00506         virtual IntersectionSceneQueryResult& execute(void);
    00507
    00515         virtual void execute(IntersectionSceneQueryListener* listener) = 0;
    00516
    00520         virtual IntersectionSceneQueryResult& getLastResults(void) const;
    00527         virtual void clearResults(void);
    00528
    00530         bool queryResult(MovableObject* first, MovableObject* second);
    00532         bool queryResult(MovableObject* movable, SceneQuery::WorldFragment* fragment);
    00533     };
    00534
    00535
    00536 }
    00537
    00538
    00539
    00540 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:36:06 2005