//--------------------------------------------------------------------- void DefaultPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) { // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end(); for (pi = mVolumes.begin(); pi != piend; ++pi) { PlaneBoundedVolume& vol = *pi; // Do AABB / plane volume test if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && vol.intersects(a->getWorldBoundingBox())) { if (!listener->queryResult(a)) return; break; } } } } }
//--------------------------------------------------------------------- void DefaultAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener) { // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && mAABB.intersects(a->getWorldBoundingBox())) { if (!listener->queryResult(a)) return; } } } }
//--------------------------------------------------------------------- void DefaultSphereSceneQuery::execute(SceneQueryListener* listener) { Sphere testSphere; // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; // Skip unattached if (!a->isInScene() || !(a->getQueryFlags() & mQueryMask)) continue; // Do sphere / sphere test testSphere.setCenter(a->getParentNode()->_getDerivedPosition()); testSphere.setRadius(a->getBoundingRadius()); if (mSphere.intersects(testSphere)) { if (!listener->queryResult(a)) return; } } } }
//--------------------------------------------------------------------- void PagingLandScapeOctreePlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) { PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end(); for (pi = mVolumes.begin(); pi != piend; ++pi) { std::list < SceneNode* > list; //find the nodes that intersect the AAB static_cast< PagingLandScapeOctreeSceneManager* >(mParentSceneMgr)->findNodesIn(*pi, list, 0); //grab all moveables from the node that intersect... std::list < SceneNode* >::iterator it = list.begin(); while (it != list.end()) { SceneNode::ObjectIterator oit = (*it)->getAttachedObjectIterator(); while (oit.hasMoreElements()) { MovableObject* m = oit.getNext(); if ((m->getQueryFlags() & mQueryMask) && m->isInScene() && (*pi).intersects(m->getWorldBoundingBox())) { listener->queryResult(m); } } ++it; } } }
//--------------------------------------------------------------------- void PagingLandScapeOctreeRaySceneQuery::execute( RaySceneQueryListener* listener ) { std::list < SceneNode* > list; //find the nodes that intersect the AAB static_cast< PagingLandScapeOctreeSceneManager* >( mParentSceneMgr )->findNodesIn( mRay, list, 0 ); //grab all movables from the node that intersect... std::list < SceneNode* >::iterator it = list.begin( ); while ( it != list.end( ) ) { SceneNode::ObjectIterator oit = ( *it )->getAttachedObjectIterator( ); while ( oit.hasMoreElements( ) ) { MovableObject* m = oit.getNext( ); if ( ( m->getQueryFlags( ) & mQueryMask ) && m->isInScene( ) ) { std::pair< bool, Real > result = mRay.intersects( m->getWorldBoundingBox( ) ); if ( result.first ) { listener->queryResult( m, result.second ); } } } ++it; } }
//--------------------------------------------------------------------- void PCZPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) { std::set<SceneNode*> checkedSceneNodes; PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end(); for (pi = mVolumes.begin(); pi != piend; ++pi) { PCZSceneNodeList list; //find the nodes that intersect the Plane bounded Volume static_cast<PCZSceneManager*>( mParentSceneMgr ) -> findNodesIn( *pi, list, mStartZone, (PCZSceneNode*)mExcludeNode ); //grab all moveables from the node that intersect... PCZSceneNodeList::iterator it, itend; itend = list.end(); for (it = list.begin(); it != itend; ++it) { // avoid double-check same scene node if (!checkedSceneNodes.insert(*it).second) continue; SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() && (*pi).intersects( m->getWorldBoundingBox() ) ) { listener -> queryResult( m ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask && (*pi).intersects( c->getWorldBoundingBox())) { listener->queryResult(c); } } } } } } }//for // reset startzone and exclude node mStartZone = 0; mExcludeNode = 0; }
//--------------------------------------------------------------------- void PCZRaySceneQuery::execute(RaySceneQueryListener* listener) { PCZSceneNodeList list; //find the nodes that intersect the Ray static_cast<PCZSceneManager*>( mParentSceneMgr ) -> findNodesIn( mRay, list, mStartZone, (PCZSceneNode*)mExcludeNode ); //grab all moveables from the node that intersect... PCZSceneNodeList::iterator it = list.begin(); while( it != list.end() ) { SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() ) { std::pair<bool, Real> result = mRay.intersects(m->getWorldBoundingBox()); if( result.first ) { listener -> queryResult( m, result.second ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask) { result = mRay.intersects(c->getWorldBoundingBox()); if (result.first) { listener->queryResult(c, result.second); } } } } } } } ++it; } // reset startzone and exclude node mStartZone = 0; mExcludeNode = 0; }
/** Finds any entities that intersect the AAB for the query. */ void OctreeAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener) { std::list< SceneNode * > _list; //find the nodes that intersect the AAB static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mAABB, _list, 0 ); //grab all moveables from the node that intersect... std::list< SceneNode * >::iterator it = _list.begin(); while( it != _list.end() ) { SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() && mAABB.intersects( m->getWorldBoundingBox() ) ) { listener -> queryResult( m ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask) { listener->queryResult(c); } } } } } ++it; } }
//--------------------------------------------------------------------- void DefaultRaySceneQuery::execute(RaySceneQueryListener* listener) { // Note that becuase we have no scene partitioning, we actually // perform a complete scene search even if restricted results are // requested; smarter scene manager queries can utilise the paritioning // of the scene in order to reduce the number of intersection tests // required to fulfil the query // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; if( (a->getQueryFlags() & mQueryMask) && a->isInScene()) { // Do ray / box test std::pair<bool, Real> result = mRay.intersects(a->getWorldBoundingBox()); if (result.first) { if (!listener->queryResult(a, result.second)) return; } } } } }
//--------------------------------------------------------------------- void OctreeIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener) { typedef std::pair<MovableObject *, MovableObject *> MovablePair; typedef std::set < std::pair<MovableObject *, MovableObject *> > MovableSet; MovableSet set; // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator it = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while( it.hasMoreElements() ) { MovableObject * e = it.getNext(); std::list< SceneNode * > list; //find the nodes that intersect the AAB static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( e->getWorldBoundingBox(), list, 0 ); //grab all moveables from the node that intersect... std::list< SceneNode * >::iterator nit = list.begin(); while( nit != list.end() ) { SceneNode::ObjectIterator oit = (*nit) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( m != e && set.find( MovablePair(e,m)) == set.end() && set.find( MovablePair(m,e)) == set.end() && (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() && e->getWorldBoundingBox().intersects( m->getWorldBoundingBox() ) ) { listener -> queryResult( e, m ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e2 = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e2->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask && e->getWorldBoundingBox().intersects( c->getWorldBoundingBox() )) { listener->queryResult(e, c); } } } } set.insert( MovablePair(e,m) ); } ++nit; } } } }
//--------------------------------------------------------------------- void DefaultIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener) { // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip entire section if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; // Skip if a does not pass the mask if (!(a->getQueryFlags() & mQueryMask) || !a->isInScene()) continue; // Check against later objects in the same group SceneManager::MovableObjectIterator objItB = objItA; while (objItB.hasMoreElements()) { MovableObject* b = objItB.getNext(); // Apply mask to b (both must pass) if ((b->getQueryFlags() & mQueryMask) && b->isInScene()) { const AxisAlignedBox& box1 = a->getWorldBoundingBox(); const AxisAlignedBox& box2 = b->getWorldBoundingBox(); if (box1.intersects(box2)) { if (!listener->queryResult(a, b)) return; } } } // Check against later groups Root::MovableObjectFactoryIterator factItLater = factIt; while (factItLater.hasMoreElements()) { SceneManager::MovableObjectIterator objItC = mParentSceneMgr->getMovableObjectIterator( factItLater.getNext()->getType()); while (objItC.hasMoreElements()) { MovableObject* c = objItC.getNext(); // skip entire section if type doesn't match if (!(c->getTypeFlags() & mQueryTypeMask)) break; // Apply mask to c (both must pass) if ((c->getQueryFlags() & mQueryMask) && c->isInScene()) { const AxisAlignedBox& box1 = a->getWorldBoundingBox(); const AxisAlignedBox& box2 = c->getWorldBoundingBox(); if (box1.intersects(box2)) { if (!listener->queryResult(a, c)) return; } } } } } } }