Esempio n. 1
0
void Actor::AddBoneVisualizer()
{
	SkeletonInstance* pSkeletonInstance = _pBodyEntity->getSkeleton();

	if (!pSkeletonInstance)
	{
		return;
	}

	Skeleton::BoneIterator it = pSkeletonInstance->getBoneIterator();
	while (it.hasMoreElements())
	{
		Bone* pBone = it.getNext();

		Bone::ChildNodeIterator cit = pBone->getChildIterator();
		int iCount = 0;
		while (cit.hasMoreElements())
		{
			Node* pChild = cit.getNext();
			iCount++;

			String strName = pBone->getName() + "_" + pChild->getName();
			Ogre::Entity* ent = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(strName, "bone.mesh");
			TagPoint* pTag	= _pBodyEntity->attachObjectToBone(pBone->getName(), ent);

			ent->setVisible(_bShowBone);

			_Entitys.push_back(ent);

			_BoneVisuals[pTag] = pChild;
		}

		if (iCount == 0)
		{
			Ogre::Entity* ent = OgreFramework::getSingletonPtr()->m_pSceneMgr->createEntity(pBone->getName(), "bone.mesh");
			TagPoint* pTag	= _pBodyEntity->attachObjectToBone(pBone->getName(), ent);

			ent->setVisible(_bShowBone);

			_Entitys.push_back(ent);

			_BoneVisuals[pTag] = 0;
		}
	}

	_UpdateBoneVisualizer();
}
Esempio n. 2
0
void BasicTutorial2::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
{
	// Show plane
	//mPlaneEnt->setVisible(true);
	Ogre::Entity* entGround = mSceneMgr->getEntity("GroundEntity");
	if(entGround)
	{
		entGround->setVisible(true);
	}
}
Esempio n. 3
0
/*
 * Create a fake Plane for Drag and Drop
 */   
void MyFrameListener::createDummyPlane() {
  Ogre::SceneManager* mSceneMgr = Ogre::Root::getSingleton().
                                  getSceneManager("mainSM");
  Ogre::Plane *mPlane = new Ogre::Plane(Ogre::Vector3::UNIT_Z, 0.5);

  Ogre::MeshManager::getSingleton().createPlane("DnDPlane",
                                                Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                *mPlane,800, 800, 20, 20, true, 1, 5, 5
                                                , Ogre::Vector3::UNIT_Y);
  Ogre::Entity* plane = mSceneMgr->createEntity("DnDPlane");
  plane->setVisible(false);
  plane->setMaterialName("WoodMat");
  plane->setQueryFlags(PLANE_DRAG_DROP);
  Ogre::Root::getSingleton().
      getSceneManager("mainSM")->getRootSceneNode()->
      attachObject(plane);
}
Esempio n. 4
0
	bool PlaypenApp::appFrameStarted(opal::real dt)
	{
		// Do per-frame application-specific things here.

		// Handle speech input.
		bool keepLooping = true;
		bool makeObject = false;
		std::string material;
		ObjectType type;
		std::string outputString;
		while (voce::getRecognizerQueueSize() > 0)
		{
			std::string s = voce::popRecognizedString();

			//// Check if the string contains 'quit'.
			//if (std::string::npos != s.rfind("quit"))
			//{
			//	keepLooping = false;
			//}

			// Check if we should reset.
			if (std::string::npos != s.rfind("reset"))
			{
				// Make sure the PhysicalCamera isn't grabbing anything.
				mPhysicalCamera->release();
				destroyAllPhysicalEntities();
				setupInitialPhysicalEntities();
				voce::synthesize("reset");
				return true;
			}

			// Check for material color.
			if (std::string::npos != s.rfind("yellow"))
			{
				outputString += "yellow";
				material = "Plastic/Yellow";
			}
			else if (std::string::npos != s.rfind("red"))
			{
				outputString += "red";
				material = "Plastic/Red";
			}
			else if (std::string::npos != s.rfind("blue"))
			{
				outputString += "blue";
				material = "Plastic/Blue";
			}
			else if (std::string::npos != s.rfind("green"))
			{
				outputString += "green";
				material = "Plastic/Green";
			}
			else if (std::string::npos != s.rfind("purple"))
			{
				outputString += "purple";
				material = "Plastic/Purple";
			}
			else if (std::string::npos != s.rfind("orange"))
			{
				outputString += "orange";
				material = "Plastic/Orange";
			}
			else
			{
				// Default to dark gray.
				material = "Plastic/DarkGray";
			}

			// Check for object type.
			if (std::string::npos != s.rfind("box"))
			{
				outputString += " box";
				type = OBJECT_TYPE_BOX;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("sphere"))
			{
				outputString += " sphere";
				type = OBJECT_TYPE_SPHERE;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("wall"))
			{
				outputString += " wall";
				type = OBJECT_TYPE_WALL;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("tower"))
			{
				outputString += " tower";
				type = OBJECT_TYPE_TOWER;
				makeObject = true;
			}
			else if (std::string::npos != s.rfind("character"))
			{
				outputString += " character";
				type = OBJECT_TYPE_RAGDOLL;
				makeObject = true;
			}

			if (makeObject)
			{
				voce::synthesize(outputString);
				createObject(material, type);
			}
		}

		// Update the grasping spring line.
		if (mPhysicalCamera->isGrasping())
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (!pickingSphere->isVisible())
			{
				pickingSphere->setVisible(true);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (!springLine->isVisible())
			{
				springLine->setVisible(true);
			}

			opal::Point3r desiredPos = 
				mPhysicalCamera->getGraspGlobalPos();
			Ogre::Vector3 point0(desiredPos[0], desiredPos[1], desiredPos[2]);

			opal::Point3r attachPos = mPhysicalCamera->getAttachGlobalPos();
			Ogre::Vector3 point1(attachPos[0], attachPos[1], attachPos[2]);

			pickingSphere->getParentSceneNode()->setPosition(point1);

			Ogre::Vector3 lineVec = point0 - point1;
			if (!lineVec.isZeroLength())
			{
				Ogre::SceneNode* springLineNode = 
					springLine->getParentSceneNode();
				springLineNode->setPosition(0.5 * (point0 + point1));
				
				springLineNode->setDirection(lineVec);
				springLineNode->setScale(0.1, 0.1, lineVec.length());
			}
			else
			{
				springLine->setVisible(false);
			}
		}
		else
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (pickingSphere->isVisible())
			{
				pickingSphere->setVisible(false);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (springLine->isVisible())
			{
				springLine->setVisible(false);
			}
		}

		// Return true to continue looping.
		return keepLooping;
	}
