//--------------------------------------------------------------------- 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 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 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 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; } } } } } } }