예제 #1
0
파일: objects.cpp 프로젝트: darkf/openmw
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 ()));
    }
}
예제 #2
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();
  }
예제 #3
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;
}
예제 #4
0
파일: animation.cpp 프로젝트: Chiur/openmw
static void updateBoneTree(const Ogre::SkeletonInstance *skelsrc, Ogre::Bone *bone)
{
    if(skelsrc->hasBone(bone->getName()))
    {
        Ogre::Bone *srcbone = skelsrc->getBone(bone->getName());
        if(!srcbone->getParent() || !bone->getParent())
        {
            bone->setOrientation(srcbone->getOrientation());
            bone->setPosition(srcbone->getPosition());
            bone->setScale(srcbone->getScale());
        }
        else
        {
            bone->_setDerivedOrientation(srcbone->_getDerivedOrientation());
            bone->_setDerivedPosition(srcbone->_getDerivedPosition());
            bone->setScale(Ogre::Vector3::UNIT_SCALE);
        }
    }

    Ogre::Node::ChildNodeIterator boneiter = bone->getChildIterator();
    while(boneiter.hasMoreElements())
        updateBoneTree(skelsrc, static_cast<Ogre::Bone*>(boneiter.getNext()));
}
예제 #5
0
파일: IKChain.cpp 프로젝트: sandsmark/loom
void IKChain::Initialize()
{
	// Get skeleton root Ogre::Bone
	Ogre::Bone* oBoneRoot = mOgreSkeleton->getRootBone();
	Ogre::Vector3 vecBonePos = oBoneRoot->getPosition();
	oBoneRoot->setManuallyControlled(true);
	// Create IK root
	mIKRoot = new IKJoint(oBoneRoot, NULL, oBoneRoot->getPosition().x + mMeshNode->getPosition().x, oBoneRoot->getPosition().y + mMeshNode->getPosition().y, oBoneRoot->getPosition().z + mMeshNode->getPosition().z);
	// Keep track of previously processed Ogre::Bone
	IKJoint* oLastIKJoint = mIKRoot;
	// Current Ogre::Bone
	Ogre::Bone* oCurrentBone = oBoneRoot;
	cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
	mJointCount = 1;
	// Ogre::Bone iterator
	Ogre::Node::ChildNodeIterator oIterator = oCurrentBone->getChildIterator();
	Ogre::Vector3 vecParent = oBoneRoot->_getDerivedPosition();
	while ( oIterator.hasMoreElements() ) 
	{
		oCurrentBone = (Ogre::Bone*)oIterator.getNext();
		oCurrentBone->setManuallyControlled(true);
		cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
		Ogre::Vector3 vecDerived = oCurrentBone->_getDerivedPosition();
		Ogre::Vector3 vecJointPos = oCurrentBone->_getDerivedPosition() + mMeshNode->getPosition();
		vecBonePos = oCurrentBone->getPosition();
		IKJoint* oNewJoint = new IKJoint(oCurrentBone, oLastIKJoint, vecJointPos.x, vecJointPos.y, vecJointPos.z);
		oLastIKJoint->SetChild(oNewJoint);
		oLastIKJoint = oNewJoint;
		oIterator = oCurrentBone->getChildIterator();
		mJointCount++;
		mChainLength += vecParent.distance(oCurrentBone->_getDerivedPosition());
		vecParent = oCurrentBone->_getDerivedPosition();
	}
	mChainLength = mChainLength;
	mIKEffector = oLastIKJoint;
	cout << "Ogre::Bone count is " << mJointCount << endl;
}
예제 #6
0
void CsCameraManager::Load (Ogre::SceneNode* ogreScene) {
	UnLoad();
	SetupDefaultCamera();

	if (ogreScene == NULL) return;

	Ogre::Node::ChildNodeIterator it = ogreScene->getChildIterator();
	
	Ogre::SceneNode *tempNode;

	while (it.hasMoreElements()) {
		tempNode = static_cast <Ogre::SceneNode*> (it.getNext());
		assert(tempNode);

		if ((tempNode->getName().find("Camera")) != std::string::npos) {
			ogreScene->removeChild(tempNode);

			if (tempNode->getName().find("Free") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::FREE_CAMERA);
			else if (tempNode->getName().find("Track") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::TRACK_CAMERA);
			else if (tempNode->getName().find("Chase") != std::string::npos) {
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::CHASE_CAMERA);
				if (tempNode->getName().find("001") != std::string::npos) {
					mCurrentCamera = mCameraList.size() - 1;
					ApplyCamera();
				}
			}
			else if (tempNode->getName().find("Cockpit") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::COCKPIT_CAMERA);
		}
	}

	mCurrentCamera = 0;
	ApplyCamera();
}
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode)
{
	Ogre::Entity *Entity = NULL;
	Ogre::Camera *Camera = NULL;
	Ogre::Light *Light = NULL;
	Ogre::ParticleSystem *ParticleSystem = NULL;
	Ogre::ManualObject *ManualObject = NULL;
	Ogre::BillboardSet *BillboardSet = NULL;

	xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode");
	
	Ogre::String SceneNodeName = SceneNode->getName();

	xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "SceneNodeName",
										BAD_CAST SceneNodeName.c_str());

	Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator();

	while (obji.hasMoreElements())
	{
		Ogre::MovableObject* mobj = obji.getNext();
	
		Ogre::String Type = mobj->getMovableType();
	
		if (Type == "Entity")
		{
			Entity = (Ogre::Entity *)(mobj);
			Ogre::String EntityName = Entity->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity");
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "EntityName",
										BAD_CAST EntityName.c_str());

			Ogre::MeshPtr Mesh = Entity->getMesh();
			Ogre::String MeshName = Mesh->getName();
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "MeshName",
										BAD_CAST MeshName.c_str());
			xmlTextWriterEndElement(m_XmlWriter); 
		}
		
		if (Type == "Camera")
		{
			Camera = (Ogre::Camera *)(mobj);
			Ogre::String CameraName = Camera->getName();
			xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera");
			
			xmlTextWriterWriteAttribute(m_XmlWriter, 
										BAD_CAST "CameraName",
										BAD_CAST CameraName.c_str());
			
			Ogre::Vector3 CameraPosition = Camera->getPosition();
			
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XPosition",
										"%f",CameraPosition.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YPosition",
										"%f",CameraPosition.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZPosition",
										"%f",CameraPosition.z);

			Ogre::Vector3 CameraDirection = Camera->getDirection();

			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "XDirection",
										"%f",CameraDirection.x);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "YDirection",
										"%f",CameraDirection.y);
			xmlTextWriterWriteFormatAttribute(m_XmlWriter, 
										BAD_CAST "ZDirection",
										"%f",CameraDirection.z);

			xmlTextWriterEndElement(m_XmlWriter); 
		}

		if (Type == "Light")
		{
			Light = (Ogre::Light *)(mobj);
		}

		if (Type == "ParticleSystem")
		{
			ParticleSystem = (Ogre::ParticleSystem *)(mobj);
		}

		if (Type == "ManualObject")
		{
			ManualObject = (Ogre::ManualObject *)(mobj);
		}

		if (Type == "BillboardSet")
		{
			BillboardSet = (Ogre::BillboardSet *)(mobj);
		}

	}

	Ogre::Node::ChildNodeIterator nodei = SceneNode->getChildIterator();

	while (nodei.hasMoreElements())
	{
		Ogre::SceneNode* node = (Ogre::SceneNode*)(nodei.getNext());
			// Add this subnode and its children...
		SceneNodeExplore(node);
	}

	xmlTextWriterEndElement(m_XmlWriter); //end SceneNode
}