Example #1
0
void Actor::update(float deltaTime)
{
    assert(mNode);
    if(mNode->numAttachedObjects() == 0)
    {
        return;
    }

    Ogre::Entity* entity = dynamic_cast<Ogre::Entity*>(mNode->getAttachedObject(0));
    if(!entity)
    {
        return;
    }

    Ogre::AnimationStateSet* set = entity->getAllAnimationStates();
    if(!set)
    {
        return;
    }

    Ogre::AnimationStateIterator it = set->getAnimationStateIterator();
    while(it.hasMoreElements())
    {
        Ogre::AnimationState* state = it.getNext();

        if(state->getEnabled())
        {
            state->addTime(deltaTime);
        }
    }
}
Example #2
0
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int group, const std::string &bonename)
{
    NifOgre::EntityList entities = NifOgre::Loader::createEntities(mEntityList.mSkelBase, bonename,
                                                                   mInsert, mesh);
    std::vector<Ogre::Entity*> &parts = entities.mEntities;
    for(size_t i = 0;i < parts.size();i++)
    {
        parts[i]->getUserObjectBindings().setUserAny(Ogre::Any(group));
        if (mVisibilityFlags != 0)
            parts[i]->setVisibilityFlags(mVisibilityFlags);

        for(unsigned int j=0; j < parts[i]->getNumSubEntities(); ++j)
        {
            Ogre::SubEntity* subEnt = parts[i]->getSubEntity(j);
            subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
        }
    }
    if(entities.mSkelBase)
    {
        Ogre::AnimationStateSet *aset = entities.mSkelBase->getAllAnimationStates();
        Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
        while(asiter.hasMoreElements())
        {
            Ogre::AnimationState *state = asiter.getNext();
            state->setEnabled(false);
            state->setLoop(false);
        }
        Ogre::SkeletonInstance *skelinst = entities.mSkelBase->getSkeleton();
        Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
        while(boneiter.hasMoreElements())
            boneiter.getNext()->setManuallyControlled(true);
    }
    return entities;
}
Example #3
0
float GfxBody::getAnimationMask (const std::string &name)
{
    if (dead) THROW_DEAD(className);
    Ogre::AnimationState *state = getAnimState(name);
    if (!state->getEnabled()) return 0.0f;
    return state->getWeight();
}
    bool EC_OgreAnimationController::EnableAnimation(const std::string& name, bool looped, Real fadein, bool high_priority)
    {
        Ogre::Entity* entity = GetEntity();
        Ogre::AnimationState* animstate = GetAnimationState(entity, name);
        if (!animstate) 
            return false;

        animstate->setLoop(looped);

        // See if we already have this animation
        AnimationMap::iterator i = animations_.find(name);
        if (i != animations_.end())
        {
            i->second.phase_ = PHASE_FADEIN;
            i->second.num_repeats_ = (looped ? 0: 1);
            i->second.fade_period_ = fadein;
            i->second.high_priority_ = high_priority;
            return true;
        }
        
        // Start new animation from zero weight & speed factor 1, also reset time position
        animstate->setTimePosition(0.0f);
        
        Animation newanim;
        newanim.phase_ = PHASE_FADEIN;
        newanim.num_repeats_ = (looped ? 0: 1); // if looped, repeat 0 times (loop indefinetly) otherwise repeat one time.
        newanim.fade_period_ = fadein;
        newanim.high_priority_ = high_priority;

        animations_[name] = newanim;

        return true;
    }
Example #5
0
void GfxBody::setAnimationMask (const std::string &name, float v)
{
    if (dead) THROW_DEAD(className);
    Ogre::AnimationState *state = getAnimState(name);
    state->setWeight(v);
    state->setEnabled(v > 0.0f);
}
Example #6
0
/**
 * @brief render a frame
 * @author Kito Berg-Taylor
 */
