예제 #1
0
  void RendererSystemComponent::DestroySceneNode(Ogre::SceneNode* sceneNode)
  {
    Ogre::Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* childSceneNode = static_cast<SceneNode*>(children.getNext());
      this->DestroySceneNode(childSceneNode);
    }

    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());
        
        Ogre::Entity::ChildObjectListIterator childObjects = entity->getAttachedObjectIterator();

        while(childObjects.hasMoreElements())
        {
          m_scene->GetSceneManager()->destroyMovableObject(childObjects.getNext());
        }
      }

      m_scene->GetSceneManager()->destroyMovableObject(object);
    }

    sceneNode->removeAndDestroyAllChildren();
  }
예제 #2
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;
    }
예제 #3
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;
    }
예제 #4
0
파일: SubObject.cpp 프로젝트: mfichman/warp
/** Destructor */
SubObject::~SubObject() {

	// Destroy all attached entities and scene nodes
	unsigned short count = node_->numAttachedObjects();
	for (unsigned short i = 0; i < count; i++) {
		MovableObject* obj = node_->getAttachedObject(0U);
		node_->detachObject((unsigned short)0);
		node_->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}
	node_->getParentSceneNode()->removeAndDestroyChild(node_->getName());

	// Remove from world if the subobject was separated off
	if (body_.get()) { 
		body_->setUserPointer(0);
		game_->getWorld()->removeCollisionObject(body_.get()); 
	}
}
예제 #5
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;
    }

}
예제 #6
0
  void RendererSystemComponent::LinkSkeletons(Ogre::SceneNode* sceneNode, RendererSystemComponent::SkeletonList* skeletons)
  {
    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());

        if (entity->hasSkeleton())
        {
          Ogre::Skeleton::BoneIterator boneIterator = entity->getSkeleton()->getBoneIterator();

          while(boneIterator.hasMoreElements())
          {
            Ogre::Bone* oBone = boneIterator.getNext();
            oBone->setManuallyControlled(true);

            /*Entity *axis = m_scene->GetSceneManager()->createEntity(oBone->getName() + "_axis", "/data/entities/meshes/axes.mesh");
            TagPoint* tagPoint = entity->attachObjectToBone(oBone->getName(), axis);
            tagPoint->setScale(0.005f, 0.005f, 0.005f);*/
          }

          skeletons->push_back(entity->getSkeleton());
        }
      }
    }

    Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* child = static_cast<SceneNode*>(children.getNext());
      this->LinkSkeletons(child, skeletons);
    }
  }
// -------------------------------------------------------------------------
OgreBulletDynamics::RigidBody* OgreBulletListener::getBodyUnderCursorUsingOgre(Ogre::Vector3 &intersectionPoint, Ray &rayTo)
{
    rayTo = mCamera->getCameraToViewportRay (mInputListener->getAbsMouseX(), mInputListener->getAbsMouseY());

    mRayQuery->setRay (rayTo);
    const RaySceneQueryResult& result = mRayQuery->execute();
    if (!result.empty())
    {
        RaySceneQueryResult::const_iterator i = result.begin();

        mRayQuery->setSortByDistance (true, 1);//only one hit
        while((i != result.end()))
        {
            SceneNode *node = i->movable->getParentSceneNode() ;
#if (OGRE_VERSION >=  ((1 << 16) | (5 << 8) | 0)) // must have at least shoggoth (1.5.0)
			intersectionPoint = node->_getDerivedPosition ();
#else
			intersectionPoint = node->getWorldPosition ();
#endif
            const unsigned short num = node->numAttachedObjects();
            MovableObject* movable;
            for (unsigned short cur = 0;cur < num; cur++)
            {
                movable = node->getAttachedObject(cur);
                if (movable->getMovableType() == OgreBulletCollisions::Object::mMovableType) 
                {
                    OgreBulletCollisions::Object *object = static_cast <OgreBulletCollisions::Object *>(movable);
                    OgreBulletDynamics::RigidBody *body = static_cast <OgreBulletDynamics::RigidBody *>(object);
                    setDebugText ("Hit :" + body->getName());

                    return body;
                }
            }
            ++i;
        }	
    }// if results.	 
    return 0;
}
예제 #8
0
bool OcclusionQuery::isPotentialOccluder(Ogre::SceneNode* node)
{
    bool result = false;
    for (unsigned int i=0; i < node->numAttachedObjects(); ++i)
    {
        MovableObject* ob = node->getAttachedObject(i);
        std::string type = ob->getMovableType();
        if (type == "Entity")
        {
            Entity* ent = static_cast<Entity*>(ob);
            for (unsigned int j=0; j < ent->getNumSubEntities(); ++j)
            {
                // if any sub entity has a material with depth write off,
                // consider the object as not an occluder
                MaterialPtr mat = ent->getSubEntity(j)->getMaterial();

                Material::TechniqueIterator techIt = mat->getTechniqueIterator();
                while (techIt.hasMoreElements())
                {
                    Technique* tech = techIt.getNext();
                    Technique::PassIterator passIt = tech->getPassIterator();
                    while (passIt.hasMoreElements())
                    {
                        Pass* pass = passIt.getNext();

                        if (pass->getDepthWriteEnabled() == false)
                            return false;
                        else
                            result = true;
                    }
                }
            }
        }
    }
    return result;
}
예제 #9
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;
            }

        }
    }
}
예제 #10
0
파일: Object.cpp 프로젝트: mfichman/warp
Object::~Object() {

	// Notify projectiles that the object is toast
	clearAllTrackers();
	//cout << "Collecting " << name_ << endl;

	// Un-track
	if (target_) target_->removeTracker(this);

	// Clean up physics
	game_->getWorld()->removeCollisionObject(body_.get());

	// Destroy all subobjects
	subObjects_.clear();

	// Destroy objects attached to the scene node
	while (node_->numAttachedObjects() > 0) {
		MovableObject* obj = node_->getAttachedObject(0U);
		node_->detachObject((unsigned short)0U);
		node_->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}

	// Destroy all attached entities and scene nodes
	SceneNode::ChildNodeIterator i = node_->getChildIterator();
	while (i.hasMoreElements()) {
		SceneNode* node = static_cast<SceneNode*>(i.getNext());
		MovableObject* obj = node->getAttachedObject(0U);
		node->detachObject((unsigned short)0U);
		node->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}
	node_->removeAndDestroyAllChildren();
	node_->getParentSceneNode()->removeAndDestroyChild(node_->getName());

	// Clean up scripting
	lua_State* env = game_->getScriptState();
	StackCheck check(env);
	lua_getref(env, table_);
	
	lua_pushnil(env);
	lua_setfield(env, -2, "__thiscpp");

	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "addEntity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setEntity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "addParticleSystem");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setParticleSystem");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "set");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "explode");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "destroy");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "target");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setPosition");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getPosition");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setVelocity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getVelocity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setOrientation");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getOrientation");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "createMissile");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getTarget");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setTarget");
	lua_unref(env, table_);
}