Ejemplo n.º 1
0
void OgreApplication::SetupAnimation(Ogre::String object_name){

	/* Retrieve scene manager and root scene node */
    Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
	Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

	/* Set up animation */
	Ogre::Real duration = Ogre::Math::TWO_PI;
	Ogre::Real num_steps = 36;
	Ogre::Real step = duration/num_steps;
	Ogre::Animation* animation = scene_manager->createAnimation("Animation", duration);
	animation->setInterpolationMode(Ogre::Animation::IM_LINEAR);
	Ogre::Node *object_scene_node = root_scene_node->getChild(object_name);
	Ogre::NodeAnimationTrack* track = animation->createNodeTrack(0, object_scene_node);

	/* Set up frames for animation */
	Ogre::TransformKeyFrame* key;
	Ogre::Quaternion quat;
	for (int i = 0; i < num_steps; i++){
		Ogre::Real current = ((float) i) * step;
		key = track->createNodeKeyFrame(current);
		quat.FromAngleAxis(Ogre::Radian(-current), Ogre::Vector3(0, 1, 0));
		key->setRotation(quat);
		key->setScale(Ogre::Vector3(0.5, 0.5, 0.5));
	}

	/* Create animation state */
	animation_state_ = scene_manager->createAnimationState("Animation");
	animation_state_->setEnabled(true);
	animation_state_->setLoop(true);

	/* Turn on animating flag */
	animating_ = true;
}
Ejemplo n.º 2
0
void AssetLoader::createCamera(Ogre::SceneManager* sceneMgr, const aiScene* scene, Ogre::String camName)
{
	for (size_t n = 0; n < scene->mNumCameras; n++)
	{
		// カメラを作成
		Ogre::Camera* cam = sceneMgr->createCamera(scene->mCameras[n]->mName.data);
		std::cout << "Create Camra " << cam->getName() << " " << scene->mCameras[n]->mHorizontalFOV << std::endl;
		cam->setFOVy(Ogre::Radian(scene->mCameras[n]->mHorizontalFOV));
		
		// 視点アニメーション用ノード
		Ogre::SceneNode* camNode = sceneMgr->getRootSceneNode()->createChildSceneNode(cam->getName()+"CamNode");
		camNode->attachObject(cam);

		// アニメーションを走査
		for (size_t na = 0; na < scene->mNumAnimations; na++) {
			aiAnimation* aiani = scene->mAnimations[na];
			for (size_t nc = 0; nc < aiani->mNumChannels; nc++) {
				// カメラと同じ名前のチャネルを取得する
				if (Ogre::String(scene->mCameras[n]->mName.data) == cam->getName()) {
					
					//アニメーションを付けるトラックを作成しておく
					Ogre::Animation* ogani = sceneMgr->createAnimation(cam->getName()+"Animation", aiani->mDuration);
					std::cout << "Animation : " << ogani->getName() << std::endl; 
					Ogre::NodeAnimationTrack* track = ogani->createNodeTrack(0, camNode);
					ogani->setInterpolationMode(Ogre::Animation::IM_LINEAR);

					// アニメーションチャネルからキーフレームアニメーションを取得
					aiNodeAnim* chan = aiani->mChannels[n];
					for (size_t np = 0; np < chan->mNumPositionKeys; np++) {						
						aiVectorKey* vk = &(chan->mPositionKeys[np]);
						Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(vk->mTime);
						key->setTranslate(Ogre::Vector3(vk->mValue[0], vk->mValue[1], vk->mValue[2]));

						aiQuatKey* qk = &(chan->mRotationKeys[np]);
						key->setRotation(Ogre::Quaternion(qk->mValue.w, qk->mValue.x, qk->mValue.y, qk->mValue.z));
					}

					// 管理するアニメーションの名前を付けておく
					Ogre::AnimationState* aniState = sceneMgr->createAnimationState(ogani->getName());
					aniState->setEnabled(true);
					aniState->setLoop(true);
					aniState->setTimePosition(0.0);

					//ループを抜ける
					na = scene->mNumAnimations;
					break;
				}
			}
		}
	}
}
Ejemplo n.º 3
0
void MenuScene::createAnimation(void)
{

	Ogre::SceneNode *titleNode = static_cast<Ogre::SceneNode *>(mSceneMgr->getRootSceneNode()->getChild("boomb_title"));
	Ogre::Animation *anim = mSceneMgr->createAnimation("title_animation", 3);
	anim->setInterpolationMode(Ogre::Animation::IM_SPLINE);
	Ogre::NodeAnimationTrack *track = anim->createNodeTrack(0, titleNode);
	Ogre::TransformKeyFrame *key = track->createNodeKeyFrame(0);
	key->setTranslate(Ogre::Vector3(0,0,100));
	Ogre::Quaternion q1 = titleNode->getOrientation();
	Ogre::Quaternion q2(Ogre::Degree(45), Ogre::Vector3::UNIT_X);
	key->setRotation(q2);
	key = track->createNodeKeyFrame(1.5);
	key->setTranslate(Ogre::Vector3(0,0,120));
	key->setRotation(q2);
	key = track->createNodeKeyFrame(3);
	key->setTranslate(Ogre::Vector3(0,0,100));
	key->setRotation(q2);

	mTitleAnimState = mSceneMgr->createAnimationState("title_animation");
	mTitleAnimState->setEnabled(true);
	mTitleAnimState->setLoop(true);

	Ogre::SceneNode *backgroundNode = static_cast<Ogre::SceneNode *>(mSceneMgr->getRootSceneNode()->getChild("boomb_background"));
	anim = mSceneMgr->createAnimation("background_animation", 30);
	anim->setInterpolationMode(Ogre::Animation::IM_SPLINE);
	track = anim->createNodeTrack(0, backgroundNode);
	key = track->createNodeKeyFrame(0);
	key->setTranslate(Ogre::Vector3(20,0,20));
	key = track->createNodeKeyFrame(15);
	key->setTranslate(Ogre::Vector3(-20,0,-20));
	key = track->createNodeKeyFrame(30);
	key->setTranslate(Ogre::Vector3(20,0,20));
	mBackgroundAnimState = mSceneMgr->createAnimationState("background_animation");
	mBackgroundAnimState->setEnabled(true);
	mBackgroundAnimState->setLoop(true);
}
Ejemplo n.º 4
0
/* Function used to load an AnimationState to a sceneNode.
 * Params:
 * 	@scnManager		the SceneManager
 * 	@node			The SceneNode to load the AnimationStates
 * 	@elem			The TiXmlElement where is the animation
 * Returns:
 * 	anim			On success
 * 	0				On error
 */