void THIS::paintGL()
{
    if (!initialised)
        initializeOgre();

    for (Ogre::SceneManager::MovableObjectIterator mit = mSceneMgr->getMovableObjectIterator("Entity");mit.hasMoreElements(); mit.moveNext() )
    {
        Ogre::Entity *entity = static_cast<Ogre::Entity*>(mit.peekNextValue());
        if (entity->hasSkeleton() )
        {
            for (Ogre::AnimationStateIterator animIt = entity->getAllAnimationStates()->getAnimationStateIterator(); animIt.hasMoreElements(); animIt.moveNext() )
            {
                Ogre::AnimationState *animState = animIt.peekNextValue();
                if ( animState->getEnabled() )
                {
                    animState->addTime(mWindow->getBestFPS()/10000);
                }
            }
        }
    }

    //Ogre::WindowEventUtilities::messagePump();
    mRoot->renderOneFrame();


}
Example #7
0
void
PlayersManager::createPlayer(zappy::Player *player)
{
  Ogre::Entity *ent;
  Ogre::SceneNode *node;
  Ogre::AnimationState *anim;
  std::string id(NumberToString<unsigned int>(player->getId()));
  OPlayer *toAdd;

  ent = this->mSceneMgr->createEntity("Player" + id, "robot.mesh");
  node = this->mSceneMgr->getRootSceneNode()->
    createChildSceneNode(PLAYERNODENAME + id,
                         Ogre::Vector3(player->getX() * Constants::SquareSize,
                                       0,
                                       player->getY() * Constants::SquareSize));
  ent->setQueryFlags(Constants::PLAYER_MASK);
  anim = ent->getAnimationState("Idle");
  anim->setLoop(true);
  anim->setEnabled(true);
  node->attachObject(ent);
  player->setRendered(true);
  toAdd = new OPlayer(ent, node);
  toAdd->setSpell(this->mSceneMgr->createParticleSystem("Aureola" + id, "Examples/Aureola"));
  toAdd->setBroad(this->mSceneMgr->createParticleSystem("Purple" + id, "Examples/PurpleFountain"));
  this->mOPlayers.push_back(toAdd);
}
int main(int argc, char **argv)
{
		if(argc <= 1 || argc > 2)
		{
			std::cout << "Invalid argument, it sould be : ./ogre_show_animationstate /path/name.mesh !\n";
			return -1;
		}

		std::string nameMesh(argv[1]);
		std::string pathMesh;

		int index = nameMesh.size();
		while(nameMesh[index] != '/')
		{
			index--;
			if(index == 0)
			{
				pathMesh = "./";
				break;
			}
		}

		if(index != 0)
		{
			pathMesh = nameMesh.substr(0, index);
		}

		// Init
		Ogre::Root* mRoot = new Ogre::Root();
		new Ogre::DefaultHardwareBufferManager();

		Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General");
		Ogre::ResourceGroupManager::getSingleton().addResourceLocation(pathMesh, "FileSystem", "General");
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		// load mesh
		Ogre::MeshPtr mesh =
		Ogre::MeshManager::getSingleton().load(nameMesh, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

		// create & load a SkeletonInstance
		Ogre::SkeletonInstance* skelInst = new Ogre::SkeletonInstance(mesh->getSkeleton());
		skelInst->load();

		// create & load an AnimationStateSet
		Ogre::AnimationStateSet* animStateSet = new Ogre::AnimationStateSet();
		mesh->_initAnimationState(animStateSet);

		// show animation state
		std::cout << "Animation states : \n";
		Ogre::AnimationStateIterator iter = animStateSet->getAnimationStateIterator();
		while(iter.hasMoreElements())
		{
			Ogre::AnimationState* animationState = iter.getNext();
			std::cout << "\t- " << animationState->getAnimationName() << "\n";
		}

		return 0;
}
Example #9
0
	void DemoGameLogic::update(void)
	{
		mLastFrameTime = mCurrentTime;
		mCurrentTime = mTime->elapsed();

		float timeElapsedInSeconds = (mCurrentTime - mLastFrameTime) / 1000.0f;

		for (Ogre::SceneManager::MovableObjectIterator moi = mSceneManager->getMovableObjectIterator("Entity"); moi.hasMoreElements(); moi.moveNext())
		{
			Ogre::Entity *entity = static_cast<Ogre::Entity*>(moi.peekNextValue());

			Ogre::AnimationStateSet* animationStateSet = entity->getAllAnimationStates();		
			if(animationStateSet && animationStateSet->hasAnimationState("Walk"))
			{
				Ogre::AnimationState* walkAnimationState = animationStateSet->getAnimationState("Walk");
				walkAnimationState->addTime(timeElapsedInSeconds);
			}
		}

		float distance = mCameraSpeed * timeElapsedInSeconds;

		if(mKeyStates[Qt::Key_W] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() + mCamera->getDirection() * distance);
		}
		if(mKeyStates[Qt::Key_S] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() - mCamera->getDirection() * distance);
		}
		if(mKeyStates[Qt::Key_A] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() - mCamera->getRight() * distance);
		}
		if(mKeyStates[Qt::Key_D] == KS_PRESSED)
		{
			mCamera->setPosition(mCamera->getPosition() + mCamera->getRight() * distance);
		}

		if(!mIsFirstFrame)
		{
			QPoint mouseDelta = mCurrentMousePos - mLastFrameMousePos;
			mCamera->yaw(Ogre::Radian(-mouseDelta.x() * timeElapsedInSeconds));
			mCamera->pitch(Ogre::Radian(-mouseDelta.y() * timeElapsedInSeconds));

			int wheelDelta = mCurrentWheelPos - mLastFrameWheelPos;
			Ogre::Radian fov = mCamera->getFOVy();
			fov += Ogre::Radian(-wheelDelta * 0.001);
			fov = (std::min)(fov, Ogre::Radian(2.0f));
			fov = (std::max)(fov, Ogre::Radian(0.5f));
			mCamera->setFOVy(fov);
		}
		mLastFrameMousePos = mCurrentMousePos;
		mLastFrameWheelPos = mCurrentWheelPos;

		mIsFirstFrame = false;
	}
