[692] | 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 | #include <OgreRoot.h>
|
---|
| 40 |
|
---|
| 41 | namespace Ogre
|
---|
| 42 | {
|
---|
| 43 |
|
---|
| 44 | //---------------------------------------------------------------------
|
---|
| 45 | OctreeIntersectionSceneQuery::OctreeIntersectionSceneQuery(SceneManager* creator)
|
---|
| 46 | : DefaultIntersectionSceneQuery(creator)
|
---|
| 47 | {
|
---|
| 48 |
|
---|
| 49 | }
|
---|
| 50 | //---------------------------------------------------------------------
|
---|
| 51 | OctreeIntersectionSceneQuery::~OctreeIntersectionSceneQuery()
|
---|
| 52 | {}
|
---|
| 53 | //---------------------------------------------------------------------
|
---|
| 54 | void OctreeIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener)
|
---|
| 55 | {
|
---|
| 56 | typedef std::pair<MovableObject *, MovableObject *> MovablePair;
|
---|
| 57 | typedef std::set
|
---|
| 58 | < std::pair<MovableObject *, MovableObject *> > MovableSet;
|
---|
| 59 |
|
---|
| 60 | MovableSet set;
|
---|
| 61 |
|
---|
| 62 | // Iterate over all movable types
|
---|
| 63 | Root::MovableObjectFactoryIterator factIt =
|
---|
| 64 | Root::getSingleton().getMovableObjectFactoryIterator();
|
---|
| 65 | while(factIt.hasMoreElements())
|
---|
| 66 | {
|
---|
| 67 | SceneManager::MovableObjectIterator it =
|
---|
| 68 | mParentSceneMgr->getMovableObjectIterator(
|
---|
| 69 | factIt.getNext()->getType());
|
---|
| 70 | while( it.hasMoreElements() )
|
---|
| 71 | {
|
---|
| 72 |
|
---|
| 73 | MovableObject * e = it.getNext();
|
---|
| 74 |
|
---|
| 75 | std::list < SceneNode * > list;
|
---|
| 76 | //find the nodes that intersect the AAB
|
---|
| 77 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( e->getWorldBoundingBox(), list, 0 );
|
---|
| 78 | //grab all moveables from the node that intersect...
|
---|
| 79 | std::list < SceneNode * >::iterator nit = list.begin();
|
---|
| 80 | while( nit != list.end() )
|
---|
| 81 | {
|
---|
| 82 | SceneNode::ObjectIterator oit = (*nit) -> getAttachedObjectIterator();
|
---|
| 83 | while( oit.hasMoreElements() )
|
---|
| 84 | {
|
---|
| 85 | MovableObject * m = oit.getNext();
|
---|
| 86 |
|
---|
| 87 | if( m != e &&
|
---|
| 88 | set.find( MovablePair(e,m)) == set.end() &&
|
---|
| 89 | set.find( MovablePair(m,e)) == set.end() &&
|
---|
| 90 | (m->getQueryFlags() & mQueryMask) &&
|
---|
| 91 | (m->getTypeFlags() & mQueryTypeMask) &&
|
---|
| 92 | m->isInScene() &&
|
---|
| 93 | e->getWorldBoundingBox().intersects( m->getWorldBoundingBox() ) )
|
---|
| 94 | {
|
---|
| 95 | listener -> queryResult( e, m );
|
---|
| 96 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 97 | if (m->getMovableType() == "Entity")
|
---|
| 98 | {
|
---|
| 99 | Entity* e2 = static_cast<Entity*>(m);
|
---|
| 100 | Entity::ChildObjectListIterator childIt = e2->getAttachedObjectIterator();
|
---|
| 101 | while(childIt.hasMoreElements())
|
---|
| 102 | {
|
---|
| 103 | MovableObject* c = childIt.getNext();
|
---|
| 104 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 105 | e->getWorldBoundingBox().intersects( c->getWorldBoundingBox() ))
|
---|
| 106 | {
|
---|
| 107 | listener->queryResult(e, c);
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | set.insert( MovablePair(e,m) );
|
---|
| 113 |
|
---|
| 114 | }
|
---|
| 115 | ++nit;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | /** Creates a custom Octree AAB query */
|
---|
| 122 | OctreeAxisAlignedBoxSceneQuery::OctreeAxisAlignedBoxSceneQuery(SceneManager* creator)
|
---|
| 123 | : DefaultAxisAlignedBoxSceneQuery(creator)
|
---|
| 124 | {
|
---|
| 125 | }
|
---|
| 126 | /** Deletes the custom Octree query */
|
---|
| 127 | OctreeAxisAlignedBoxSceneQuery::~OctreeAxisAlignedBoxSceneQuery()
|
---|
| 128 | {}
|
---|
| 129 |
|
---|
| 130 | /** Finds any entities that intersect the AAB for the query. */
|
---|
| 131 | void OctreeAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 132 | {
|
---|
| 133 | std::list < SceneNode * > list;
|
---|
| 134 | //find the nodes that intersect the AAB
|
---|
| 135 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mAABB, list, 0 );
|
---|
| 136 |
|
---|
| 137 | //grab all moveables from the node that intersect...
|
---|
| 138 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 139 | while( it != list.end() )
|
---|
| 140 | {
|
---|
| 141 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 142 | while( oit.hasMoreElements() )
|
---|
| 143 | {
|
---|
| 144 | MovableObject * m = oit.getNext();
|
---|
| 145 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 146 | (m->getTypeFlags() & mQueryTypeMask) &&
|
---|
| 147 | m->isInScene() &&
|
---|
| 148 | mAABB.intersects( m->getWorldBoundingBox() ) )
|
---|
| 149 | {
|
---|
| 150 | listener -> queryResult( m );
|
---|
| 151 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 152 | if (m->getMovableType() == "Entity")
|
---|
| 153 | {
|
---|
| 154 | Entity* e = static_cast<Entity*>(m);
|
---|
| 155 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 156 | while(childIt.hasMoreElements())
|
---|
| 157 | {
|
---|
| 158 | MovableObject* c = childIt.getNext();
|
---|
| 159 | if (c->getQueryFlags() & mQueryMask)
|
---|
| 160 | {
|
---|
| 161 | listener->queryResult(c);
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | ++it;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 | //---------------------------------------------------------------------
|
---|
| 174 | OctreeRaySceneQuery::
|
---|
| 175 | OctreeRaySceneQuery(SceneManager* creator) : DefaultRaySceneQuery(creator)
|
---|
| 176 | {
|
---|
| 177 | }
|
---|
| 178 | //---------------------------------------------------------------------
|
---|
| 179 | OctreeRaySceneQuery::~OctreeRaySceneQuery()
|
---|
| 180 | {}
|
---|
| 181 | //---------------------------------------------------------------------
|
---|
| 182 | void OctreeRaySceneQuery::execute(RaySceneQueryListener* listener)
|
---|
| 183 | {
|
---|
| 184 | std::list < SceneNode * > list;
|
---|
| 185 | //find the nodes that intersect the AAB
|
---|
| 186 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mRay, list, 0 );
|
---|
| 187 |
|
---|
| 188 | //grab all moveables from the node that intersect...
|
---|
| 189 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 190 | while( it != list.end() )
|
---|
| 191 | {
|
---|
| 192 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 193 | while( oit.hasMoreElements() )
|
---|
| 194 | {
|
---|
| 195 | MovableObject * m = oit.getNext();
|
---|
| 196 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 197 | (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() )
|
---|
| 198 | {
|
---|
| 199 | std::pair<bool, Real> result = mRay.intersects(m->getWorldBoundingBox());
|
---|
| 200 |
|
---|
| 201 | if( result.first )
|
---|
| 202 | {
|
---|
| 203 | listener -> queryResult( m, result.second );
|
---|
| 204 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 205 | if (m->getMovableType() == "Entity")
|
---|
| 206 | {
|
---|
| 207 | Entity* e = static_cast<Entity*>(m);
|
---|
| 208 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 209 | while(childIt.hasMoreElements())
|
---|
| 210 | {
|
---|
| 211 | MovableObject* c = childIt.getNext();
|
---|
| 212 | if (c->getQueryFlags() & mQueryMask)
|
---|
| 213 | {
|
---|
| 214 | result = mRay.intersects(c->getWorldBoundingBox());
|
---|
| 215 | if (result.first)
|
---|
| 216 | {
|
---|
| 217 | listener->queryResult(c, result.second);
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | ++it;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 |
|
---|
| 232 | //---------------------------------------------------------------------
|
---|
| 233 | OctreeSphereSceneQuery::
|
---|
| 234 | OctreeSphereSceneQuery(SceneManager* creator) : DefaultSphereSceneQuery(creator)
|
---|
| 235 | {
|
---|
| 236 | }
|
---|
| 237 | //---------------------------------------------------------------------
|
---|
| 238 | OctreeSphereSceneQuery::~OctreeSphereSceneQuery()
|
---|
| 239 | {}
|
---|
| 240 | //---------------------------------------------------------------------
|
---|
| 241 | void OctreeSphereSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 242 | {
|
---|
| 243 | std::list < SceneNode * > list;
|
---|
| 244 | //find the nodes that intersect the AAB
|
---|
| 245 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mSphere, list, 0 );
|
---|
| 246 |
|
---|
| 247 | //grab all moveables from the node that intersect...
|
---|
| 248 | std::list < SceneNode * >::iterator it = list.begin();
|
---|
| 249 | while( it != list.end() )
|
---|
| 250 | {
|
---|
| 251 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 252 | while( oit.hasMoreElements() )
|
---|
| 253 | {
|
---|
| 254 | MovableObject * m = oit.getNext();
|
---|
| 255 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 256 | (m->getTypeFlags() & mQueryTypeMask) &&
|
---|
| 257 | m->isInScene() &&
|
---|
| 258 | mSphere.intersects( m->getWorldBoundingBox() ) )
|
---|
| 259 | {
|
---|
| 260 | listener -> queryResult( m );
|
---|
| 261 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 262 | if (m->getMovableType() == "Entity")
|
---|
| 263 | {
|
---|
| 264 | Entity* e = static_cast<Entity*>(m);
|
---|
| 265 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 266 | while(childIt.hasMoreElements())
|
---|
| 267 | {
|
---|
| 268 | MovableObject* c = childIt.getNext();
|
---|
| 269 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 270 | mSphere.intersects( c->getWorldBoundingBox()))
|
---|
| 271 | {
|
---|
| 272 | listener->queryResult(c);
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | ++it;
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | //---------------------------------------------------------------------
|
---|
| 283 | OctreePlaneBoundedVolumeListSceneQuery::
|
---|
| 284 | OctreePlaneBoundedVolumeListSceneQuery(SceneManager* creator)
|
---|
| 285 | : DefaultPlaneBoundedVolumeListSceneQuery(creator)
|
---|
| 286 | {
|
---|
| 287 |
|
---|
| 288 | }
|
---|
| 289 | //---------------------------------------------------------------------
|
---|
| 290 | OctreePlaneBoundedVolumeListSceneQuery::~OctreePlaneBoundedVolumeListSceneQuery()
|
---|
| 291 | {}
|
---|
| 292 | //---------------------------------------------------------------------
|
---|
| 293 | void OctreePlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener)
|
---|
| 294 | {
|
---|
| 295 | std::set<SceneNode*> checkedSceneNodes;
|
---|
| 296 |
|
---|
| 297 | PlaneBoundedVolumeList::iterator pi, piend;
|
---|
| 298 | piend = mVolumes.end();
|
---|
| 299 | for (pi = mVolumes.begin(); pi != piend; ++pi)
|
---|
| 300 | {
|
---|
| 301 | std::list < SceneNode * > list;
|
---|
| 302 | //find the nodes that intersect the AAB
|
---|
| 303 | static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( *pi, list, 0 );
|
---|
| 304 |
|
---|
| 305 | //grab all moveables from the node that intersect...
|
---|
| 306 | std::list < SceneNode * >::iterator it, itend;
|
---|
| 307 | itend = list.end();
|
---|
| 308 | for (it = list.begin(); it != itend; ++it)
|
---|
| 309 | {
|
---|
| 310 | // avoid double-check same scene node
|
---|
| 311 | if (!checkedSceneNodes.insert(*it).second)
|
---|
| 312 | continue;
|
---|
| 313 | SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator();
|
---|
| 314 | while( oit.hasMoreElements() )
|
---|
| 315 | {
|
---|
| 316 | MovableObject * m = oit.getNext();
|
---|
| 317 | if( (m->getQueryFlags() & mQueryMask) &&
|
---|
| 318 | (m->getTypeFlags() & mQueryTypeMask) &&
|
---|
| 319 | m->isInScene() &&
|
---|
| 320 | (*pi).intersects( m->getWorldBoundingBox() ) )
|
---|
| 321 | {
|
---|
| 322 | listener -> queryResult( m );
|
---|
| 323 | // deal with attached objects, since they are not directly attached to nodes
|
---|
| 324 | if (m->getMovableType() == "Entity")
|
---|
| 325 | {
|
---|
| 326 | Entity* e = static_cast<Entity*>(m);
|
---|
| 327 | Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator();
|
---|
| 328 | while(childIt.hasMoreElements())
|
---|
| 329 | {
|
---|
| 330 | MovableObject* c = childIt.getNext();
|
---|
| 331 | if (c->getQueryFlags() & mQueryMask &&
|
---|
| 332 | (*pi).intersects( c->getWorldBoundingBox()))
|
---|
| 333 | {
|
---|
| 334 | listener->queryResult(c);
|
---|
| 335 | }
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | }//for
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 |
|
---|
| 345 | }
|
---|