void GameBodyObject::DumpNodes(NxOgre::StringPairList &l, Ogre::Node *n, int level, int nid) 
	{

		Ogre::SceneNode::ObjectIterator object_it = ((Ogre::SceneNode *)n)->getAttachedObjectIterator();
		Ogre::Node::ChildNodeIterator node_it = n->getChildIterator();
		
		Ogre::MovableObject *m;
		Ogre::Entity *e;

		if (level != 0) 
		{
			l.insert(
				"Node" + 
				Ogre::StringConverter::toString(nid) + 
				"-Position", 
				Ogre::StringConverter::toString(n->getPosition()));
		}
		
		int i=0;
		while(object_it.hasMoreElements()) 
		{
			
			m = object_it.getNext();
			
			if (m->getMovableType() == "Entity") 
			{
				e = static_cast<Ogre::Entity*>(m);
				NxOgre::NxString entitySuffix = "";
				
				
				if (i > 0)
				{
					entitySuffix = Ogre::StringConverter::toString(i);
				}
					
				if (level == 0) 
				{
					l.insert("Entity" + entitySuffix, e->getMesh()->getName());
				}
				
				else 
				{
					l.insert(
							"Node" + 
							Ogre::StringConverter::toString(nid) +
							"-Entity" +
							entitySuffix,
							e->getMesh()->getName()
						);
				}
			}
			i++;
		}

		while(node_it.hasMoreElements()) 
		{
			DumpNodes(l, node_it.getNext(), level + 1, nid++);
		}

	}
	Object* ObjectManager::collisionAABB(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, int queryMask)
	{
		Ogre::Vector3 direction = toPoint - fromPoint;
		Ogre::Ray ray(fromPoint, direction);
		mRayQuery->setRay(ray);
		mRayQuery->setQueryMask(queryMask);
		// The rays are sorted by the distance query set, [very important]
		mRayQuery->setSortByDistance(true);

		Ogre::RaySceneQueryResult& result = mRayQuery->execute();
		Ogre::RaySceneQueryResult::iterator itr = result.begin();

		// Just get the nearest object
		if (itr != result.end() && itr->movable)
		{
			Ogre::MovableObject *object =  itr->movable;
			Ogre::Vector3 pos = object->getParentSceneNode()->getPosition();
			// If the current starting point of an object in the distance is less than a predetermined range
			// then return this obj
			// Avoid using the square root operation squaredLength
			if ((pos - fromPoint).squaredLength() <= direction.squaredLength())
				return getObject(itr->movable->getName());
		}

		return NULL;
	}