Example #10
0
	ProfessorController(Root* root)
	{
		mProfessorNode = root->getSceneManager("main")->getSceneNode("Professor");
		mProfessorEntity = root->getSceneManager("main")->getEntity("Professor");

		mWalkSpeed = 80.0f;
		mDirection = Vector3::ZERO;
		mAnimationState = mProfessorEntity->getAnimationState("Walk");
		mAnimationState->setEnabled(true);
		mAnimationState->setLoop(true);
	}
Example #11
0
	bool CAnimatedEntity::stopAnimation(const std::string &anim)
	{
		if(!_entity->getAllAnimationStates()->hasAnimationState(anim))
			return false;
		Ogre::AnimationState *animation = _entity->getAnimationState(anim);
		animation->setEnabled(false);
		// Si la animación a parar es la animación activa ya no lo estará.
		if(animation == _currentAnimation)
			_currentAnimation = 0;
		return true;

	} // stopAnimation
 void EC_OgreAnimationController::SetAnimationToEnd(const std::string& name)
 {
     Ogre::Entity* entity = GetEntity();
     Ogre::AnimationState* animstate = GetAnimationState(entity, name);
     if (!animstate) 
         return;
         
     if (animstate)
     {
         SetAnimationTimePosition(name, animstate->getLength());
     }
 }
