[657] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | /***************************************************************************
|
---|
| 26 | OgreOctreeSceneQuery.cpp - description
|
---|
| 27 | -------------------
|
---|
| 28 | begin : Tues July 20, 2004
|
---|
| 29 | copyright : (C) 2004by Jon Anderson
|
---|
| 30 | email : janders@users.sf.net
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | ***************************************************************************/
|
---|
| 35 |
|
---|
| 36 | #include <OgreOctreeSceneQuery.h>
|
---|
| 37 | #include <OgreOctreeSceneManager.h>
|
---|
| 38 | #include <OgreEntity.h>
|
---|
| 39 |
|
---|
| 40 | namespace Ogre
|
---|
| 41 | {
|
---|
| 42 |
|
---|
| 43 | //---------------------------------------------------------------------
|
---|
| 44 | OctreeIntersectionSceneQuery::OctreeIntersectionSceneQuery(SceneManager* creator)
|
---|
| 45 | : DefaultIntersectionSceneQuery(creator)
|
---|
| 46 | {
|
---|
| 47 |
|
---|
| 48 | }
|
---|
| 49 | //---------------------------------------------------------------------
|
---|
| 50 | OctreeIntersectionSceneQuery::~OctreeIntersectionSceneQuery()
|
---|
| 51 | {}
|
---|
| 52 | //---------------------------------------------------------------------
|
---|
| 53 | void OctreeIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener)
|
---|
| 54 | {
|
---|
| 55 | typedef std::pair<MovableObject *, MovableObject *> MovablePair;
|
---|
| 56 | typedef std::set
|
---|
| 57 | < std::pair<MovableObject *, MovableObject *> > MovableSet;
|
---|
| 58 |
|
---|
| 59 | MovableSet set;
|
---|
| 60 |
|
---|
| 61 | SceneManager::EntityIterator it = mParentSceneMgr->getEntityIterator();
|
---|
| 62 | while( it.hasMoreElements() )
|
---|
| 63 | {
|
---|
| 64 |
|
---|
| 65 | Entity * e = it.getNext();
|
---|
| 66 |
|
---|
| 67 | std::list < SceneNode * > list;
|
---|
| 68 | //find the nodes that intersect the AAB
|
---|
| 69 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( e->getWorldBoundingBox(), list, 0 );
|
---|
| 70 | //grab all moveables from the node that intersect...
|
---|
| 71 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 72 | while( it != list.end() )
|
---|
| 73 | {
|
---|
| 74 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 75 | while( oit.hasMoreElements() )
|
---|
| 76 | {
|
---|
| 77 | MovableObject * m = oit.getNext();
|
---|
| 78 |
|
---|
| 79 | if( m != e &&
|
---|
| 80 | set.find( MovablePair(e,m)) == set.end() &&
|
---|
| 81 | set.find( MovablePair(m,e)) == set.end() &&
|
---|
| 82 | (m->getQueryFlags() & mQueryMask) &&
|
---|
| 83 | m->isInScene() &&
|
---|
| 84 | e->getWorldBoundingBox().intersects( m->getWorldBoundingBox() ) )
|
---|
| 85 | {
|
---|
| 86 | listener -> queryResult( e, m );
|
---|
| 87 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 88 | if (m->getMovableType() == "Entity")
|
---|
| 89 | {
|
---|
| 90 | Entity* e2 = static_cast<Entity*>(m);
|
---|
| 91 | Entity::ChildObjectListIterator childIt = e2->getAttachedObjectIterator();
|
---|
| 92 | while(childIt.hasMoreElements())
|
---|
| 93 | {
|
---|
| 94 | MovableObject* c = childIt.getNext();
|
---|
| 95 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 96 | e->getWorldBoundingBox().intersects( c->getWorldBoundingBox() ))
|
---|
| 97 | {
|
---|
| 98 | listener->queryResult(e, c);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | set.insert( MovablePair(e,m) );
|
---|
| 104 |
|
---|
| 105 | }
|
---|
| 106 | ++it;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | /** Creates a custom Octree AAB query */
|
---|
| 112 | OctreeAxisAlignedBoxSceneQuery::OctreeAxisAlignedBoxSceneQuery(SceneManager* creator)
|
---|
| 113 | : DefaultAxisAlignedBoxSceneQuery(creator)
|
---|
| 114 | {
|
---|
| 115 | }
|
---|
| 116 | /** Deletes the custom Octree query */
|
---|
| 117 | OctreeAxisAlignedBoxSceneQuery::~OctreeAxisAlignedBoxSceneQuery()
|
---|
| 118 | {}
|
---|
| 119 |
|
---|
| 120 | /** Finds any entities that intersect the AAB for the query. */
|
---|
| 121 | void OctreeAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 122 | {
|
---|
| 123 | std::list < SceneNode * > list;
|
---|
| 124 | //find the nodes that intersect the AAB
|
---|
| 125 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mAABB, list, 0 );
|
---|
| 126 |
|
---|
| 127 | //grab all moveables from the node that intersect...
|
---|
| 128 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 129 | while( it != list.end() )
|
---|
| 130 | {
|
---|
| 131 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 132 | while( oit.hasMoreElements() )
|
---|
| 133 | {
|
---|
| 134 | MovableObject * m = oit.getNext();
|
---|
| 135 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 136 | m->isInScene() &&
|
---|
| 137 | mAABB.intersects( m->getWorldBoundingBox() ) )
|
---|
| 138 | {
|
---|
| 139 | listener -> queryResult( m );
|
---|
| 140 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 141 | if (m->getMovableType() == "Entity")
|
---|
| 142 | {
|
---|
| 143 | Entity* e = static_cast<Entity*>(m);
|
---|
| 144 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 145 | while(childIt.hasMoreElements())
|
---|
| 146 | {
|
---|
| 147 | MovableObject* c = childIt.getNext();
|
---|
| 148 | if (c->getQueryFlags() & mQueryMask)
|
---|
| 149 | {
|
---|
| 150 | listener->queryResult(c);
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | ++it;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | }
|
---|
| 162 | //---------------------------------------------------------------------
|
---|
| 163 | OctreeRaySceneQuery::
|
---|
| 164 | OctreeRaySceneQuery(SceneManager* creator) : DefaultRaySceneQuery(creator)
|
---|
| 165 | {
|
---|
| 166 | }
|
---|
| 167 | //---------------------------------------------------------------------
|
---|
| 168 | OctreeRaySceneQuery::~OctreeRaySceneQuery()
|
---|
| 169 | {}
|
---|
| 170 | //---------------------------------------------------------------------
|
---|
| 171 | void OctreeRaySceneQuery::execute(RaySceneQueryListener* listener)
|
---|
| 172 | {
|
---|
| 173 | std::list < SceneNode * > list;
|
---|
| 174 | //find the nodes that intersect the AAB
|
---|
| 175 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mRay, list, 0 );
|
---|
| 176 |
|
---|
| 177 | //grab all moveables from the node that intersect...
|
---|
| 178 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 179 | while( it != list.end() )
|
---|
| 180 | {
|
---|
| 181 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 182 | while( oit.hasMoreElements() )
|
---|
| 183 | {
|
---|
| 184 | MovableObject * m = oit.getNext();
|
---|
| 185 | if( (m->getQueryFlags() & mQueryMask) && m->isInScene() )
|
---|
| 186 | {
|
---|
| 187 | std::pair<bool, Real> result = mRay.intersects(m->getWorldBoundingBox());
|
---|
| 188 |
|
---|
| 189 | if( result.first )
|
---|
| 190 | {
|
---|
| 191 | listener -> queryResult( m, result.second );
|
---|
| 192 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 193 | if (m->getMovableType() == "Entity")
|
---|
| 194 | {
|
---|
| 195 | Entity* e = static_cast<Entity*>(m);
|
---|
| 196 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 197 | while(childIt.hasMoreElements())
|
---|
| 198 | {
|
---|
| 199 | MovableObject* c = childIt.getNext();
|
---|
| 200 | if (c->getQueryFlags() & mQueryMask)
|
---|
| 201 | {
|
---|
| 202 | result = mRay.intersects(c->getWorldBoundingBox());
|
---|
| 203 | if (result.first)
|
---|
| 204 | {
|
---|
| 205 | listener->queryResult(c, result.second);
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | ++it;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | //---------------------------------------------------------------------
|
---|
| 221 | OctreeSphereSceneQuery::
|
---|
| 222 | OctreeSphereSceneQuery(SceneManager* creator) : DefaultSphereSceneQuery(creator)
|
---|
| 223 | {
|
---|
| 224 | }
|
---|
| 225 | //---------------------------------------------------------------------
|
---|
| 226 | OctreeSphereSceneQuery::~OctreeSphereSceneQuery()
|
---|
| 227 | {}
|
---|
| 228 | //---------------------------------------------------------------------
|
---|
| 229 | void OctreeSphereSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 230 | {
|
---|
| 231 | std::list < SceneNode * > list;
|
---|
| 232 | //find the nodes that intersect the AAB
|
---|
| 233 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mSphere, list, 0 );
|
---|
| 234 |
|
---|
| 235 | //grab all moveables from the node that intersect...
|
---|
| 236 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 237 | while( it != list.end() )
|
---|
| 238 | {
|
---|
| 239 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 240 | while( oit.hasMoreElements() )
|
---|
| 241 | {
|
---|
| 242 | MovableObject * m = oit.getNext();
|
---|
| 243 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 244 | m->isInScene() &&
|
---|
| 245 | mSphere.intersects( m->getWorldBoundingBox() ) )
|
---|
| 246 | {
|
---|
| 247 | listener -> queryResult( m );
|
---|
| 248 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 249 | if (m->getMovableType() == "Entity")
|
---|
| 250 | {
|
---|
| 251 | Entity* e = static_cast<Entity*>(m);
|
---|
| 252 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 253 | while(childIt.hasMoreElements())
|
---|
| 254 | {
|
---|
| 255 | MovableObject* c = childIt.getNext();
|
---|
| 256 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 257 | mSphere.intersects( c->getWorldBoundingBox()))
|
---|
| 258 | {
|
---|
| 259 | listener->queryResult(c);
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | ++it;
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 | //---------------------------------------------------------------------
|
---|
| 270 | OctreePlaneBoundedVolumeListSceneQuery::
|
---|
| 271 | OctreePlaneBoundedVolumeListSceneQuery(SceneManager* creator)
|
---|
| 272 | : DefaultPlaneBoundedVolumeListSceneQuery(creator)
|
---|
| 273 | {
|
---|
| 274 |
|
---|
| 275 | }
|
---|
| 276 | //---------------------------------------------------------------------
|
---|
| 277 | OctreePlaneBoundedVolumeListSceneQuery::~OctreePlaneBoundedVolumeListSceneQuery()
|
---|
| 278 | {}
|
---|
| 279 | //---------------------------------------------------------------------
|
---|
| 280 | void OctreePlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 281 | {
|
---|
| 282 | std::set<SceneNode*> checkedSceneNodes;
|
---|
| 283 |
|
---|
| 284 | PlaneBoundedVolumeList::iterator pi, piend;
|
---|
| 285 | piend = mVolumes.end();
|
---|
| 286 | for (pi = mVolumes.begin(); pi != piend; ++pi)
|
---|
| 287 | {
|
---|
| 288 | std::list < SceneNode * > list;
|
---|
| 289 | //find the nodes that intersect the AAB
|
---|
| 290 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( *pi, list, 0 );
|
---|
| 291 |
|
---|
| 292 | //grab all moveables from the node that intersect...
|
---|
| 293 | std::list < SceneNode * >::iterator it, itend;
|
---|
| 294 | itend = list.end();
|
---|
| 295 | for (it = list.begin(); it != itend; ++it)
|
---|
| 296 | {
|
---|
| 297 | // avoid double-check same scene node
|
---|
| 298 | if (!checkedSceneNodes.insert(*it).second)
|
---|
| 299 | continue;
|
---|
| 300 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 301 | while( oit.hasMoreElements() )
|
---|
| 302 | {
|
---|
| 303 | MovableObject * m = oit.getNext();
|
---|
| 304 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 305 | m->isInScene() &&
|
---|
| 306 | (*pi).intersects( m->getWorldBoundingBox() ) )
|
---|
| 307 | {
|
---|
| 308 | listener -> queryResult( m );
|
---|
| 309 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 310 | if (m->getMovableType() == "Entity")
|
---|
| 311 | {
|
---|
| 312 | Entity* e = static_cast<Entity*>(m);
|
---|
| 313 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 314 | while(childIt.hasMoreElements())
|
---|
| 315 | {
|
---|
| 316 | MovableObject* c = childIt.getNext();
|
---|
| 317 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 318 | (*pi).intersects( c->getWorldBoundingBox()))
|
---|
| 319 | {
|
---|
| 320 | listener->queryResult(c);
|
---|
| 321 | }
|
---|
| 322 | }
|
---|
| 323 | }
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
| 326 | }
|
---|
| 327 | }//for
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 |
|
---|
| 331 | }
|
---|