void OLMeshTracker::UpdateSubNodes(Ogre::Node* regionNode, Ogre::Node* node, bool recurse, Ogre::MeshPtr meshP) {
	if (recurse && node->numChildren() > 0) {
		// if node has more children nodes, visit them recursivily
		Ogre::SceneNode::ChildNodeIterator nodeChildIterator = node->getChildIterator();
		while (nodeChildIterator.hasMoreElements()) {
			Ogre::Node* nodeChild = nodeChildIterator.getNext();
			// 'false' causes it to not visit sub-children which are included in parent and pos relative to parent
			UpdateSubNodes(regionNode, nodeChild, true, meshP);
		}
	}
	// children taken care of... check for attached objects to this node
	Ogre::SceneNode* snode = (Ogre::SceneNode*)node;
	Ogre::SceneNode::ObjectIterator snodeObjectIterator = snode->getAttachedObjectIterator();
	while (snodeObjectIterator.hasMoreElements()) {
		Ogre::MovableObject* snodeObject = snodeObjectIterator.getNext();
		if (snodeObject->getMovableType() == "Entity") {
			Ogre::Entity* snodeEntity = (Ogre::Entity*)snodeObject;
			Ogre::MeshPtr entityMesh = snodeEntity->getMesh();
			if (entityMesh == meshP) {
				snode->needUpdate(true);
				// LG::Log("OLMeshTracker::UpdateSubNodes: setting node update for %s", snode->getName().c_str());
			}
		}
	}
	return;
}
//-----------------------------------------------------------------------------------------
bool CSceneManagerEditor::_setSkydomeActive(OgitorsPropertyBase* property, const bool& value)
{
    if(value && mSkyBoxActive->get())
        mSkyBoxActive->set(false);

    if(value && mSkyDomeMaterial->get() == "")
    {
        mSystem->DisplayMessageDialog(OTR("You must first define a SkyDome Material!"), DLGTYPE_OK); 
        return false;
    }

    if(mHandle)
    {
        try
        {
            mHandle->setSkyDome(value ,mSkyDomeMaterial->get());        
            if(value)
            {
                Ogre::SceneNode *node = mHandle->getSkyDomeNode();
                Ogre::SceneNode::ObjectIterator it = node->getAttachedObjectIterator();
                while(it.hasMoreElements())
                {
                    Ogre::MovableObject *object = it.getNext();
                    object->setVisibilityFlags(0x7F000000);
                }
            }
        }
        catch(...)
        {
            mSystem->DisplayMessageDialog(OTR("The Material supplied is not compatible with Sky Dome!"), DLGTYPE_OK); 
            return false;
        }
    }
    return true;
}
Exemple #5
0
void CObject::changeState(EEntityStateTypes eState) {
  switch (m_uiType) {
  case OBJECT_GREEN_BUSH:
  case OBJECT_LIGHT_STONE:
    if (eState == EST_LIFTED) {
      btRigidBody *pRB = btRigidBody::upcast(this->getCollisionObject());
      ASSERT(pRB);

      m_pMap->getPhysicsManager()->getWorld()->removeCollisionObject(pRB);
      m_pMap->getPhysicsManager()->getWorld()->addRigidBody(pRB, COL_DAMAGE_P, MASK_DAMAGE_P_COLLIDES_WITH);

      // Entities now cast shadows
      Ogre::SceneNode::ObjectIterator itObject = this->getSceneNode()->getAttachedObjectIterator();
      while (itObject.hasMoreElements()) {
        Ogre::MovableObject* pObject = static_cast<Ogre::MovableObject*>(itObject.getNext());
        pObject->setCastShadows(true);
      }
    }
    else if (eState == EST_THROWN) {
      btRigidBody *pRB = btRigidBody::upcast(this->getCollisionObject());
      ASSERT(pRB);

      pRB->setLinearFactor(btVector3(1, 1, 1));
      pRB->setAngularFactor(0);
      pRB->activate();
    }
  break;
  }
  CWorldEntity::changeState(eState);
}
void OGRE3DPointRenderable::destroyNode(Ogre::SceneNode* node)
{
 
 if (node == 0)
  return;
 
 Ogre::SceneNode::ObjectIterator object_it = node->getAttachedObjectIterator();
 Ogre::MovableObject *m;

 while(object_it.hasMoreElements())
 {
  m = object_it.getNext();

  // Move Cameras to RootSceneNodes
  if (m->getMovableType() == "Camera")
  {
   node->detachObject(m);
   mRenderSystem->getSceneManager()->getRootSceneNode()->attachObject(m);
  }
  // Everything else gets destroyed.
  else
   mRenderSystem->getSceneManager()->destroyMovableObject(m);
 }
 
 node->detachAllObjects();
 node->removeAndDestroyAllChildren();
 
 mRenderSystem->getSceneManager()->destroySceneNode(node);
}
Exemple #7
0
void Objects::clearSceneNode (Ogre::SceneNode *node)
{
    for (int i=node->numAttachedObjects()-1; i>=0; --i)
    {
        Ogre::MovableObject *object = node->getAttachedObject (i);

        // for entities, destroy any objects attached to bones
        if (object->getTypeFlags () == Ogre::SceneManager::ENTITY_TYPE_MASK)
        {
            Ogre::Entity* ent = static_cast<Ogre::Entity*>(object);
            Ogre::Entity::ChildObjectListIterator children = ent->getAttachedObjectIterator ();
            while (children.hasMoreElements())
            {
                mRenderer.getScene ()->destroyMovableObject (children.getNext ());
            }
        }

        node->detachObject (object);
        mRenderer.getScene()->destroyMovableObject (object);
    }

    Ogre::Node::ChildNodeIterator it = node->getChildIterator ();
    while (it.hasMoreElements ())
    {
        clearSceneNode(static_cast<Ogre::SceneNode*>(it.getNext ()));
    }
}
Exemple #8
0
boolean COgreObject::getFirstEntityInHierarchy(Ogre::SceneNode* pNode, Ogre::Entity*& pEntity) const
{
	for(uint32 i=0; i<pNode->numAttachedObjects(); i++)
	{
		Ogre::MovableObject* pMovableObject = pNode->getAttachedObject(0);
		if(pMovableObject->getMovableType() == Ogre::EntityFactory::FACTORY_TYPE_NAME)
		{
			pEntity = dynamic_cast<Ogre::Entity*>(pMovableObject);
			return true;
		}
	}

	for(uint32 i=0; i<pNode->numChildren(); i++)
	{
		Ogre::SceneNode* l_pChildNode = dynamic_cast<Ogre::SceneNode*>(pNode->getChild(i));

		if(l_pChildNode != NULL && getFirstEntityInHierarchy(l_pChildNode, pEntity) == true)
		{
			return true;
		}
	}

	m_rKernelContext.getLogManager() << LogLevel_Trace << "Failed to retrieve Entity\n";
	return false;
}
Exemple #9
0
//=============================================================================
// NodeMaterialOrig
//=============================================================================
NodeMaterialOrig::NodeMaterialOrig( Ogre::SceneNode* sceneNode )
: NodeMaterial(),
  _sceneNode( sceneNode )
{
  for( Ogre::SceneNode::ObjectIterator it = sceneNode->getAttachedObjectIterator() ;
       it.hasMoreElements() ;
       it.moveNext() )
  {
    Ogre::MovableObject * currentMO = it.peekNextValue() ;
    if ( currentMO->getMovableType() == Ogre::EntityFactory::FACTORY_TYPE_NAME )
    {
      //OMTRACEID( "DEBUG", "Create entity " << currentMO->getName() ) ;
      _entities[ it.peekNextKey() ] = new EntityMaterialOrig( static_cast< Ogre::Entity *> ( currentMO ) ) ;
    }
  }
  for( Ogre::Node::ChildNodeIterator it = sceneNode->getChildIterator() ;
       it.hasMoreElements() ;
       it.moveNext() )
  {
    Ogre::SceneNode* childSceneNode = static_cast< Ogre::SceneNode* >( it.peekNextValue() ) ;
    //OMTRACEID( "DEBUG", "Create ChildSceneNode " << childSceneNode->getName() ) ;
    NodeMaterialOrig* child = new NodeMaterialOrig( childSceneNode ) ;
    _childs.push_back( child ) ;
  }
}
Exemple #10
0
//!
//! Returns the first movable object of the given type name contained in
//! the given scene node.
//!
//! \param sceneNode The scene node to find the first object in.
//! \param typeName The name of the type of objects to look for.
//! \return The first movable object of the given type name contained in the given scene node.
//!
Ogre::MovableObject * OgreTools::findFirstObject ( Ogre::SceneNode *sceneNode, const QString &typeName )
{
    // make sure the given scene node is valid
    if (!sceneNode) {
        Log::error("The given scene node is invalid.", "OgreTools::findFirstObject");
        return 0;
    }

    // iterate over the list of attached objects
    Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator();
    while (objectIterator.hasMoreElements()) {
        Ogre::MovableObject *movableObject = objectIterator.getNext();
        if (movableObject && QString::compare(movableObject->getMovableType().c_str(), typeName) == 0)
            return movableObject;
    }

    // iterate over the list of child nodes
    Ogre::SceneNode::ChildNodeIterator childIter = sceneNode->getChildIterator();
    while( childIter.hasMoreElements() ) {
        Ogre::SceneNode *childSceneNode = (Ogre::SceneNode *) childIter.getNext();
        return findFirstObject(childSceneNode, typeName);
    }

    return 0;
}
Exemple #11
0
		/*dumper*/ /*TODO: humanize*/
		void DumpNodes(std::stringstream &ss, Ogre::Node *n, int level)
		   {
			  for(int i = 0; i < level; i++)
			  {
				 ss << " ";
			  }
			  ss << "SceneNode: " << n->getName() << " (parent: " << n->getParent()->getName() << ")" <<  std::endl;
 
			  Ogre::SceneNode::ObjectIterator object_it = ((Ogre::SceneNode *)n)->getAttachedObjectIterator();
			  Ogre::Node::ChildNodeIterator node_it = n->getChildIterator();
 
			  Ogre::MovableObject *m;
			  while(object_it.hasMoreElements())
			  {
				 for(int i = 0; i < level + 2; i++)
				 {
					ss << " ";
				 }
				 m = object_it.getNext();
				 ss << "parent(" << m->getParentSceneNode()->getName() << ") type " << m->getMovableType() << ": " << m->getName() << std::endl;
			  }
			  while(node_it.hasMoreElements())
			  {
				 DumpNodes(ss, node_it.getNext(), level + 2);
			  }
		   }
	void GameBodyObject::restoreCustom(NxOgre::StringPairList spl) 
	{

		mNode = mpScene->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode();

		for (NxOgre::StringPairList::StringPair sp = spl.begin();spl.hasNext();) 
		{
			sp = spl.next();
	/*
			std::stringstream ss;
			ss << sp.first;
			ss << " => ";
			ss << sp.second;
			ss << std::endl;

			NxDebug(ss.str());
	*/
			NxOgre::NxString key = sp.first;
			Ogre::StringUtil::toLowerCase(key);

			if (key == "entity" || key == "node") 
			{

				Ogre::Entity* entity = mpScene->getOgreSceneManager()->createEntity(
					mName + "-" + sp.second + "-" + Ogre::StringConverter::toString(mNode->numAttachedObjects()), 
					sp.second
				);

				mNode->attachObject(entity);

			}

			if (key == "node-scale") 
			{
				mNode->setScale(Ogre::StringConverter::parseVector3(sp.second));
			}

		}

		// Assign first Attached Object that is an entity to mEntity

		Ogre::SceneNode::ObjectIterator object_it = mNode->getAttachedObjectIterator();
		Ogre::MovableObject *m;
		while(object_it.hasMoreElements()) 
		{
			m = object_it.getNext();
			if (m->getMovableType() == "Entity")
			{
				mEntity = (Ogre::Entity*) m;
				break;
			}
		}

		mNode->setPosition(getGlobalPosition());
		mNode->setOrientation(getGlobalOrientation());

	}