Example #13
0
bool CAnimatedEntity::setAnimation(const std::string &anim, bool loop, int rewind, float fadeTime)
{
    if(!_entity->getAllAnimationStates()->hasAnimationState(anim))
        return false;
    //comprobamos si la animación ya estaba ejecutandose
    auto runningAnim = _runningAnimations.find(anim);

    if(runningAnim != _runningAnimations.end()) {
        if(runningAnim->second.state == FADE_OUT) {
            runningAnim->second.state = FADE_IN;

            //comprobamos que la animación no estaba justo para
            //ser sacada
            if(!_deletedAnims.empty()) {

                auto delAnim = _deletedAnims.begin();
                auto delEnd = _deletedAnims.end();

                for(; delAnim!=delEnd; delAnim++) {
                    if ((*delAnim) == runningAnim->second.animation->getAnimationName()) {
                        _deletedAnims.erase(delAnim);
                        runningAnim->second.animation->setEnabled(true);
                        break;
                    }
                }

            }

        }
        runningAnim->second.direction = rewind;
        return true;
    }

    //cogemos la animacion y la preparamos para ejecutarla
    Ogre::AnimationState* animstate = _entity->getAnimationState(anim);
    animstate->setEnabled(true);
    animstate->setLoop(loop);
    animstate->setWeight(0);

    //seteamos la animación nueva para que haga fade-in, teniendo
    //en cuenta el tiempo de fade que se le ha pasado
    Animation animation;
    animation.animation = animstate;
    animation.state = FADE_IN;
    animation.fadeTime = fadeTime;
    animation.direction = rewind;
    //metemos la animacion en la lista de animaciones ejecutandose
    TAnim newAnim (anim,animation);
    _runningAnimations.insert(newAnim);

    return true;

} // setAnimation
Example #14
0
void NPCCharacter::_behaviorMove(const Ogre::Vector3& target)
{
	//Check for duplicate move calls and update lua function call with that info
	//std::cout << target << std::endl;
	if(_destination.squaredDistance(target) >= 5)
	{
		updateDestination(target,false);
		_destination = target;
	}

	if(destinationReached())
	{
		_isBhvFinished = true;
	}
	else
	{
		_isBhvFinished = false;
	}
	

	//point the character in the direction it's traveling
	Ogre::Vector3 vel = getVelocity();
	float speed = vel.length();
	vel.y = 0;
	vel.normalise();
	if(speed > .2f)
	{
		Ogre::Vector3 src = _node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
		src.y = 0;

		//moving sufficiently fast, change to moving animation and point character
		Utility::rotateToTarget(_node,vel,true);

		//change animation if needed.
		if(_animHandler.getSource() != nullptr)
		{
			Ogre::AnimationState* target = _animHandler.getTarget();
			//this relies on the properties of the '&&' construct used by C++(if the first is false,
			//then the if-statement is false. It DOESN'T check both fields.
			if((target == nullptr && _animHandler.getSource()->getAnimationName() != "Walk") || 
				(target != nullptr && target->getAnimationName() != "Walk"))
			{
				_animHandler.blend("Walk",AnimationBlender::BlendWhileAnimating,.2f,true);
			}
		}
	}
	//also have to reset the head, since I'm manually controlling it.
	Ogre::Skeleton* skel = static_cast<Ogre::Entity*>(_movableObject)->getSkeleton();
	Ogre::Bone* headBone = skel->getBone("Bip01_Head");
	//not sure how to do this.

}
Example #15
0
CharacterAnimation::CharacterAnimation(Ogre::Entity* ent)
{
	Ogre::AnimationStateSet * anims = ent->getAllAnimationStates();
	Ogre::AnimationStateIterator it = anims->getAnimationStateIterator();
	while(it.hasMoreElements())
	{
		Ogre::AnimationState * as = it.getNext();
		as->setWeight(0);
		Animations.insert(std::make_pair(as->getAnimationName(), AnimState(as, 0, 5, 5, 1)));
	}
	
	ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
}
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;
				}
			}
		}
	}
}
Example #17
0
CreatureAnimation::CreatureAnimation(const MWWorld::Ptr& ptr): Animation()
{
    mInsert = ptr.getRefData().getBaseNode();
    MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();

    assert (ref->mBase != NULL);
    if(!ref->mBase->mModel.empty())
    {
        std::string mesh = "meshes\\" + ref->mBase->mModel;

        mEntityList = NifOgre::NIFLoader::createEntities(mInsert, &mTextKeys, mesh);
        for(size_t i = 0; i < mEntityList.mEntities.size(); i++)
        {
            Ogre::Entity *ent = mEntityList.mEntities[i];
            ent->setVisibilityFlags(RV_Actors);

            bool transparent = false;
            for (unsigned int j=0; j < ent->getNumSubEntities() && !transparent; ++j)
            {
                Ogre::MaterialPtr mat = ent->getSubEntity(j)->getMaterial();
                Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
                while (techIt.hasMoreElements() && !transparent)
                {
                    Ogre::Technique* tech = techIt.getNext();
                    Ogre::Technique::PassIterator passIt = tech->getPassIterator();
                    while (passIt.hasMoreElements() && !transparent)
                    {
                        Ogre::Pass* pass = passIt.getNext();

                        if (pass->getDepthWriteEnabled() == false)
                            transparent = true;
                    }
                }
            }
            ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
        }

        if(mEntityList.mSkelBase)
        {
            Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates();
            Ogre::AnimationStateIterator as = aset->getAnimationStateIterator();
            while(as.hasMoreElements())
            {
                Ogre::AnimationState *state = as.getNext();
                state->setEnabled(true);
                state->setLoop(false);
            }
        }
    }
}
Example #18
0
void Animation::setEnabled(bool enabled)
{
	for (AnimationPartSet::const_iterator I = mAnimationParts.begin(); I != mAnimationParts.end(); ++I) {
		//we'll get an assert error if we try to enable an animation with zero length
		Ogre::AnimationState* state = I->state;
		if (state->getLength() != 0) {
			if (state->getEnabled() != enabled) {
				state->setEnabled(enabled);
				state->destroyBlendMask();
				if (enabled) {
					const std::vector<BoneGroupRef>& boneGroupRefs = I->boneGroupRefs;
					for (std::vector<BoneGroupRef>::const_iterator J = boneGroupRefs.begin(); J != boneGroupRefs.end(); ++J) {
						const BoneGroupRef& boneGroupRef = *J;
						const BoneGroupDefinition& boneGroupDef = *boneGroupRef.boneGroupDefinition;
						if (!state->hasBlendMask()) {
							state->createBlendMask(mBoneNumber, 0.0f);
						}
						const std::vector<size_t>& boneIndices = boneGroupDef.Bones;
						for (std::vector<size_t>::const_iterator bones_I = boneIndices.begin(); bones_I != boneIndices.end(); ++bones_I) {
							state->setBlendMaskEntry(*bones_I, boneGroupRef.weight);
						}
					}
				}
			}
		}
	}
}
Example #19
0
//-------------------------------------------------------------------------------------
bool
PlayersManager::taking(zappy::Player *p, int i)
{
  OPlayer *OPlayer;

  OPlayer = this->mOPlayers.at(i);
  Ogre::AnimationState *anim = OPlayer->getEntity()->
    getAnimationState("Slump");
  anim->setEnabled(true);
  anim->setLoop(true);
  anim->addTime(this->tslf);
  if (OPlayer->stateHasChanged())
    OPlayer->detachAnim();
  return true;
}
Example #20
0
void MainWindow::updateOGRE()
{
	QMutexLocker locker(&mutex);
	static bool updateGUI=true;


	Ogre::Root* mRoot = Ogre::Root::getSingletonPtr();
	mRoot->_fireFrameStarted();

	// loop through ogre widgets and update animation
	QList<OgreWidget*> rendlist = this->findChildren<OgreWidget*>();
	foreach (OgreWidget* w, rendlist)
	{

		// update animation for OgreWidget's sceneManager
		if (w->mRenderWindow && w->updatesEnabled())
		{
			// update OgreWidget
			w->update();
			//emit w->paintEvent(new QPaintEvent(w->rect()));
			for (Ogre::SceneManager::MovableObjectIterator mit = w->getSceneManager()->getMovableObjectIterator("Entity");
				mit.hasMoreElements(); mit.moveNext() )
			{
				Ogre::Entity *entity = static_cast<Ogre::Entity*>(mit.peekNextValue());
				if (updateGUI) {
					updateGUI = false;

				}
				// check has skeleton to avoid crash for non animable entities
				if (entity->hasSkeleton())
				{
					for (Ogre::AnimationStateIterator animIt = entity->getAllAnimationStates()->getAnimationStateIterator();
						animIt.hasMoreElements(); animIt.moveNext() )
					{
						Ogre::AnimationState *animState = animIt.peekNextValue();
						if ( animState->getEnabled() )
						{
							//std::cout << entity->getName() << " ZZZZZZZZZZZ " << animState->getAnimationName();
							animState->addTime(w->getRenderWindow()->getBestFPS()/10000);
						}
					}
				}
			}
		}
	}
	mRoot->_fireFrameRenderingQueued();
	mRoot->_fireFrameEnded();
}
Example #21
0
 bool customframeEnded( const Ogre::FrameEvent& evt)
 {
   // Update animation
   // To move, we add it the time since last frame
   mAnimationState->addTime( evt.timeSinceLastFrame );
   return true;
 }