Esempio n. 5
0
ObjectEditHandler::ObjectEditHandler(SceneDoc *Owner)
{
	mOwner = Owner;
	mMode = OEM_NONE;
	mAxisMode = AM_NONE;
	mTarget = NULL;
	mObjectEditNode = mOwner->getSceneManager()->getRootSceneNode()->createChildSceneNode();
	mRayQuery = mOwner->getSceneManager()->createRayQuery(Ogre::Ray());

	mMaterials[0] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/RedMat");
	mMaterials[1] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/GreenMat");
	mMaterials[2] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/BlueMat");
	mMaterials[3] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorWhiteMat");
	mMaterials[4] = Ogre::MaterialManager::getSingletonPtr()->getByName("Editor/ObjectIndicatorYellowMat");

	//////////////////////////////////////////////////
	// 碰撞检测
	//////////////////////////////////////////////////

	mCollisionManager = new OgreOpcode::CollisionManager(Owner->getSceneManager());
	mCollisionManager->addCollClass("Object");
	mCollisionManager->addCollType("Object", "Object", OgreOpcode::COLLTYPE_IGNORE);
	mCollisionContext = mCollisionManager->createContext("SceneObject");

	Ogre::MovableObjectFactory* Factory = 
		Ogre::Root::getSingleton().getMovableObjectFactory(Ogre::EntityFactory::FACTORY_TYPE_NAME);
	Ogre::NameValuePairList Params;

	//////////////////////////////////////////////////
	// 平移放缩指示器
	//////////////////////////////////////////////////

	mIndicatorContext = mCollisionManager->createContext("TransScale");

	mTransScaleNode = mObjectEditNode->createChildSceneNode("TransScaleIndicator");
	mTransScaleNode->setScale(200.0f, 200.0f, 200.0f);

	// x
	Ogre::SceneNode *SubNode = mTransScaleNode->createChildSceneNode();
	SubNode->roll(Ogre::Degree(-90.0f));

	Ogre::Entity *Entity = Owner->getSceneManager()->createEntity("TransScaleXLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0); // 参与查询
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_X] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleXCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleXCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	OgreOpcode::CollisionObject *CollisionObject = 
		AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_X;

	// y
	SubNode = mTransScaleNode;

	Entity = Owner->getSceneManager()->createEntity("TransScaleYLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_Y] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleYCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleYCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Y;

	// z
	SubNode = mTransScaleNode->createChildSceneNode();
	SubNode->pitch(Ogre::Degree(90));

	Entity = Owner->getSceneManager()->createEntity("TransScaleZLine", "MoveArrowLineVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_Z] = Entity;

	Entity = Owner->getSceneManager()->createEntity("TransScaleZCone", "MoveArrowConeVisible.mesh");
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);

	Params["mesh"] = "MoveArrowCollision.mesh";
	Entity = (Ogre::Entity*)Factory->createInstance("TransScaleZCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_Z;

	// box
	SubNode = mTransScaleNode;

	Params["mesh"] = "Box1m.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("TransScaleAll", Owner->getSceneManager(), &Params);
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[3]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_TRANS_SCALE_ALL] = Entity;

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_TRANS_SCALE_ALL;

	mIndicatorContext->reset();
	mObjectEditNode->removeChild(mTransScaleNode);

	//////////////////////////////////////////////////
	// 旋转指示器
	//////////////////////////////////////////////////

	mIndicatorContext = mCollisionManager->createContext("Rotate");

	mRotateNode = mObjectEditNode->createChildSceneNode("RotateIndicator");
	mRotateNode->setScale(200.0f, 200.0f, 200.0f);

	// x
	SubNode = mRotateNode->createChildSceneNode();
	SubNode->roll(Ogre::Degree(90));

	Entity = Owner->getSceneManager()->createEntity("RotateX", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[0]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_X] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateXCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_X;

	// y
	SubNode = mRotateNode;
	Entity = Owner->getSceneManager()->createEntity("RotateY", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[1]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_Y] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateYCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);
	
	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Y;

	// z
	SubNode = mRotateNode->createChildSceneNode();
	SubNode->pitch(Ogre::Degree(90.0f));

	Entity = Owner->getSceneManager()->createEntity("RotateZ", "RotationRingVisible.mesh");
	//Entity->setQueryFlags(0);
	Entity->setCastShadows(false);
	Entity->setMaterial(mMaterials[2]);
	Entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8);
	SubNode->attachObject(Entity);
	mTransformEntities[AM_ROTATE_Z] = Entity;

	Params["mesh"] = "RotationRingCollision.mesh";
	Entity =(Ogre::Entity*)Factory->createInstance("RotateZCol", Owner->getSceneManager(), &Params);
	Entity->setQueryFlags(0);
	Entity->setCastShadows(false);

	Entity->setVisible(false);
	SubNode->attachObject(Entity);

	CollisionObject = AddCollisionEntity(mIndicatorContext, Entity);
	mCollisionObjectToAxisMode[CollisionObject] = AM_ROTATE_Z;

	mIndicatorContext->reset();
	mObjectEditNode->removeChild(mRotateNode);
}
Esempio n. 6
0
Ogre::Entity*
ModelFile::GetModel( const ModelInfo& info )
{
    VectorTexForGen textures;
    Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create( info.data.name + "export", "General" );
    Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create( info.data.name + "export", "General" );

    int number_of_bones = GetU8( 0x02 );
    int number_of_parts = GetU8( 0x03 );
    int offset_to_bones = GetU32LE( 0x0c );
    int offset_to_parts = GetU32LE( 0x10 );



    Ogre::Bone* root1 = skeleton->createBone( "0", 0 );
    Ogre::Bone* root2 = skeleton->createBone( "1", 1 );
    root1->addChild( root2 );

    for( int i = 0; i < number_of_bones; ++i )
    {
        Bone bone;
        bone.parent_id = ( i != 0 ) ? ( s8 )GetU8( offset_to_bones + i * 0x04 + 0x03 ) : -1;
        bone.length    = ( s16 )GetU16LE( offset_to_bones + i * 0x04 + 0x00 );
        m_Skeleton.push_back(bone);

        Ogre::Bone* bone1 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 2 ), i * 2 + 2 );
        Ogre::Bone* bone2 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 3 ), i * 2 + 3 );

        LOGGER->Log( "Add skeleton bone: bone_id = " + Ogre::StringConverter::toString( i ) + ", length = " + Ogre::StringConverter::toString( bone.length ) + ", parent = " + Ogre::StringConverter::toString( bone.parent_id ) + ".\n" );

        if( bone.parent_id == -1 )
        {
            skeleton->getBone( 1 )->addChild( bone1 );
        }
        else
        {
            skeleton->getBone( bone.parent_id * 2 + 3 )->addChild( bone1 );
        }
        bone1->addChild( bone2 );
    }



    AnimationExtractor( skeleton, info, m_Skeleton );



    // draw skeleton
    {
        //DrawSkeleton( m_Skeleton, mesh );
    }



    for( int i = 0; i < number_of_parts; ++i )
    {
        MeshExtractor( info.data, "ffix/field_model/" + info.data.name, this, offset_to_parts + i * 0x28, textures, mesh );
    }



    // <OGRE> ///////////////////////////////
    skeleton->optimiseAllAnimations();
    Ogre::SkeletonSerializer skeleton_serializer;
    skeleton_serializer.exportSkeleton( skeleton.getPointer(), "exported/models/field/units/" + info.data.name + ".skeleton" );

    // Update bounds
    Ogre::AxisAlignedBox aabb( -999, -999, -999, 999, 999, 999 );
    mesh->_setBounds( aabb, false );
    mesh->_setBoundingSphereRadius( 999 );

    mesh->setSkeletonName( "models/field/units/" + info.data.name + ".skeleton" );

    Ogre::MeshSerializer ser;
    ser.exportMesh( mesh.getPointer(), "exported/models/field/units/" + info.data.name + ".mesh" );



    // create and export textures for model
    //if (textures.size() > 0)
    {
        Vram* vram = new Vram();

        File* tex = new File( "./data/field/5/1b/2/4/1.tim" );
        LoadTimFileToVram( tex, 0, vram );
        delete tex;
        tex = new File( "./data/field/5/1b/2/4/2.tim" );
        LoadTimFileToVram( tex, 0, vram );
        delete tex;

        vram->Save( "1.jpg" );

        CreateTexture( vram, info.data, "exported/models/field/units/" + info.data.name + ".png", textures );

        delete vram;
    }



    CreateMaterial( "ffix/field_model/" + info.data.name, "exported/models/field/units/" + info.data.name + ".material", ( textures.size() > 0 ) ? "models/field/units/" + info.data.name + ".png" : "", "", "" );



    Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" );
    Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/field/units/" + info.data.name + ".mesh" );
    //thisEntity->setDisplaySkeleton(true);
    //thisEntity->setDebugDisplayEnabled(true);
    thisEntity->setVisible( false );
    thisEntity->getAnimationState( info.animations_name[ 0 ] )->setEnabled(true);
    thisEntity->getAnimationState( info.animations_name[ 0 ] )->setLoop(true);
    Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode();
    thisSceneNode->setPosition( 0, 0, 0 );
    thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) );
    thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) );
    thisSceneNode->pitch( Ogre::Radian( Ogre::Degree(90.0f ) ) );
    thisSceneNode->attachObject( thisEntity );

    return thisEntity;
}
// BETWEEN FRAME OPERATION
void VisCalcFrustDist::calculateEntityVisibility(Ogre::Node* regionNode, Ogre::Node* node, bool recurse) {
	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
			calculateEntityVisibility(regionNode, nodeChild, false);
			visChildren++;
		}
	}
	visNodes++;
	// children taken care of... check fo attached objects to this node
	Ogre::SceneNode* snode = (Ogre::SceneNode*)node;
	// the camera needs to be made relative to the region
	// Ogre::Vector3 relCameraPos = LG::RendererOgre::Instance()->m_camera->getPosition() - regionNode->getPosition();
	// float snodeDistance = LG::RendererOgre::Instance()->m_camera->getPosition().distance(snode->_getWorldAABB().getCenter());
	// float snodeDistance = relCameraPos.distance(snode->getPosition());
	float snodeDistance = LG::RendererOgre::Instance()->m_camera->getDistanceFromCamera(regionNode, snode->getPosition());
	Ogre::SceneNode::ObjectIterator snodeObjectIterator = snode->getAttachedObjectIterator();
	while (snodeObjectIterator.hasMoreElements()) {
		Ogre::MovableObject* snodeObject = snodeObjectIterator.getNext();
		if (snodeObject->getMovableType() == "Entity") {
			visEntities++;
			Ogre::Entity* snodeEntity = (Ogre::Entity*)snodeObject;
			// check it's visibility if it's not world geometry (terrain and ocean)
			if ((snodeEntity->getQueryFlags() & Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK) == 0) {
				// computation if it should be visible
				// Note: this call is overridden by derived classes that do fancier visibility rules
				bool shouldBeVisible = this->CalculateVisibilityImpl(LG::RendererOgre::Instance()->m_camera, snodeEntity, snodeDistance);
				if (snodeEntity->isVisible()) {
					// we currently think this object is visible. make sure it should stay that way
					if (shouldBeVisible) {
						// it should stay visible
						visVisToVis++;
					}
					else {
						// not visible any more... make invisible nad unload it`
						/*
						Ogre::Vector3 cPos = LG::RendererOgre::Instance()->m_camera->getPosition();
						Ogre::Vector3 rPos = regionNode->getPosition();
						Ogre::Vector3 sPos = snode->getPosition();
						LG::Log("VisToInVis: cPos=<%f,%f,%f>, rPos=<%f,%f,%f>, sPos(%s)=<%f,%f,%f>, d=%f", 
								cPos.x, cPos.y, cPos.z, 
								rPos.x, rPos.y, rPos.z, 
								snode->getName().c_str(),
								sPos.x, sPos.y, sPos.z, 
								snodeDistance);
								*/
						snodeEntity->setVisible(false);
						snode->needUpdate(true);
						visVisToInvis++;
						if (!snodeEntity->getMesh().isNull()) {
							queueMeshUnload(snodeEntity->getMesh());
						}
					}
				}
				else {
					// the entity currently thinks it's not visible.
					// check to see if it should be visible by checking a fake bounding box
					if (shouldBeVisible) {
						// it should become visible again
						if (!snodeEntity->getMesh().isNull()) {
							// queueMeshLoad(snodeEntity, snodeEntity->getMesh());
							LG::OLMeshTracker::Instance()->MakeLoaded(snodeEntity->getMesh()->getName(),
									Ogre::String(""), Ogre::String("visible"), snodeEntity);
						}
						// snodeEntity->setVisible(true);	// must happen after mesh loaded
						visInvisToVis++;
					}
					else {
						visInvisToInvis++;
					}
				}
			}
		}
	}
}
Esempio n. 8
0
//-------------------------------------------------------------------------------------
void SimonSays::createScene(void)
{
    // set up the basics
	mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3,0.3,0.3));
	/*Ogre::Light *light = mSceneMgr->createLight("MainLight");
	light->setPosition(20.0f, 80.0f, 50.0f);*/

	// put in a floor ;)
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);

	Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
    plane, 1500, 1500, 40, 40, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);

	Ogre::Entity* floor = mSceneMgr->createEntity("GroundEntity", "ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(floor);

	floor->setMaterialName("Examples/Rockwall");
	floor->setCastShadows(false);

	// for now, use a pinguin, character selection will be added later
	Ogre::Entity *player = mSceneMgr->createEntity("Player", "penguin.mesh");
	Ogre::SceneNode *playerNode = mSceneMgr->getRootSceneNode()->
		createChildSceneNode("PlayerNode");
	playerNode->attachObject(player);
	playerNode->translate(35,20,-65);
	player->setVisible( false );

	// use spots placed in 2x2 field to show the order
	// 
	//  yellow  | red		keys:	u	|	i
	//  ----------------			----------
	//  blue    | green				j	|	k


	Ogre::SceneNode *lightNode = mSceneMgr->getRootSceneNode()->
		createChildSceneNode("LightNode");
	lightNode->setPosition(0,80,0);

	Ogre::Light *yellow = mSceneMgr->createLight("yellowSpot");
	yellow->setType(Ogre::Light::LT_SPOTLIGHT);
	yellow->setDiffuseColour(.5,.5,0);
	yellow->setSpecularColour(.5,.5,0);
	yellow->setDirection(0,-1,0);
	//yellow->setSpotlightInnerAngle(Ogre::Degree(5.0f));
	//yellow->setSpotlightOuterAngle(Ogre::Degree(45.0f));
	//yellow->setSpotlightFalloff(0.0f);
	//yellow->setPosition(Ogre::Vector3(0,0,0));
	//yellow->setSpotlightFalloff(0.0f);
	yellow->setSpotlightRange(Ogre::Degree(15), Ogre::Degree(15));
	lightNode->attachObject(yellow);
	yellow->setVisible( false );

	Ogre::Light *red = mSceneMgr->createLight("redSpot");
	red->setType(Ogre::Light::LT_SPOTLIGHT);
	red->setDiffuseColour(1,0,0);
	red->setSpecularColour(1,0,0);
	red->setDirection(1,-1,0);
	//red->setPosition(Ogre::Vector3(0,0,0));
	//red->setSpotlightFalloff(0.0f);
	red->setSpotlightRange(Ogre::Degree(15), Ogre::Degree(15));
	lightNode->attachObject(red);
	red->setVisible( false );

	Ogre::Light *blue = mSceneMgr->createLight("blueSpot");
	blue->setType(Ogre::Light::LT_SPOTLIGHT);
	blue->setDiffuseColour(0,0,1.0);
	blue->setSpecularColour(0,0,1.0);
	blue->setDirection(0,-1,1);
	//blue->setPosition(Ogre::Vector3(0,100,0));
	blue->setSpotlightRange(Ogre::Degree(15), Ogre::Degree(15));
	lightNode->attachObject(blue);
	blue->setVisible( false );

	Ogre::Light *green = mSceneMgr->createLight("greenSpot");
	green->setType(Ogre::Light::LT_SPOTLIGHT);
	green->setDiffuseColour(0,1,0);
	green->setSpecularColour(0,1,0);
	green->setDirection(1,-1,1);
	//green->setPosition(Ogre::Vector3(100,100,0));
	green->setSpotlightRange(Ogre::Degree(15), Ogre::Degree(15));
	lightNode->attachObject(green);
	green->setVisible( false );
	
	// everything's set up, let's get the game and the streaming started!
	
	mSceneMgr->getLight("yellowSpot")->setVisible( true );
	mSceneMgr->getLight("redSpot")->setVisible( true );
	mSceneMgr->getLight("blueSpot")->setVisible( true );
	mSceneMgr->getLight("greenSpot")->setVisible( true );
	
	turnEnded = false;
	gameStarted = false;
	correctOrder = true;
	pause = false; // set pause to false
	// --> game ist started by user input!!

	frameCounter = 1;

	// set up streaming
	setUpStream();
}
Esempio n. 9
0
void RenderedTexture::renderTextures()
{
    //Set up RTT texture
    Ogre::TexturePtr renderTexture;
    if (renderTexture.isNull()) {
        renderTexture = Ogre::TextureManager::getSingleton().createManual(
            getUniqueID("RenderedEntityMaterial"), "EntityRenderer",
            Ogre::TEX_TYPE_2D, textureSize, textureSize, 0,
            Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, 0);
    }
    renderTexture->setNumMipmaps(0);

    //Set up render target
    Ogre::RenderTexture* renderTarget = renderTexture->getBuffer()->getRenderTarget(); 
    renderTarget->setAutoUpdated(false);

    //Set up camera
    Ogre::SceneNode* camNode = sceneMgr->getSceneNode("EntityRenderer::cameraNode");
    Ogre::Camera* renderCamera = sceneMgr->createCamera(getUniqueID("EntityRendererCam"));
    camNode->attachObject(renderCamera);
    renderCamera->setLodBias(1000.0f);

    Ogre::Viewport* renderViewport = renderTarget->addViewport(renderCamera);
    renderViewport->setOverlaysEnabled(false);
    renderViewport->setClearEveryFrame(true);
    renderViewport->setShadowsEnabled(false);
    renderViewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 0.0f));

    //Set up scene node
    Ogre::SceneNode* node = sceneMgr->getSceneNode("EntityRenderer::renderNode");

    Ogre::SceneNode* oldSceneNode = entity->getParentSceneNode();
    if (oldSceneNode)
        oldSceneNode->detachObject(entity);
    node->attachObject(entity);
    node->setPosition(-entityCenter);

    //Set up camera FOV
    const Ogre::Real objDist = entityRadius * 100;
    const Ogre::Real nearDist = objDist - (entityRadius + 1); 
    const Ogre::Real farDist = objDist + (entityRadius + 1);

    renderCamera->setAspectRatio(1.0f);
    renderCamera->setFOVy(Ogre::Math::ATan(2.0 * entityRadius / objDist));
    renderCamera->setNearClipDistance(nearDist);
    renderCamera->setFarClipDistance(farDist);

    //Disable mipmapping (without this, masked textures look bad)
    Ogre::MaterialManager* mm = Ogre::MaterialManager::getSingletonPtr();
    Ogre::FilterOptions oldMinFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIN);
    Ogre::FilterOptions oldMagFilter = mm->getDefaultTextureFiltering(Ogre::FT_MAG);
    Ogre::FilterOptions oldMipFilter = mm->getDefaultTextureFiltering(Ogre::FT_MIP);
    mm->setDefaultTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR,Ogre:: FO_NONE);

    //Disable fog
    Ogre::FogMode oldFogMode = sceneMgr->getFogMode();
    Ogre::ColourValue oldFogColor = sceneMgr->getFogColour();
    Ogre::Real oldFogDensity = sceneMgr->getFogDensity();
    Ogre::Real oldFogStart = sceneMgr->getFogStart();
    Ogre::Real oldFogEnd = sceneMgr->getFogEnd();
    sceneMgr->setFog(Ogre::FOG_NONE);

    // Get current status of the queue mode
    Ogre::SceneManager::SpecialCaseRenderQueueMode OldSpecialCaseRenderQueueMode =
        sceneMgr->getSpecialCaseRenderQueueMode();
    //Only render the entity
    sceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE); 
    sceneMgr->addSpecialCaseRenderQueue(renderQueueGroup);

    Ogre::uint8 oldRenderQueueGroup = entity->getRenderQueueGroup();
    entity->setRenderQueueGroup(renderQueueGroup);
    bool oldVisible = entity->getVisible();
    entity->setVisible(true);
    float oldMaxDistance = entity->getRenderingDistance();
    entity->setRenderingDistance(0);

    //Calculate the filename hash used to uniquely identity this render
    std::string strKey = entityKey;
    char key[32] = {0};
    Ogre::uint32 i = 0;
    for (std::string::const_iterator it = entityKey.begin(); it != entityKey.end(); ++it) {
        key[i] ^= *it;
        i = (i+1) % sizeof(key);
    }
    for (i = 0; i < sizeof(key); ++i)
        key[i] = (key[i] % 26) + 'A';

    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
        GetUserDir().string(), "FileSystem", "BinFolder");
    std::string fileNamePNG =
        "Rendered." + std::string(key, sizeof(key)) + '.' +
        Ogre::StringConverter::toString(textureSize) + ".png";

    //Attempt to load the pre-render file if allowed
    bool needsRegen = false;
    if (!needsRegen) {
        try{
            texture = Ogre::TextureManager::getSingleton().load(
                fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0);
        } catch (...) {
            needsRegen = true;
        }
    }

    if (needsRegen) {
        //If this has not been pre-rendered, do so now

        //Position camera
        camNode->setPosition(0, 0, 0);
        // TODO camNode->setOrientation(Quaternion(yaw, Vector3::UNIT_Y) * Quaternion(-pitch, Vector3::UNIT_X));
        camNode->translate(Ogre::Vector3(0, 0, objDist), Ogre::Node::TS_LOCAL);
						
        renderTarget->update();

        //Save RTT to file
        renderTarget->writeContentsToFile((GetUserDir() / fileNamePNG).string());

        //Load the render into the appropriate texture view
        texture = Ogre::TextureManager::getSingleton().load(fileNamePNG, "BinFolder", Ogre::TEX_TYPE_2D, 0);

        ggTexture = ClientUI::GetTexture(GetUserDir() / fileNamePNG);
    }

    entity->setVisible(oldVisible);
    entity->setRenderQueueGroup(oldRenderQueueGroup);
    entity->setRenderingDistance(oldMaxDistance);
    sceneMgr->removeSpecialCaseRenderQueue(renderQueueGroup);
    // Restore original state
    sceneMgr->setSpecialCaseRenderQueueMode(OldSpecialCaseRenderQueueMode); 

    //Re-enable mipmapping
    mm->setDefaultTextureFiltering(oldMinFilter, oldMagFilter, oldMipFilter);

    //Re-enable fog
    sceneMgr->setFog(oldFogMode, oldFogColor, oldFogDensity, oldFogStart, oldFogEnd);

    //Delete camera
    renderTarget->removeViewport(0);
    renderCamera->getSceneManager()->destroyCamera(renderCamera);

    //Delete scene node
    node->detachAllObjects();
    if (oldSceneNode)
        oldSceneNode->attachObject(entity);

    //Delete RTT texture
    assert(!renderTexture.isNull());
    std::string texName2(renderTexture->getName());

    renderTexture.setNull();
    if (Ogre::TextureManager::getSingletonPtr())
        Ogre::TextureManager::getSingleton().remove(texName2);
}
Esempio n. 10
0
void RoR::GfxEnvmap::SetupEnvMap()
{
    m_rtt_texture = Ogre::TextureManager::getSingleton().getByName("EnvironmentTexture");

    for (int face = 0; face < NUM_FACES; face++)
    {
        m_render_targets[face] = m_rtt_texture->getBuffer(face)->getRenderTarget();
        m_cameras[face] = gEnv->sceneManager->createCamera("EnvironmentCamera-" + TOSTRING(face));
        m_cameras[face]->setAspectRatio(1.0);
        m_cameras[face]->setProjectionType(Ogre::PT_PERSPECTIVE);
        m_cameras[face]->setFixedYawAxis(false);
        m_cameras[face]->setFOVy(Ogre::Degree(90));
        m_cameras[face]->setNearClipDistance(0.1f);
        m_cameras[face]->setFarClipDistance(gEnv->mainCamera->getFarClipDistance());

        Ogre::Viewport* v = m_render_targets[face]->addViewport(m_cameras[face]);
        v->setOverlaysEnabled(false);
        v->setClearEveryFrame(true);
        v->setBackgroundColour(gEnv->mainCamera->getViewport()->getBackgroundColour());
        m_render_targets[face]->setAutoUpdated(false);
    }

    m_cameras[0]->setDirection(+Ogre::Vector3::UNIT_X);
    m_cameras[1]->setDirection(-Ogre::Vector3::UNIT_X);
    m_cameras[2]->setDirection(+Ogre::Vector3::UNIT_Y);
    m_cameras[3]->setDirection(-Ogre::Vector3::UNIT_Y);
    m_cameras[4]->setDirection(-Ogre::Vector3::UNIT_Z);
    m_cameras[5]->setDirection(+Ogre::Vector3::UNIT_Z);

    if (App::diag_envmap.GetActive())
    {
        // create fancy mesh for debugging the envmap
        Ogre::Overlay* overlay = Ogre::OverlayManager::getSingleton().create("EnvMapDebugOverlay");
        if (overlay)
        {
            Ogre::Vector3 position = Ogre::Vector3::ZERO;
            float scale = 1.0f;

            Ogre::MeshPtr mesh = Ogre::MeshManager::getSingletonPtr()->createManual("cubeMapDebug", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            // create sub mesh
            Ogre::SubMesh* sub = mesh->createSubMesh();

            // Initialize render operation
            sub->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
            //
            sub->useSharedVertices = true;
            mesh->sharedVertexData = new Ogre::VertexData;
            sub->indexData = new Ogre::IndexData;

            // Create vertex declaration
            size_t offset = 0;
            mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
            offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
            mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);

            // Create and bind vertex buffer
            mesh->sharedVertexData->vertexCount = 14;
            Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
                Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
                    mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
                    mesh->sharedVertexData->vertexCount,
                    Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
            mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);

            // Vertex data
            static const float vertexData[] = {
                // Position      Texture coordinates    // Index
                0.0, 2.0, -1.0, 1.0, 1.0, //  0
                0.0, 1.0, -1.0, -1.0, 1.0, //  1
                1.0, 2.0, -1.0, 1.0, -1.0, //  2
                1.0, 1.0, -1.0, -1.0, -1.0, //  3
                2.0, 2.0, 1.0, 1.0, -1.0, //  4
                2.0, 1.0, 1.0, -1.0, -1.0, //  5
                3.0, 2.0, 1.0, 1.0, 1.0, //  6
                3.0, 1.0, 1.0, -1.0, 1.0, //  7
                4.0, 2.0, -1.0, 1.0, 1.0, //  8
                4.0, 1.0, -1.0, -1.0, 1.0, //  9
                1.0, 3.0, -1.0, 1.0, 1.0, // 10
                2.0, 3.0, 1.0, 1.0, 1.0, // 11
                1.0, 0.0, -1.0, -1.0, 1.0, // 12
                2.0, 0.0, 1.0, -1.0, 1.0, // 13
            };

            // Fill vertex buffer
            float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
            for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
            {
                // Position
                *pData++ = position.x + scale * vertexData[i++];
                *pData++ = position.y + scale * vertexData[i++];
                *pData++ = 0.0;

                // Texture coordinates
                *pData++ = vertexData[i++];
                *pData++ = vertexData[i++];
                *pData++ = vertexData[i++];
            }
            vertexBuffer->unlock();

            // Create index buffer
            sub->indexData->indexCount = 36;
            Ogre::HardwareIndexBufferSharedPtr indexBuffer =
                Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
                    Ogre::HardwareIndexBuffer::IT_16BIT,
                    sub->indexData->indexCount,
                    Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
            sub->indexData->indexBuffer = indexBuffer;

            // Index data
            static const Ogre::uint16 indexData[] = {
                // Indices         // Face
                 0,  1,  2,        //  0
                 2,  1,  3,        //  1
                 2,  3,  4,        //  2
                 4,  3,  5,        //  3
                 4,  5,  6,        //  4
                 6,  5,  7,        //  5
                 6,  7,  8,        //  6
                 8,  7,  9,        //  7
                10,  2, 11,        //  8
                11,  2,  4,        //  9
                 3, 12,  5,        // 10
                 5, 12, 13,        // 11
            };

            // Fill index buffer
            indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData, true);

            mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE);
            mesh->_setBoundingSphereRadius(10);
            mesh->load();

            Ogre::Entity* e = gEnv->sceneManager->createEntity(mesh->getName());
            e->setCastShadows(false);
            e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
            e->setVisible(true);

            e->setMaterialName("tracks/EnvMapDebug");
            Ogre::SceneNode* mDebugSceneNode = new Ogre::SceneNode(gEnv->sceneManager);
            mDebugSceneNode->attachObject(e);
            mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5));
            mDebugSceneNode->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
            mDebugSceneNode->setVisible(true);
            mDebugSceneNode->_update(true, true);
            mDebugSceneNode->_updateBounds();
            overlay->add3D(mDebugSceneNode);
            overlay->show();
        }
    }
}
Esempio n. 11
0
	bool PlaypenApp::appFrameStarted(opal::real dt)
	{
		// Do per-frame application-specific things here.

		// Update the grasping spring line.
		if (mPhysicalCamera->isGrasping())
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (!pickingSphere->isVisible())
			{
				pickingSphere->setVisible(true);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (!springLine->isVisible())
			{
				springLine->setVisible(true);
			}

			opal::Point3r desiredPos = 
				mPhysicalCamera->getGraspGlobalPos();
			Ogre::Vector3 point0(desiredPos[0], desiredPos[1], desiredPos[2]);

			opal::Point3r attachPos = mPhysicalCamera->getAttachGlobalPos();
			Ogre::Vector3 point1(attachPos[0], attachPos[1], attachPos[2]);

			pickingSphere->getParentSceneNode()->setPosition(point1);

			Ogre::Vector3 lineVec = point0 - point1;
			if (!lineVec.isZeroLength())
			{
				Ogre::SceneNode* springLineNode = 
					springLine->getParentSceneNode();
				springLineNode->setPosition(0.5 * (point0 + point1));
				
				springLineNode->setDirection(lineVec, Ogre::Node::TS_WORLD);
				springLineNode->setScale(0.1, 0.1, lineVec.length());
			}
			else
			{
				springLine->setVisible(false);
			}
		}
		else
		{
			Ogre::Entity* pickingSphere = 
				mSceneMgr->getEntity("pickingSphere");
			if (pickingSphere->isVisible())
			{
				pickingSphere->setVisible(false);
			}

			Ogre::Entity* springLine = 
				mSceneMgr->getEntity("springLine");
			if (springLine->isVisible())
			{
				springLine->setVisible(false);
			}
		}

		// Return true to continue looping.
		return true;
	}