Exemple #13
0
void Actor::setCastShadows(bool hasShadows)
{
    assert(mNode);
    Ogre::SceneNode::ObjectIterator it = mNode->getAttachedObjectIterator();
    while(it.hasMoreElements())
    {
        Ogre::MovableObject* obj = static_cast<Ogre::MovableObject*>(it.getNext());
        obj->setCastShadows(hasShadows);
    }
}
void PolygonPointPickListener::processPickResult(bool& continuePicking, Ogre::RaySceneQueryResultEntry& entry, Ogre::Ray& cameraRay, const MousePickerArgs& mousePickerArgs)
{
	if (entry.movable) {
		Ogre::MovableObject* pickedMovable = entry.movable;
		if (pickedMovable->isVisible() && pickedMovable->getUserAny().getType() == typeid(PolygonPointUserObject*)) {
			//TODO: make sure that it's a point which belongs to our polygon
			mPickedUserObject = Ogre::any_cast<PolygonPointUserObject*>(pickedMovable->getUserAny());
			continuePicking = false;
		}
	}
}
  VideoVisual::VideoVisual(
      const std::string &name, rendering::VisualPtr parent, 
      int height, int width) : 
      rendering::Visual(name, parent), height_(height), width_(width) 
  {

    texture_ = Ogre::TextureManager::getSingleton().createManual(
        name + "__VideoTexture__",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D,
        width_, height_,
        0,
        Ogre::PF_BYTE_BGRA,
        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::MaterialPtr material =
      Ogre::MaterialManager::getSingleton().create(
          name + "__VideoMaterial__", "General");
    material->getTechnique(0)->getPass(0)->createTextureUnitState(
        name + "__VideoTexture__");
    material->setReceiveShadows(false);

    double factor = 1.0;

    Ogre::ManualObject mo(name + "__VideoObject__");
    mo.begin(name + "__VideoMaterial__",
        Ogre::RenderOperation::OT_TRIANGLE_LIST);

    mo.position(-factor / 2, factor / 2, 0.51);
    mo.textureCoord(0, 0);

    mo.position(factor / 2, factor / 2, 0.51);
    mo.textureCoord(1, 0);

    mo.position(factor / 2, -factor / 2, 0.51);
    mo.textureCoord(1, 1);

    mo.position(-factor / 2, -factor / 2, 0.51);
    mo.textureCoord(0, 1);

    mo.triangle(0, 3, 2);
    mo.triangle(2, 1, 0);
    mo.end();

    mo.convertToMesh(name + "__VideoMesh__");

    Ogre::MovableObject *obj = (Ogre::MovableObject*)
      this->GetSceneNode()->getCreator()->createEntity(
          name + "__VideoEntity__",
          name + "__VideoMesh__");
    obj->setCastShadows(false);
    this->AttachObject(obj);
  }
void ResourceGroupReloader::updateOnEveryRenderable()
{

	//1/ get all the available object type (entity, light, user defined types ...)
	std::vector<std::string> allAvailableTypes; 
	Ogre::Root::MovableObjectFactoryIterator iterFactory = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
	for(;iterFactory.hasMoreElements();)
	{
		Ogre::MovableObjectFactory* factory = iterFactory.getNext();
		allAvailableTypes.push_back(factory->getType());
	}

	UpdateMaterialRenderableVisitor lRenderableVisitor;

	//2/ for each scene manager, lets visit renderables!
	// unfortunately that does not cover all renderables type... (overlays...)
	Ogre::SceneManagerEnumerator::SceneManagerIterator iterSceneManager = Ogre::Root::getSingleton().getSceneManagerIterator();
	for(;iterSceneManager.hasMoreElements();)
	{
		Ogre::SceneManager * scMgr = iterSceneManager.getNext();

		std::vector<std::string>::iterator iterMovableType = allAvailableTypes.begin();
		std::vector<std::string>::iterator iterMovableTypeEnd = allAvailableTypes.end();
		for(;iterMovableType!=iterMovableTypeEnd;iterMovableType++)
		{
			Ogre::SceneManager::MovableObjectIterator iterMovable = scMgr->getMovableObjectIterator(*iterMovableType);
			for(;iterMovable.hasMoreElements();)
			{
				Ogre::MovableObject * movable = iterMovable.getNext();
				movable->visitRenderables(&lRenderableVisitor,false);
			}
		}
	}

	// 3 / visit overlays!
	{
		Ogre::OverlayManager::OverlayMapIterator iterOverlay = Ogre::OverlayManager::getSingleton().getOverlayIterator();
		for(;iterOverlay.hasMoreElements();)
		{
			Ogre::Overlay* lOverlay = iterOverlay.getNext();
			// get the first level of OverlayContainer in the Overlay
			Ogre::Overlay::Overlay2DElementsIterator iterOverlayElem = lOverlay->get2DElementsIterator();
			for(;iterOverlayElem.hasMoreElements();)
			{
				Ogre::OverlayContainer * lOverlayCont = iterOverlayElem.getNext();
				visitRecursivelyRenderablesFrom(lOverlayCont,lRenderableVisitor, false);
			}
		}
	}
}
Exemple #17
0
//!
//! Creates a deep copy of the given scene node.
//!
//! \param sceneNode The scene node to copy.
//! \param sceneNodeCopy The scene node to add the copied objects to (will be created if 0).
//! \param namePrefix The prefix to use for names of copied objects.
//! \param sceneManager The scene manager to use for creating the object.
//!
void OgreTools::deepCopySceneNode ( Ogre::SceneNode *sceneNode, Ogre::SceneNode *&sceneNodeCopy, const QString &namePrefix, Ogre::SceneManager *sceneManager /* = 0 */ )
{
    // make sure the given scene node is valid
    if (!sceneNode) {
        Log::error("The given scene node is invalid.", "OgreTools::deepCopySceneNode");
        return;
    }

    // make sure a valid scene manager is available
    if (!sceneManager)
        sceneManager = sceneNode->getCreator();
    if (!sceneManager) {
        Log::error("No valid scene manager available.", "OgreTools::deepCopySceneNode");
        return;
    }

    // create the target scene node if it doesn't exist yet
    if (!sceneNodeCopy) {
        QString sceneNodeCopyName = QString("%1_%2Copy").arg(namePrefix).arg(sceneNode->getName().c_str());
        sceneNodeCopy = copySceneNode(sceneNode, sceneNodeCopyName, sceneManager);
        if (!sceneNodeCopy) {
            Log::error("The scene node could not be copied.", "OgreTools::deepCopySceneNode");
            return;
        }
    }

    // iterate over the list of attached objects
    Ogre::SceneNode::ObjectIterator objectIterator = sceneNode->getAttachedObjectIterator();
    while (objectIterator.hasMoreElements()) {
        Ogre::MovableObject *movableObject = objectIterator.getNext();
        if (movableObject) {
            QString entityCopyName = QString("%1_%2Copy").arg(namePrefix).arg(movableObject->getName().c_str());
            Ogre::MovableObject *movableObjectCopy = cloneMovableObject(movableObject, entityCopyName, sceneManager);
            if (movableObjectCopy)
                sceneNodeCopy->attachObject(movableObjectCopy);
        }
    }

    // iterate over the list of child nodes
    Ogre::SceneNode::ChildNodeIterator childNodeIterator = sceneNode->getChildIterator();
    while (childNodeIterator.hasMoreElements() ) {
        Ogre::SceneNode *childSceneNode = (Ogre::SceneNode *) childNodeIterator.getNext();
        QString childSceneNodeCopyName = QString("%1_%2Copy").arg(namePrefix).arg(childSceneNode->getName().c_str());
        Ogre::SceneNode *childSceneNodeCopy = copySceneNode(childSceneNode, childSceneNodeCopyName, sceneManager);
        if (childSceneNodeCopy) {
            sceneNodeCopy->addChild(childSceneNodeCopy);
            deepCopySceneNode(childSceneNode, childSceneNodeCopy, namePrefix, sceneManager);
        }
    }
}
Exemple #18
0
	//该函数不支持多线程
	string BaseManager::pickMovableObject( int x,int y ){
		//如果相同的帧同时相同的x,y就直接返回结果
		if( mPickFrameCount == getFrameCount() && 
			mPickX == x && mPickY == y ){
			return mPickName;
		}

		mRay = mCamera->getCameraToViewportRay(
				(Ogre::Real)x/(Ogre::Real)mWindow->getWidth(),
				(Ogre::Real)y/(Ogre::Real)mWindow->getHeight()
				);

		mSceneQuery->setRay( mRay );

		//距离排序
		mSceneQuery->setSortByDistance(true);
		Ogre::RaySceneQueryResult result = mSceneQuery->execute();

		//execute不能执行像素级的查询,它仅仅是和包围盒进行比较
		//可以考虑使用渲染到纹理,使用1x1的纹理来对查询结果进行像素级别的查询
		//这里使用逐个求交点的办法
		Ogre::MovableObject* pmo = nullptr;
		Ogre::Real dis;
		for( size_t i = 0;i < result.size();++i ){
			if( result[i].movable && 
				result[i].movable->isVisible() &&  //不可见的
				result[i].movable->isInScene() ){ //不在场景中的
				mIntersect = false;
				result[i].movable->visitRenderables(this);
				if( mIntersect ){
					//考虑到同一帧中间有多个地方的代码需要调用该函数
					//这样使用内存换速度
					if( !pmo || dis>mIntersectDistance ){
						dis = mIntersectDistance;
						pmo = result[i].movable;
					}				
				}
			}
		}

		if( pmo ){
			mPickX = x;
			mPickY = y;
			mPickFrameCount = getFrameCount();
			mPickName = pmo->getName();
			return mPickName;
		}
		//返回一个空字串表示没有
		return "";
	}
Exemple #19
0
void OgreRecast::removeDrawnNavmesh(unsigned int tileRef)
{
    Ogre::String name = "RecastMOWalk_"+Ogre::StringConverter::toString(tileRef);
    Ogre::LogManager::getSingletonPtr()->logMessage("Removing tile: "+name);
    Ogre::String entName = "";

    if(OgreRecast::STATIC_GEOM_DEBUG) {
        m_pSceneMgr->destroyManualObject(name);
        entName = "ent_"+name;
        name = "mesh_"+name;
        m_pSceneMgr->destroyMovableObject(entName, "Entity");
        Ogre::MeshManager::getSingletonPtr()->remove(name);

        name = "RecastMONeighbour_"+Ogre::StringConverter::toString(tileRef);
        m_pSceneMgr->destroyManualObject(name);
        entName = "ent_"+name;
        name = "mesh_"+name;
        m_pSceneMgr->destroyMovableObject(entName, "Entity");
        Ogre::MeshManager::getSingletonPtr()->remove(name);

        name = "RecastMOBoundary_"+Ogre::StringConverter::toString(tileRef);
        m_pSceneMgr->destroyManualObject(name);
        entName = "ent_"+name;
        name = "mesh_"+name;
        m_pSceneMgr->destroyMovableObject(entName, "Entity");
        Ogre::MeshManager::getSingletonPtr()->remove(name);

        // Set dirty flag to trigger rebuild next update
        m_rebuildSg = true;

    } else {
        try {
            Ogre::MovableObject *o = m_pRecastSN->getAttachedObject(name);
            o->detachFromParent();
            m_pSceneMgr->destroyManualObject(name);

            name = "RecastMONeighbour_"+Ogre::StringConverter::toString(tileRef);
            o = m_pRecastSN->getAttachedObject(name);
            o->detachFromParent();
            m_pSceneMgr->destroyManualObject(name);

            name = "RecastMOBoundary_"+Ogre::StringConverter::toString(tileRef);
            o = m_pRecastSN->getAttachedObject(name);
            o->detachFromParent();
            m_pSceneMgr->destroyManualObject(name);
        } catch (Ogre::Exception e) {
            // This is possible if the tile contained no polygons (hence it was not drawn)
        }
    }
}
Exemple #20
0
bool Actor::isVisible() const
{
    assert(mNode);
    Ogre::SceneNode::ObjectIterator it = mNode->getAttachedObjectIterator();
    while(it.hasMoreElements())
    {
        Ogre::MovableObject* obj = static_cast<Ogre::MovableObject*>(it.getNext());
        if(!obj->isVisible())
        {
            return false;
        }
    }
    return true;
}
Exemple #21
0
SelectionHandler::~SelectionHandler()
{
  S_Movable::iterator it = tracked_objects_.begin();
  S_Movable::iterator end = tracked_objects_.end();
  for (; it != end; ++it)
  {
    Ogre::MovableObject* m = *it;
    m->setListener(0);
  }

  while (!boxes_.empty())
  {
    destroyBox(boxes_.begin()->first);
  }
}
Exemple #22
0
    void SelectionBox::performSelection(std::list<AgentId> &selection, Ogre::Camera *mCamera)
    {
        if((mRight - mLeft) * (mBottom - mTop) < 0.0001)
            return;

        float left = (mLeft + 1.f) / 2.f;
        float right = (mRight + 1.f) / 2.f;
        float top = (1.f - mBottom) / 2.f;
        float bottom = (1.f - mTop) / 2.f;
        Ogre::Ray topLeft = mCamera->getCameraToViewportRay(left, top);
        Ogre::Ray topRight = mCamera->getCameraToViewportRay(right, top);
        Ogre::Ray bottomLeft = mCamera->getCameraToViewportRay(left, bottom);
        Ogre::Ray bottomRight = mCamera->getCameraToViewportRay(right, bottom);

        // These planes have now defined an "open box" which extends to infinity in front of the camera. You can think of
        // the rectangle we drew with the mouse as being the termination point of the box just in front of the camera.
        Ogre::PlaneBoundedVolume vol;
        const Ogre::Real min = .1, max = 500;
        vol.planes.push_back(Ogre::Plane(topLeft.getPoint(min), topRight.getPoint(min), bottomRight.getPoint(min)));         // front plane
        vol.planes.push_back(Ogre::Plane(topLeft.getOrigin(), topLeft.getPoint(max), topRight.getPoint(max)));         // top plane
        vol.planes.push_back(Ogre::Plane(topLeft.getOrigin(), bottomLeft.getPoint(max), topLeft.getPoint(max)));       // left plane
        vol.planes.push_back(Ogre::Plane(bottomLeft.getOrigin(), bottomRight.getPoint(max), bottomLeft.getPoint(max)));   // bottom plane
        vol.planes.push_back(Ogre::Plane(topRight.getOrigin(), topRight.getPoint(max), bottomRight.getPoint(max)));     // right plane

        Ogre::PlaneBoundedVolumeList volList;
        volList.push_back(vol);

        mVolQuery->setVolumes(volList);
        Ogre::SceneQueryResult result = mVolQuery->execute();

        // Finally we need to handle the results of the query. First we will deselect all previously selected objects,
        // then we will select all objects which were found by the query.
        std::list<Ogre::SceneNode *> nodes;
        Ogre::SceneQueryResultMovableList::iterator iter;

        for(iter = result.movables.begin(); iter != result.movables.end(); ++iter)
        {
            Ogre::MovableObject *movable = *iter;

            if(movable->getMovableType().compare("Entity") == 0)
            {
                Ogre::Entity *pentity = static_cast<Ogre::Entity *>(movable);
                nodes.push_back(pentity->getParentSceneNode());
            }
        }

        mEngine->level()->getAgentsIdsFromSceneNodes(nodes, selection);
    }
	void
	BoxCenterManager::init()
	{
		mBoxCenterObjMap.clear();

		ObjBoxCenterMap::iterator iter;
		for(iter = mObjBoxCenterMap.begin();iter != mObjBoxCenterMap.end();iter++)
		{
			Ogre::MovableObject* mv = iter->second;
			if (mv->getParentSceneNode())
			{
				mv->getParentSceneNode()->destroy();
			}

			delete iter->second;
		}
		mObjBoxCenterMap.clear();
	}
Exemple #24
0
MapCameraLightningInstance::MapCameraLightningInstance(MapCameraLightning& lightning)
: mLightning(lightning)
{

	Ogre::SceneManager::MovableObjectIterator iterator = lightning.getSceneManager().getMovableObjectIterator(Ogre::LightFactory::FACTORY_TYPE_NAME);

	while (iterator.hasMoreElements()) {
		Ogre::MovableObject* light = iterator.getNext();
		if (light && light != mLightning.getLight()) {
			if (light->getVisible()) {
				mVisibleLights.push_back(light);
				light->setVisible(false);
			}
		}
	}
	mLightning.getLight()->setVisible(true);
	mAmbientColour = mLightning.getSceneManager().getAmbientLight();
	mLightning.getSceneManager().setAmbientLight(mLightning.getLight()->getDiffuseColour());
}
	void RenderBoxWrap::removeNode(Ogre::SceneNode* _node)
	{
		//System::Console::WriteLine("remove node {0}", gcnew System::String(_node->getName().c_str()));

		while(_node->numAttachedObjects() != 0)
		{
			Ogre::MovableObject* object = _node->getAttachedObject(0);

			removeEntity(object->getName());
		}

		while (_node->numChildren() != 0)
		{
			Ogre::SceneNode* forDelete = (Ogre::SceneNode*)_node->getChild(0);

			removeNode(forDelete);
		}

		_node->getParentSceneNode()->removeAndDestroyChild(_node->getName());
	}
Exemple #26
0
//------------------------------------------------------------
/*static*/ void SceneFactoryInterface::destroySceneNodeAndObjects(Ogre::SceneNode *&osn)
{
	if( osn == 0 )return;
	unsigned short objectCount = osn->numAttachedObjects();
	for( unsigned short i = 0; i < objectCount; ++i )
	{
		Ogre::MovableObject* obj = osn->detachObject(i);
		obj->_getManager()->destroyMovableObject(obj);
	}

	Ogre::Node::ChildNodeIterator iter = osn->getChildIterator();
	while( iter.hasMoreElements() )
	{
		Ogre::SceneNode* node = static_cast< Ogre::SceneNode* >( iter.getNext() );
		destroySceneNodeAndObjects(node);
	}

	osn->removeAndDestroyAllChildren();
	osn->getCreator()->destroySceneNode(osn);
	osn = 0;
}
bool gkPhysicsController::_markDbvt(bool v)
{
	if (m_suspend)
		return false;

	bool result = false;
	if (m_dbvtMark != v)
	{
		m_dbvtMark = v;
		if ( m_object->getType() == GK_ENTITY &&  !m_object->getProperties().isInvisible())
		{
			Ogre::MovableObject* mov = m_object->getMovable();

			if (mov)
			{
				result = mov->isVisible() != m_dbvtMark;
				mov->setVisible(m_dbvtMark);
			}
		}
	}
	return result;
}
Exemple #28
0
void ReflectionTextureListener::preRenderTargetUpdate(const RenderTargetEvent& evt)
{
    // Hide plane and objects below the water
    mWater->setVisible(false);


	/*list<Ogre::Entity*> entList = Level::getSingleton()->getEntityList();
	list<Ogre::Entity*>::iterator it;
	for (it = entList.begin();it != entList.end();it++){
		if ((*it)->isVisible()){
			Ogre::AxisAlignedBox box = (*it)->getWorldBoundingBox();
			if (box.getMinimum().y < mWater->getSceneNode()->_getDerivedPosition().y){
				(*it)->setVisible(false);
				belowWaterEnts.push_back((*it));
			}
		}
	}*/

    /*std::vector<Entity*>::iterator i, iend;
    iend = belowWaterEnts.end();
    for (i = belowWaterEnts.begin(); i != iend; ++i)
    {
        (*i)->setVisible(false);
    }*/

	Ogre::SceneManager::MovableObjectIterator it = Level::getSingleton()->getSceneManager()->getMovableObjectIterator("Entity");
	while(it.hasMoreElements()){
		Ogre::MovableObject *m = it.getNext();	
		if (m->isVisible() && m->getParentSceneNode()->_getDerivedPosition().y < mWater->getSceneNode()->_getDerivedPosition().y){
			m->setVisible(false);
			belowWaterEnts.push_back(m);
		}
	}


	Ogre::Camera* cam = Level::getSingleton()->getCurrentSegment()->getActiveCamera()->getCamera();
	cam->enableReflection(mWater->getReflectionPlane());

}
Exemple #29
0
bool StateTargeting::OnInputSys_MouseMove( const OIS::MouseEvent &arg )
{
	SelectableObject* pObj = World::GetSingleton().GetSelectedObjects().at(0);
	eCommandType cmd = pObj->GetActiveAbility()->m_type;

	//获取当前鼠标hover下的物体
	Ogre::MovableObject* pMovable = World::GetSingleton().GetRaySceneQueryResult(arg, QueryTypeSelectableObject);
	SelectableObject* pHoverObj = nullptr;
	if(pMovable)
	{
		pHoverObj = Ogre::any_cast<SelectableObject*>(pMovable->getUserAny());
		assert(pHoverObj);
	}

	//根据当前命令类型确定鼠标样式
	Kratos::eCursorMode mode;
	switch (cmd)
	{
	case eCommandType_Move:
		{
			//无法移动..
			if(pHoverObj)
				mode = Kratos::eCursorMode_TargetInvalid;
			else
				mode = Kratos::eCursorMode_TargetNone;
		}
		break;

	case eCommandType_Gather:
		{
			if(pHoverObj && pHoverObj->GetType() == eObjectType_Resource)
				mode = Kratos::eCursorMode_TargetAllied;
			else
				mode = Kratos::eCursorMode_TargetInvalid;
		}
		break;

	case eCommandType_Attack:
		{
			if (pHoverObj)
			{
				if(pHoverObj->GetType() == eObjectType_Resource)
					mode = Kratos::eCursorMode_TargetInvalid;
				else if(pObj->GetAi()->IsAlly(pHoverObj))
					mode = Kratos::eCursorMode_TargetAllied;
				else
					mode = Kratos::eCursorMode_TargetEnemy;
			}
			else
			{
				mode = Kratos::eCursorMode_TargetNone;
			}
		}
		break;

	default: assert(0);
	}

	GUIMANAGER.SetCursorMode(mode);

	//让其他handler继续响应
	return false;
}
Exemple #30
0
bool CollisionTools::raycast(const Ogre::Ray &ray, Ogre::Vector3 &result,Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask)
{
	target = NULL;

    // check we are initialised
    if (mRaySceneQuery != NULL)
    {
        // create a query object
        mRaySceneQuery->setRay(ray);
		mRaySceneQuery->setSortByDistance(true);
		mRaySceneQuery->setQueryMask(queryMask);
        // execute the query, returns a vector of hits
        if (mRaySceneQuery->execute().size() <= 0)
        {
            // raycast did not hit an objects bounding box
            return (false);
        }
    }
    else
    {
        //LOG_ERROR << "Cannot raycast without RaySceneQuery instance" << ENDLOG;
        return (false);
    }

    // at this point we have raycast to a series of different objects bounding boxes.
    // we need to test these different objects to see which is the first polygon hit.
    // there are some minor optimizations (distance based) that mean we wont have to
    // check all of the objects most of the time, but the worst case scenario is that
    // we need to test every triangle of every object.
    //Ogre::Ogre::Real closest_distance = -1.0f;
	closest_distance = -1.0f;
    Ogre::Vector3 closest_result;
    Ogre::RaySceneQueryResult &query_result = mRaySceneQuery->getLastResults();
    for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
    {
        // stop checking if we have found a raycast hit that is closer
        // than all remaining entities
        if ((closest_distance >= 0.0f) &&
            (closest_distance < query_result[qr_idx].distance))
        {
            break;
        }

        // Only check this result if its a hit against an Entity or
        // ManualObject.
        if ((query_result[qr_idx].movable != NULL) &&
            (query_result[qr_idx].movable->isVisible()) &&
            ((query_result[qr_idx].movable->getMovableType().compare("Entity") == 0) ||
             (query_result[qr_idx].movable->getMovableType().compare("ManualObject") == 0)))
        {
            // get the entity to check
            Ogre::MovableObject *pmovable =
               static_cast<Ogre::MovableObject*>(query_result[qr_idx].movable);

            Ogre::MeshPtr mesh_ptr;

            if (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0)
            {
                mesh_ptr = ((Ogre::Entity*)pmovable)->getMesh();
            }
            else
            {
                // XXX: Does "Mesh" get replaced so we can get away with not
                // XXX: deleting it for now?
                mesh_ptr = ((Ogre::ManualObject*)pmovable)->convertToMesh("Mesh", "General");
            }

            // mesh data to retrieve
            size_t vertex_count;
            size_t index_count;
            Ogre::Vector3 *vertices;
            Ogre::uint32 *indices;

            // get the mesh information
            GetMeshInformation(mesh_ptr, vertex_count, vertices, index_count, indices, pmovable->getParentNode()->_getDerivedPosition(), pmovable->getParentNode()->_getDerivedOrientation(), pmovable->getParentNode()->_getDerivedScale());

            // test for hitting individual triangles on the mesh
            bool new_closest_found = false;
            for (size_t i = 0; i < index_count; i += 3)
            {
                // check for a hit against this triangle
                std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
                    vertices[indices[i+1]], vertices[indices[i+2]], true, false);

                // if it was a hit check if its the closest
                if (hit.first)
                {
                    if ((closest_distance < 0.0f) ||
                        (hit.second < closest_distance))
                    {
                        // this is the closest so far, save it off
                        closest_distance = hit.second;
                        new_closest_found = true;
                    }
                }
            }

            // free the verticies and indicies memory
            delete[] vertices;
            delete[] indices;

            // if we found a new closest raycast for this object, update the
            // closest_result before moving on to the next object.
            if (new_closest_found)
            {
                target = pmovable;
                closest_result = ray.getPoint(closest_distance);
            }
        }
    }

    // return the result
    if (closest_distance >= 0.0f)
    {
        // raycast success
        result = closest_result;
        return (true);
    }
    else
    {
        // raycast failed
        return (false);
    }
}