Example #22
0
void
	Player::stopAnimation(std::string anim)
{
	Ogre::SceneManager::MovableObjectIterator iterator = SceneManager()->getMovableObjectIterator("Entity");
	while(iterator.hasMoreElements())
	{
		Ogre::Entity* e = static_cast<Ogre::Entity*>(iterator.getNext());

		if (e->hasSkeleton())
		{
			Ogre::AnimationState *animation = e->getAnimationState(anim);
			animation->setEnabled(false);
			animation->setTimePosition(0);
		}
	}
}
 bool EC_OgreAnimationController::SetAnimationTimePosition(const std::string& name, Real newPosition)
 {
     Ogre::Entity* entity = GetEntity();
     Ogre::AnimationState* animstate = GetAnimationState(entity, name);
     if (!animstate) 
         return false;
         
     // See if we find this animation in the list of active animations
     AnimationMap::iterator i = animations_.find(name);
     if (i != animations_.end())
     {
         animstate->setTimePosition(newPosition);
         return true;
     }
     // Animation not active
     return false;
 }
Example #24
0
//-------------------------------------------------------------------------------------
bool
PlayersManager::moving(zappy::Player *p, int i)
{
  OPlayer *OPlayer = this->mOPlayers.at(i);
  this->speed = Constants::SquareSize /
    ((Constants::timeUnit / static_cast<Ogre::Real>(time)));

  Ogre::SceneNode *node = OPlayer->getSceneNode();
  Ogre::Vector3 &direction = OPlayer->getDirection();
  Ogre::Real &distance = OPlayer->getDistance();
  Ogre::Real move = this->speed * this->tslf;
  Ogre::Vector3 destination(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize);
  Ogre::AnimationState *anim = OPlayer->getEntity()->
    getAnimationState(distance <= 0.0f ? "Idle" : "Walk");

  anim->setLoop(true);
  anim->setEnabled(true);
  if (direction == Ogre::Vector3::ZERO)
    {
      Ogre::Vector3 src = node->getOrientation() * Ogre::Vector3::UNIT_X;
      direction = destination - node->getPosition();
      distance = direction.normalise();
      if ((1.0f + src.dotProduct(direction)) < 0.0001f)
        node->yaw(Ogre::Degree(180));
      else
        node->rotate(src.getRotationTo(direction));
      if (distance > Constants::SquareSize)
        distance = 0.0f;
    }
  else
    {
      distance -= move;
      if (distance <= 0.0f)
        {
          node->setPosition(destination);
          direction = Ogre::Vector3::ZERO;
        }
      else
        node->translate(direction * move);
    }
  if (OPlayer->stateHasChanged())
    OPlayer->detachAnim();
  anim->addTime(this->tslf);
  return true;
}
Example #25
0
//-------------------------------------------------------------------------------------
bool
PlayersManager::dying(zappy::Player *p, int i)
{
  OPlayer *OPlayer = this->mOPlayers.at(i);

  if (OPlayer->stateHasChanged())
    OPlayer->detachAnim();
  Ogre::Vector3 position(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize);
  Ogre::AnimationState *anim = OPlayer->getEntity()->
    getAnimationState("Die");
  Ogre::SceneNode *node = OPlayer->getSceneNode();
  if (position != node->getPosition())
      node->setPosition(position);
  anim->setEnabled(true);
  anim->setLoop(false);
  anim->addTime(this->tslf);
  return true;
}
Example #26
0
	bool frameStarted(const FrameEvent &evt)
	{
	
		

		mAnimationState->addTime(evt.timeSinceLastFrame);

		return true;
	}
