Esempio n. 1
0
    //---------------------------------------------------------------------
    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;
    }
Esempio n. 2
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;
    }
Esempio n. 3
0
    /** Adds the attached objects of this PCZSceneNode into the queue. */
    void PCZSceneNode::_addToRenderQueue( Camera* cam, 
                                          RenderQueue *queue, 
                                          bool onlyShadowCasters, 
                                          VisibleObjectsBoundsInfo* visibleBounds )
    {
        ObjectMap::iterator mit = mObjectsByName.begin();

        while ( mit != mObjectsByName.end() )
        {
#if OGRE_NODE_STORAGE_LEGACY
            MovableObject * mo = mit->second;
#else
            MovableObject * mo = *mit;
#endif

            mo->_notifyCurrentCamera(cam);
            if ( mo->isVisible() &&
                (!onlyShadowCasters || mo->getCastShadows()))
            {
                mo -> _updateRenderQueue( queue );

                if (visibleBounds)
                {
                    visibleBounds->merge(mo->getWorldBoundingBox(true), 
                                         mo->getWorldBoundingSphere(true), 
                                         cam);
                }
            }
            ++mit;
        }
    }
	//---------------------------------------------------------------------
	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 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;
    }
}
Esempio n. 7
0
//---------------------------------------------------------------------
void OctreeSphereSceneQuery::execute(SceneQueryListener* listener)
{
    std::list< SceneNode * > _list;
    //find the nodes that intersect the AAB
    static_cast<OctreeSceneManager*>( mParentSceneMgr ) -> findNodesIn( mSphere, _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() && 
                mSphere.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 &&
                            mSphere.intersects( c->getWorldBoundingBox()))
                        {
                            listener->queryResult(c);
                        }
                    }
                }
            }
        }

        ++it;
    }
}
Esempio n. 8
0
AxisAlignedBox getWorldAABB(SceneNode* node)
{
	AxisAlignedBox aabb;

	// merge with attached objects
	for (int i=0; i<node->numAttachedObjects(); ++i)
	{
		MovableObject* o = node->getAttachedObject(i);
		aabb.merge(o->getWorldBoundingBox(true));
	}

	// merge with child nodes
	for (int i=0; i<node->numChildren(); ++i)
	{
		SceneNode* child = static_cast<SceneNode*>(node->getChild(i));
		aabb.merge( getWorldAABB(child) );
	}

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

	}
    //-----------------------------------------------------------------------
    bool BspRaySceneQuery::processLeaf(const BspNode* leaf, const Ray& tracingRay, 
        RaySceneQueryListener* listener, Real maxDistance, Real traceDistance)
    {
        const BspNode::IntersectingObjectSet& objects = leaf->getObjects();

        BspNode::IntersectingObjectSet::const_iterator i, iend;
        iend = objects.end();
        //Check ray against objects
        for(i = objects.begin(); i != iend; ++i)
        {
            // cast away constness, constness of node is nothing to do with objects
            MovableObject* obj = const_cast<MovableObject*>(*i);
            // Skip this object if not enabled
            if(!(obj->getQueryFlags() & mQueryMask) ||
				!((obj->getTypeFlags() & mQueryTypeMask)))
                continue;

            // check we haven't reported this one already
            // (objects can be intersecting more than one node)
            if (mObjsThisQuery.find(obj) != mObjsThisQuery.end())
                continue;

            //Test object as bounding box
            std::pair<bool, Real> result = 
                tracingRay.intersects(obj->getWorldBoundingBox());
            // if the result came back positive and intersection point is inside
            // the node, fire the event handler
            if(result.first && result.second <= maxDistance)
            {
                if (!listener->queryResult(obj, result.second + traceDistance))
					return false;
            }
        }


        // Check ray against brushes
        if (mQueryTypeMask & SceneManager::WORLD_GEOMETRY_TYPE_MASK)
        {
            const BspNode::NodeBrushList& brushList = leaf->getSolidBrushes();
            BspNode::NodeBrushList::const_iterator bi, biend;
            biend = brushList.end();
            bool intersectedBrush = false;
            for (bi = brushList.begin(); bi != biend; ++bi)
            {
                BspNode::Brush* brush = *bi;
                

                std::pair<bool, Real> result = Math::intersects(tracingRay, brush->planes, true);
                // if the result came back positive and intersection point is inside
                // the node, check if this brush is closer
                if(result.first && result.second <= maxDistance)
                {
                    intersectedBrush = true;
                    if(mWorldFragmentType == SceneQuery::WFT_SINGLE_INTERSECTION)
                    {
                        // We're interested in a single intersection
                        // Have to create these 
                        SceneQuery::WorldFragment* wf = OGRE_ALLOC_T(SceneQuery::WorldFragment, 1, MEMCATEGORY_SCENE_CONTROL);
                        wf->fragmentType = SceneQuery::WFT_SINGLE_INTERSECTION;
                        wf->singleIntersection = tracingRay.getPoint(result.second);
                        // save this so we can clean up later
                        mSingleIntersections.push_back(wf);
                        if (!listener->queryResult(wf, result.second + traceDistance))
							return false;
                    }
                    else if (mWorldFragmentType ==  SceneQuery::WFT_PLANE_BOUNDED_REGION)
                    {
                        // We want the whole bounded volume
                        assert((*bi)->fragment.fragmentType == SceneQuery::WFT_PLANE_BOUNDED_REGION);
                        if (!listener->queryResult(const_cast<WorldFragment*>(&(brush->fragment)), 
                            result.second + traceDistance))
							return false; 

                    }
                }
            }
            if (intersectedBrush)
            {
                return false; // stop here
            }
        }

        return true;

    } 
Esempio n. 11
0
//---------------------------------------------------------------------
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 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 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;
							}
						}
					}

				}

			}


		}

	}