bool Util::getAnimation(Ogre::SceneManager *scnManager,
		Ogre::SceneNode *node,
		TiXmlElement *elem,
		std::list<Ogre::AnimationState *> &animList)
{
	ASSERT(scnManager);
	ASSERT(node);
	ASSERT(elem);

	if(Ogre::String(elem->Value()) != "animations") {
		debug("Invalid animation xml: %s \n", elem->Value());
		return false;
	}
	animList.clear();

	TiXmlElement *pElement = elem->FirstChildElement("animation");
	if(!pElement){
		debug("No animations found\n");
		return false;
	}
	while(pElement){
		TiXmlElement *actualElement = pElement;
		Ogre::String nombreanimacion = actualElement->Attribute("name");
		Ogre::String activada = actualElement->Attribute("enable");
		Ogre::String loop = actualElement->Attribute("loop");
		Ogre::String modointerpolacion = actualElement->Attribute("interpolationMode");
		Ogre::String modointerpolacionrotacion = actualElement->Attribute("rotationInterpolationMode");
		Ogre::Real longitud= Ogre::StringConverter::parseReal(actualElement->Attribute("length"));

		Ogre::SceneManager *sceneMgr = scnManager;
		Ogre::Animation *animrueda = sceneMgr->createAnimation(nombreanimacion,longitud);

		if (modointerpolacion == "spline") {
			animrueda->setInterpolationMode(Ogre::Animation::IM_SPLINE);
		} else //linear
		{
			animrueda->setInterpolationMode(Ogre::Animation::IM_LINEAR);
		}

		if (modointerpolacionrotacion == "spherical") {
			animrueda->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL);
		} else //linear
		{
			animrueda->setRotationInterpolationMode(Ogre::Animation::RIM_LINEAR);
		}

		Ogre::NodeAnimationTrack *track = animrueda->createNodeTrack(
				animrueda->getNumNodeTracks() + 1, node);

		actualElement = actualElement->FirstChildElement();
		do {
			Ogre::Real tiempo = Ogre::StringConverter::parseReal(
					actualElement->Attribute("time"));
			Ogre::TransformKeyFrame *kf = track->createNodeKeyFrame(tiempo);

			kf->setTranslate(
					parseVector3(actualElement->FirstChildElement("translation")));
			kf->setRotation(
					parseQuaternion(
							actualElement->FirstChildElement("rotation")));
			kf->setScale(
					parseVector3(
							actualElement->FirstChildElement("scale")));

		} while (actualElement = actualElement->NextSiblingElement());

		// Create the animation and put it in the list
		Ogre::AnimationState *as = scnManager->createAnimationState(nombreanimacion);
		as->setEnabled(false);
		as->setLoop(false);
		ASSERT(as);
		animList.push_back(as);
		pElement = pElement->NextSiblingElement("animation");
	}


	return true;
}