Example #27
0
	void CAnimatedEntity::stopAllAnimations()
	{
		if(_entity->getAllAnimationStates()->hasEnabledAnimationState())
		{
			Ogre::ConstEnabledAnimationStateIterator it = 
				_entity->getAllAnimationStates()->getEnabledAnimationStateIterator();
			Ogre::AnimationState *animation;

			//hay que recorrer con el iterador las animaciones una a una y pausarlas
			while(it.hasMoreElements())
			{
				animation = it.getNext();
				animation->setEnabled(false);
			}

			// Si había animación activa ya no lo está.
			_currentAnimation = 0;
		}

	} // stopAllAnimations
    bool EC_OgreAnimationController::HasAnimationFinished(const std::string& name)
    {
        Ogre::Entity* entity = GetEntity();
        Ogre::AnimationState* animstate = GetAnimationState(entity, name);
        if (!animstate) 
            return false;

        AnimationMap::iterator i = animations_.find(name);
        if (i != animations_.end())
        {
            if ((!animstate->getLoop()) && ((i->second.speed_factor_ >= 0.f && animstate->getTimePosition() >= animstate->getLength()) ||
                (i->second.speed_factor_ < 0.f && animstate->getTimePosition() <= 0.f)))
                return true;
            else
                return false;
        }

        // Animation not listed, must be finished
        return true;
    }