Esempio n. 12
0
void Ninja::updateLocomote(Ogre::Real deltaTime)
{
    int xOffset = ((this->grid->getRows() * this->grid->getHeight()) - this->grid->getHeight())/2;
    int yOffset = ((this->grid->getCols() * this->grid->getHeight()) - this->grid->getHeight())/2;
    int x = (xOffset + mDestination.x)/grid->getHeight();
    int y = (yOffset + mDestination.z)/grid->getHeight();

    if (mDirection == Ogre::Vector3::ZERO)
    {
        if (nextLocation()) // a check to see if there is another destination
        {
            // Set walking animation
            this->setBaseAnimation(ANIM_WALK, true);
            //this->setTopAnimation(ANIM_WALK, true);
        }
    }
    else
    {
        Ogre::Real move = mWalkSpeed * deltaTime;
        mDistance -= move;

        if (mDistance <= 0.0f) // over shooting target
        {
            this->mBodyNode->setPosition(mDestination);

            this->setCurrentNode(grid->getNode(x, y));

            while(this->getCurrentNode()->getItemList()->size() > 0)
            {
                Ogre::Entity* ent = this->getCurrentNode()->getItemList()->front();
                this->inventory->push_back(ent);
                this->getCurrentNode()->getItemList()->pop();
                ent->detachFromParent();

                this->getmBodyEntity()->attachObjectToBone("Joint13", ent);
                ent->getParentNode()->scale(1.15f,1.15f,1.15f);

                ent->setVisible(true);
            }

            mDirection = Ogre::Vector3::ZERO;
            if (!nextLocation()) // a check to see if there is another destination
            {
                this->setCurrentNode(grid->getNode(x, y));
                this->setBaseAnimation(ANIM_IDLE_1, true);
                //this->setTopAnimation(ANIM_IDLE_1, true);
            }
            else
            {

                Ogre::Vector3 src = this->mBodyNode->getOrientation() * Ogre::Vector3::UNIT_X;
                if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
                {
                    this->mBodyNode->yaw(Ogre::Degree(180));
                }
                else
                {
                    Ogre::Quaternion quat = src.getRotationTo(mDirection);
                    this->mBodyNode->rotate(quat);
                    this->mBodyNode->yaw(Ogre::Degree(angleOffset));  // To correct for models facing different directions
                }
            }
        }
        else
        {
            this->mBodyNode->translate(mDirection * move);
        }
    }
}
Esempio n. 13
0
Ogre::Entity*
StageFile::GetModel( const StageInfo& info )
{
    //DumpSettings("exported/" + info.data.name + ".lua");

    VectorTexForGen textures;
    Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create(info.data.name + "export", "General");
    Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create(info.data.name + "export", "General");

    u32 number_of_files = GetU32LE(0);
    LOGGER->Log("Number of file " + IntToString(number_of_files) + "\n");



    Ogre::Bone* root1 = skeleton->createBone( "0", 0 );
    Ogre::Bone* root2 = skeleton->createBone( "1", 1 );
    root1->addChild( root2 );

    Ogre::Animation* anim = skeleton->createAnimation( "Idle", 1 );
    Ogre::NodeAnimationTrack* track1 = anim->createNodeTrack( 0, root1 );
    track1->removeAllKeyFrames();
    Ogre::TransformKeyFrame* frame1 = track1->createNodeKeyFrame( 0 );
    Ogre::Matrix3 matrix;
    matrix.FromEulerAnglesYXZ( Ogre::Radian( Ogre::Degree( 0 ) ), Ogre::Radian( Ogre::Degree( -90 ) ), Ogre::Radian( Ogre::Degree( 0 ) ) );
    Ogre::Quaternion rot;
    rot.FromRotationMatrix( matrix );
    frame1->setRotation( rot );



    for (u32 i = 1; i < number_of_files - 1; ++i)
    {
        int offset_to_vertex = GetU32LE(0x04 + i * 0x04);
        MeshExtractor(info.data, "ffvii/battle_stage/" + info.data.name, this, offset_to_vertex, textures, mesh, Ogre::StringConverter::toString(i), 1);
    }



    // <OGRE> ///////////////////////////////
    skeleton->optimiseAllAnimations();
    Ogre::SkeletonSerializer skeleton_serializer;
    skeleton_serializer.exportSkeleton(skeleton.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".skeleton");

    // Update bounds
    Ogre::AxisAlignedBox aabb(-999, -999, -999, 999, 999, 999);
    mesh->_setBounds(aabb, false);
    mesh->_setBoundingSphereRadius(999);

    mesh->setSkeletonName( "models/ffvii/battle/stages/" + info.data.name + ".skeleton" );

    Ogre::MeshSerializer ser;
    ser.exportMesh(mesh.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".mesh");



    // create and export textures for model
    if( textures.size() > 0 )
    {
        int number_of_files = GetU32LE( 0x00 );
        int offset_to_texture = GetU32LE( number_of_files * 0x04 );
        Vram* vram = Vram::MakeInstance().release();

        LoadTimFileToVram( this, offset_to_texture, vram );
        //vram->Save( "qqq" );
        CreateTexture( vram, info.data, "exported/models/ffvii/battle/stages/" + info.data.name + ".png", textures );
        delete vram;
    }



    CreateMaterial("ffvii/battle_stage/" + info.data.name, "exported/models/ffvii/battle/stages/" + info.data.name + ".material", "models/ffvii/battle/stages/" + info.data.name + ".png", "", "");



    Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" );
    Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/ffvii/battle/stages/" + info.data.name + ".mesh" );
    //thisEntity->setDisplaySkeleton(true);
    //thisEntity->setDebugDisplayEnabled(true);
    thisEntity->setVisible(false);
    thisEntity->getAnimationState( "Idle" )->setEnabled( true );
    thisEntity->getAnimationState( "Idle" )->setLoop( true );
    Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode();
    thisSceneNode->setPosition( 0, 0, 0 );
    thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) );
    thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) );
    thisSceneNode->pitch( Ogre::Radian( Ogre::Degree( 90.0f ) ) );
    thisSceneNode->attachObject( thisEntity );

    return thisEntity;
}
void WalkabilityMap::init(TWalkabilityMapParameters tWalkabilityMapParameters,Ogre::SceneManager * pSceneManager,Ogre::SceneNode * pDebugObjects)
{
		unsigned int i,j;

		mDebugObjects=pDebugObjects;
		mSceneManager=pSceneManager;

		mName=tWalkabilityMapParameters.name;

		mDebugObjects->createChildSceneNode("walkability#"+tWalkabilityMapParameters.name);

		myLines.clear();
		myNodes.clear();
		mDisplays.clear();

		//init node numbers
		mNodeNumbers.clear();
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			mNodeNumbers[tWalkabilityMapParameters.walkabilityNodes[i].nodeName]=i;
		}

		//init graph
		mGraph.clear();
		mGraph = Graph(mNodeNumbers.size());

		Ogre::SceneNode * pSceneNode;
		Ogre::Entity * pEntity;
		Ogre::SceneNode * pEntityDebugNode;
		ObjectTextDisplay* pDisplay;
		//create graph nodes
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			//Logger::getInstance()->log("Adding node "+tWalkabilityMapParameters.walkabilityNodes[i].nodeName);

			if(pSceneManager->hasSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName))
			{
				pSceneNode=pSceneManager->getSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
			}
			else
			{
				pSceneNode=pSceneManager->getRootSceneNode()->createChildSceneNode(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
				pSceneNode->setPosition(tWalkabilityMapParameters.walkabilityNodes[i].position);
				pSceneNode->setOrientation(tWalkabilityMapParameters.walkabilityNodes[i].orientation);
			}

			mGraph[getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].nodeName)].mSceneNode=pSceneNode;

			//create graphics debug objects
			std::string debugName="walkability#"+tWalkabilityMapParameters.name+"#"+tWalkabilityMapParameters.walkabilityNodes[i].nodeName;
			pEntityDebugNode=mDebugObjects->createChildSceneNode(debugName);
			pEntityDebugNode->setPosition(pSceneNode->getPosition());
			pEntityDebugNode->setVisible(mVisible);
			pEntity=pSceneManager->createEntity(debugName,"node.mesh");
			pEntity->setMaterialName("red");
			pEntity->setVisible(mVisible);
			pEntity->setCastShadows(false);
			pEntity->setQueryFlags(OUAN::QUERYFLAGS_NONE);
			pEntityDebugNode->attachObject(pEntity);
			myNodes.push_back(pEntity);
			pDisplay = new ObjectTextDisplay(pEntity,Application::getInstance()->getCameraManager()->getCamera());
			pDisplay->setText(tWalkabilityMapParameters.walkabilityNodes[i].nodeName);
			pDisplay->enable(mVisible);

			mDisplays.push_back(pDisplay);
		}

		//add graph edges
		for(i=0;i<tWalkabilityMapParameters.walkabilityNodes.size();i++)
		{
			for(j=0;j<tWalkabilityMapParameters.walkabilityNodes[i].neighbors.size();j++)
			{
				//Logger::getInstance()->log("Adding edge "+tWalkabilityMapParameters.walkabilityNodes[i].nodeName+"-"
				//	+tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j]);

				if(hasNode(tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j]))
				{
					add_edge(getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].nodeName.c_str()),
						getNodeNumber(tWalkabilityMapParameters.walkabilityNodes[i].neighbors[j].c_str()),
						mGraph);
				}
			}
		}

		//set graph edges properties
		Graph::vertex_descriptor v1,v2;
		Ogre::SceneNode * pSceneNode1;
		Ogre::SceneNode * pSceneNode2;

		Graph::edge_descriptor e;

		boost::graph_traits<Graph>::edge_iterator eit,eend;

		boost::property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, mGraph);
		i=0;

		Line3D *myLine; 

		for (tie(eit, eend) = edges(mGraph); eit != eend; ++eit) 
		{
			Graph::edge_descriptor e = *eit;

			v1=source(e, mGraph);
			v2=target(e, mGraph);
			pSceneNode1=mGraph[v1].mSceneNode;
			pSceneNode2=mGraph[v2].mSceneNode;

			weightmap[e]=pSceneNode1->getPosition().distance(pSceneNode2->getPosition());

			//create graphics debug objects
			myLine = new Line3D();
			myLine->addPoint(pSceneNode1->getPosition());
			myLine->addPoint(pSceneNode2->getPosition());
			myLine->setMaterial("black");
			myLine->setCastShadows(false);
			myLine->drawLines();
			mDebugObjects->attachObject(myLine);
			mDebugObjects->setVisible(mVisible);
			myLines.push_back(myLine);
		}

		//print graph information
		Logger::getInstance()->log("[TrajectoryManager] Walkability map vertices");
		boost::graph_traits<Graph>::vertex_iterator vit,vend;
		for (tie(vit, vend) = vertices(mGraph); vit != vend; ++vit) 
		{
			Logger::getInstance()->log("Vertex "+mGraph[*vit].mSceneNode->getName());
		}

		Logger::getInstance()->log("[TrajectoryManager] Walkability map edges");
		for (tie(eit, eend) = edges(mGraph); eit != eend; ++eit) 
		{
			v1=source(*eit, mGraph);
			v2=target(*eit, mGraph);

			Logger::getInstance()->log("Edge "+mGraph[v1].mSceneNode->getName()+"-"+mGraph[v2].mSceneNode->getName()+
				" distance:"+Ogre::StringConverter::toString(Ogre::Real(weightmap[*eit])));
		}
}