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

OgreOctreeSceneQuery.cpp

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-2004 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 /***************************************************************************
00026 OgreOctreeSceneQuery.cpp  -  description
00027 -------------------
00028 begin                : Tues July 20, 2004
00029 copyright            : (C) 2004by Jon Anderson
00030 email                : janders@users.sf.net
00031  
00032  
00033  
00034 ***************************************************************************/
00035 
00036 #include <OgreOctreeSceneQuery.h>
00037 #include <OgreOctreeSceneManager.h>
00038 #include <OgreEntity.h>
00039 
00040 namespace Ogre
00041 {
00042 
00043 //---------------------------------------------------------------------
00044 OctreeIntersectionSceneQuery::OctreeIntersectionSceneQuery(SceneManager* creator)
00045         : DefaultIntersectionSceneQuery(creator)
00046 {
00047 
00048 }
00049 //---------------------------------------------------------------------
00050 OctreeIntersectionSceneQuery::~OctreeIntersectionSceneQuery()
00051 {}
00052 //---------------------------------------------------------------------
00053 void OctreeIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener)
00054 {
00055     typedef std::pair<MovableObject *, MovableObject *> MovablePair;
00056     typedef std::set
00057         < std::pair<MovableObject *, MovableObject *> > MovableSet;
00058 
00059     MovableSet set;
00060 
00061     SceneManager::EntityIterator it = mParentSceneMgr->getEntityIterator();
00062     while( it.hasMoreElements() )
00063     {
00064 
00065         Entity * e = it.getNext();
00066 
00067         std::list < SceneNode * > list;
00068         //find the nodes that intersect the AAB
00069         static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( e->getWorldBoundingBox(), list, 0 );
00070         //grab all moveables from the node that intersect...
00071         std::list < SceneNode * >::iterator it = list.begin();
00072         while( it != list.end() )
00073         {
00074             SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
00075             while( oit.hasMoreElements() )
00076             {
00077                 MovableObject * m = oit.getNext();
00078 
00079                 if( m != e &&
00080                         set.find( MovablePair(e,m)) == set.end() &&
00081                         set.find( MovablePair(m,e)) == set.end() &&
00082                         (m->getQueryFlags() & mQueryMask) &&
00083                         e->getWorldBoundingBox().intersects( m->getWorldBoundingBox() ) )
00084                 {
00085                     listener -> queryResult( e, m );
00086                 }
00087                 set.insert( MovablePair(e,m) );
00088 
00089             }
00090             ++it;
00091         }
00092 
00093     }
00094 }
00096 OctreeAxisAlignedBoxSceneQuery::OctreeAxisAlignedBoxSceneQuery(SceneManager* creator)
00097         : DefaultAxisAlignedBoxSceneQuery(creator)
00098 {
00099 }
00101 OctreeAxisAlignedBoxSceneQuery::~OctreeAxisAlignedBoxSceneQuery()
00102 {}
00103 
00105 void OctreeAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener)
00106 {
00107     std::list < SceneNode * > list;
00108     //find the nodes that intersect the AAB
00109     static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mAABB, list, 0 );
00110 
00111     //grab all moveables from the node that intersect...
00112     std::list < SceneNode * >::iterator it = list.begin();
00113     while( it != list.end() )
00114     {
00115         SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
00116         while( oit.hasMoreElements() )
00117         {
00118             MovableObject * m = oit.getNext();
00119             if( (m->getQueryFlags() & mQueryMask) && mAABB.intersects( m->getWorldBoundingBox() ) )
00120             {
00121                 listener -> queryResult( m );
00122             }
00123         }
00124 
00125         ++it;
00126     }
00127 
00128 }
00129 //---------------------------------------------------------------------
00130 OctreeRaySceneQuery::
00131 OctreeRaySceneQuery(SceneManager* creator) : DefaultRaySceneQuery(creator)
00132 {
00133 }
00134 //---------------------------------------------------------------------
00135 OctreeRaySceneQuery::~OctreeRaySceneQuery()
00136 {}
00137 //---------------------------------------------------------------------
00138 void OctreeRaySceneQuery::execute(RaySceneQueryListener* listener)
00139 {
00140     std::list < SceneNode * > list;
00141     //find the nodes that intersect the AAB
00142     static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mRay, list, 0 );
00143 
00144     //grab all moveables from the node that intersect...
00145     std::list < SceneNode * >::iterator it = list.begin();
00146     while( it != list.end() )
00147     {
00148         SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
00149         while( oit.hasMoreElements() )
00150         {
00151             MovableObject * m = oit.getNext();
00152             if( (m->getQueryFlags() & mQueryMask) )
00153             {
00154                 std::pair<bool, Real> result = mRay.intersects(m->getWorldBoundingBox());
00155 
00156                 if( result.first )
00157                 {
00158                     listener -> queryResult( m, result.second );
00159                 }
00160             }
00161         }
00162 
00163         ++it;
00164     }
00165 
00166 }
00167 
00168 
00169 //---------------------------------------------------------------------
00170 OctreeSphereSceneQuery::
00171 OctreeSphereSceneQuery(SceneManager* creator) : DefaultSphereSceneQuery(creator)
00172 {
00173 }
00174 //---------------------------------------------------------------------
00175 OctreeSphereSceneQuery::~OctreeSphereSceneQuery()
00176 {}
00177 //---------------------------------------------------------------------
00178 void OctreeSphereSceneQuery::execute(SceneQueryListener* listener)
00179 {
00180     std::list < SceneNode * > list;
00181     //find the nodes that intersect the AAB
00182     static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mSphere, list, 0 );
00183 
00184     //grab all moveables from the node that intersect...
00185     std::list < SceneNode * >::iterator it = list.begin();
00186     while( it != list.end() )
00187     {
00188         SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
00189         while( oit.hasMoreElements() )
00190         {
00191             MovableObject * m = oit.getNext();
00192             if( (m->getQueryFlags() & mQueryMask) && mSphere.intersects( m->getWorldBoundingBox() ) )
00193             {
00194                 listener -> queryResult( m );
00195             }
00196         }
00197 
00198         ++it;
00199     }
00200 }
00201 //---------------------------------------------------------------------
00202 OctreePlaneBoundedVolumeListSceneQuery::
00203 OctreePlaneBoundedVolumeListSceneQuery(SceneManager* creator)
00204         : DefaultPlaneBoundedVolumeListSceneQuery(creator)
00205 {
00206 
00207 }
00208 //---------------------------------------------------------------------
00209 OctreePlaneBoundedVolumeListSceneQuery::~OctreePlaneBoundedVolumeListSceneQuery()
00210 {}
00211 //---------------------------------------------------------------------
00212 void OctreePlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener)
00213 {
00214     PlaneBoundedVolumeList::iterator pi, piend;
00215     piend = mVolumes.end();
00216     for (pi = mVolumes.begin(); pi != piend; ++pi)
00217     {
00218         std::list < SceneNode * > list;
00219         //find the nodes that intersect the AAB
00220         static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( *pi, list, 0 );
00221 
00222         //grab all moveables from the node that intersect...
00223         std::list < SceneNode * >::iterator it = list.begin();
00224         while( it != list.end() )
00225         {
00226             SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
00227             while( oit.hasMoreElements() )
00228             {
00229                 MovableObject * m = oit.getNext();
00230                 if( (m->getQueryFlags() & mQueryMask) && (*pi).intersects( m->getWorldBoundingBox() ) )
00231                 {
00232                     listener -> queryResult( m );
00233                 }
00234             }
00235             ++it;
00236         }
00237     }//for
00238 }
00239 
00240 
00241 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:36 2004