Example #29
0
void CAnimatedEntity::moveBone(const std::string &bone, float pitch) {
    Ogre::Bone * entityBone = _entity->getSkeleton()->getBone(bone);
    entityBone->reset();

    Ogre::Skeleton * skel = _entity->getSkeleton();

    //entityBone->setManuallyControlled(true);

    unsigned short boneHandle = entityBone->getHandle();
    Ogre::AnimationStateIterator animStateIt = _entity->getAllAnimationStates()->getAnimationStateIterator();

    while( animStateIt.hasMoreElements() )
    {
        Ogre::AnimationState *pAnimState = animStateIt.getNext();
        // ignore disabled animations
        skel->getAnimation(pAnimState->getAnimationName())->destroyNodeTrack(boneHandle);
    }

    entityBone->pitch(Ogre::Radian(pitch));
}
Example #30
0
  void createScene()
  {
    // Create the Entity
    Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh");
    // Attach robot to scene graph
    Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot");
    //RobotNode->setPosition((Ogre::Real)-0.3, (Ogre::Real)0.2, (Ogre::Real)0);
    RobotNode->attachObject(robot);
    RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
    RobotNode->pitch(Ogre::Degree(180));
    RobotNode->yaw(Ogre::Degree(-90));

    // The animation
    // Set the good animation
    mAnimationState = robot->getAnimationState( "Idle" );
    // Start over when finished
    mAnimationState->setLoop( true );
    // Animation enabled
    mAnimationState->setEnabled( true );
  }