示例#1
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();


}
示例#2
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);
        }
    }
}
示例#3
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;
 }
示例#4
0
	bool frameStarted(const FrameEvent &evt)
	{
	
		

		mAnimationState->addTime(evt.timeSinceLastFrame);

		return true;
	}
示例#5
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;
	}
示例#6
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;
}
示例#7
0
void Pacman::arrancaMuerte(Ogre::Real deltaT)
{
  stop();
  Ogre::AnimationState *anim;
  Ogre::Entity* pacmanEnt = static_cast<Ogre::Entity*>( node->getAttachedObject(PACMAN_NODE));
  anim = pacmanEnt->getAnimationState(PACMAN_EAT_ANIM);
  anim->setEnabled(false);
  anim = pacmanEnt->getAnimationState(PACMAN_DIES);
  anim->addTime(deltaT);
  anim->setEnabled(true);
  anim->setLoop(false);
  anim->setTimePosition(0.0);
  estoyMuriendo = true;

}
示例#8
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();
}
示例#9
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;
}
示例#10
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;
}
示例#11
0
/**更新动画*/
void Enemy::updateAnimation(float time)
{

	m_AniFade-=time;
	m_AniFade=std::max(m_AniFade,0.0f);

	if (m_pEntity)
	{
		Ogre::AnimationStateSet* animStateSet = m_pEntity->getAllAnimationStates();
		// 更新自身动画
		if (animStateSet)
		{
			Ogre::ConstEnabledAnimationStateIterator animStateItor = animStateSet->getEnabledAnimationStateIterator();
			while (animStateItor.hasMoreElements())
			{
				Ogre::AnimationState* animState = animStateItor.getNext();
				animState->addTime(time);
				// 当前动画逐渐递增权重
				if (animState== m_pAniSate)
				{
					if (animState->getWeight() < 1.0f)
					{
						animState->setWeight(1.0f - m_AniFade);
					}
				}
				// 其余动画逐渐递减权重,直到关闭动画
				else
				{
					if (Ogre::Math::RealEqual(animState->getWeight(), 0.0f))
					{
						animState->setWeight(1.0f);
						animState->setEnabled(false);
					}
					else
					{
						animState->setWeight(m_AniFade);
					}
				}
			}
		}

	}
}
示例#12
0
	bool frameStarted(const FrameEvent &evt)
	{
		mAnimationState = mProfessorEntity->getAnimationState("Walk");
		mAnimationState->setLoop(true);
		mAnimationState->setEnabled(true);
		//if (mDirection == Vector3::ZERO)
		//{
		//	if (nextLocation())
		//	{
		//		mAnimationState = mProfessorEntity->getAnimationState("Walk");
		//		mAnimationState->setLoop(true);
		//		mAnimationState->setEnabled(true);
		//	}
		//}
		//else
		//{
		//	Real move = mWalkSpeed * evt.timeSinceLastFrame; // 이동량 계산
		//	mDistance -= move; // 남은 거리 계산
		//	if (mDistance <= 0.0f)
		//	{ // 목표 지점에 다 왔으면…
		//		mProfessorNode->setPosition(mDestination); // 목표 지점에 캐릭터를 위치
		//		mDirection = Vector3::ZERO; // 정지 상태로 들어간다.
		//		if (!nextLocation())
		//		{
		//			mAnimationState->setEnabled(false);
		//			mAnimationState = mProfessorEntity->getAnimationState("Idle");
		//			mAnimationState->setLoop(true);
		//			mAnimationState->setEnabled(true);
		//		}
		//	}
		//	else
		//	{
		//		mProfessorNode->translate(mDirection * move);
		//	}
		//}

		mAnimationState->addTime(evt.timeSinceLastFrame);

		return true;
	}
示例#13
0
/*		crouch_idle | crouch_to_stand | crouch_walk | fall_idle | fall_to_roll
*		gangname_style | idle0 | idle1 | idle2 | jump | turnLeft | turnLeft90
*		turnRight | turnRight90 | run | run_to_stop | samba | strafeLeft
*		strafeRight | the_running_man | walkBackward | walkForward
*		(Example: playAnimation("jump", time);)
*/
void 
	Player::playAnimation(std::string anim, float time)
{
	disableAnimations();

	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);

			/*if (animation->getAnimationName().compare("jump") == 0)
			finishAnimation(animation, time);
			*/
			animation->setEnabled("true");
			animation->addTime(time);
		}
	}
}
示例#14
0
	bool frameStarted(const FrameEvent &evt)
	{
		// Fill Here --------------------------------------------------------------
		if (Vector3::ZERO == mDirection)
		{
			if (nextLocation())
			{
				mAnimationState = mProfessorEntity->getAnimationState("Walk");
				mAnimationState->setLoop(true);
				mAnimationState->setEnabled(true);
			}
		}
		else // Vector3::ZERO != mDirection
		{
			Real move = mWalkSpeed * evt.timeSinceLastFrame;
			mDistance -= move;
			if (mDistance <= 0.f)
			{ // 목표 지점에 다 왔으면
				mProfessorNode->setPosition(mDestination);
				mDestination = Vector3::ZERO;
				if (!nextLocation())
				{
					mAnimationState->setEnabled(false);
					mAnimationState = mProfessorEntity->getAnimationState("Idle");
					mAnimationState->setLoop(true);
					mAnimationState->setEnabled(true);
				}
			}
			else 
			{
				mProfessorNode->translate(mDirection * move);
			}
		}
		// -------------------------------------------------------------------------
		mAnimationState->addTime(evt.timeSinceLastFrame);

		return true;
	}
void OgreCharacterController::animate(Ogre::Real elapsedTime, OGRE_ANIMATION_STATE state)
{
  Ogre::Entity * ent = getEntity();
  Ogre::AnimationState * animTop = 0;
  Ogre::AnimationState * animBase = 0;

  if(animTimer > 0) {
    if(lastTop != 0)
      lastTop->addTime(elapsedTime);
    if(lastBase != 0)
      lastBase->addTime(elapsedTime);
    animTimer -= elapsedTime;
    return;
  }
  
  switch(state)
  {
  case IDLE:
    animTop  = ent->getAnimationState("IdleTop");
    animBase = ent->getAnimationState("IdleBase");
    break;
  case RUN:
    animTop = ent->getAnimationState("RunTop");
    animBase = ent->getAnimationState("RunBase");
    break;
  case DRAWSWORDS:
    drawSwords(animTop, ent);
    animBase = lastBase;
    break;
  case SLICE:
    animTop = lastTop;
    if(swordsOut)
      slice(animTop, ent);
    animBase = lastBase;
    break;
  }

  // Disable last set of animations
  if(animTop != lastTop) {
    if(lastTop != 0)
      lastTop->setEnabled(false);
  }

  if(animBase != lastBase) {
    if(lastBase != 0)
      lastBase->setEnabled(false);
  }

  // Enable next set
  if(animTop) {
    animTop->setEnabled(true);
    animTop->setLoop(true);
    animTop->addTime(elapsedTime);
  }

  if(animBase) {
    animBase->setEnabled(true);
    animBase->setLoop(true);
    animBase->addTime(elapsedTime);
  }

  // Book keeping
  lastTop = animTop;
  lastBase = animBase;
}
示例#16
0
bool
PlayState::frameStarted
(const Ogre::FrameEvent& evt)
{
   std::cout << "frameStarted PLAY" << std::endl;

  Ogre::Vector3 vt(0,0,0);     Ogre::Real tSpeed = 20.0;  
  _deltaT = evt.timeSinceLastFrame;

  _world->stepSimulation(_deltaT); // Actualizar simulacion Bullet
  _timeLastObject -= _deltaT;

  _camera->moveRelative(vt * _deltaT * tSpeed);
  if (_camera->getPosition().length() < 10.0) {
    _camera->moveRelative(-vt * _deltaT * tSpeed);
  }

  _camera->yaw(Degree(CAM_ROTATION_SPEED * _deltaT * _mouseRotation.x)); //, Node::TS_PARENT
  _camera->pitch(Degree(CAM_ROTATION_SPEED * _deltaT * _mouseRotation.y)); //, Node::TS_LOCAL
  _mouseRotation = Vector2::ZERO;

  //CONTROLAR LA DIRECCION DE LA CAMARA DEL PROYECTIL
  _projectileCamera->lookAt(_camera->getDerivedDirection());
  
  if(_trackedBody){
    _projectileCamera->setPosition(_trackedBody->getCenterOfMassPosition());
    Ogre::Vector3 trackedBodyPosition = _trackedBody->getCenterOfMassPosition();
    Ogre::Vector3 projectileLookAt(trackedBodyPosition.x - _camera->getPosition().x, trackedBodyPosition.y - _camera->getPosition().y, trackedBodyPosition.z - _camera->getPosition().z);
    //_projectileCamera->lookAt(_camera->getDerivedDirection());
    _projectileCamera->lookAt(trackedBodyPosition + projectileLookAt);
  }
   std::cout << "CAMERAS" << std::endl;
  if(_shootKeyDown){
    _keyDownTime = _keyDownTime + _deltaT;
  }
 
  if(_keyDownTime * THROW_FORCE > 100){
    _forcePercent = 100;
  }  
  else{
    _forcePercent = _keyDownTime * THROW_FORCE;
  }

  //_points++;
  _sPF->updatePower(_forcePercent);
  _sPF->updatePoints(_points);
  //std::cout<<_sPF->getSheet()->getChild("PowerWindow")->getUpdateMode() <<std::endl;
  //_sPF->getSheet()->getChild("PowerWindow")->update(_deltaT);
  //CEGUI::System::getSingleton().injectTimePulse(_deltaT);
  //DetectCollisionPig();
   std::cout << "points power" << std::endl;
  _physicsController->detectCollision();  //Este es el bueno. Hay que cambiarlo para que compruebe colisiones sobre todo
   std::cout << "pisis" << std::endl;
  _movementController->moveAll();
  std::cout << "collision moveall" << std::endl;
  if(_finalGame){
      pushState(FinalState::getSingletonPtr());
  }
  lifeWolf();
 std::cout << "wolf" << std::endl;
  if (_lanzaranimationPig){
    for (int i = 0; i < 3; ++i){
      std::ostringstream os;
      os << "pigA" <<i; 
      Ogre::AnimationState* animStatePig = _sceneMgr->getEntity(os.str())-> getAnimationState("SaltoR");
      animStatePig->setTimePosition(0.0);
      animStatePig->setEnabled(true);
      animStatePig->setLoop(true);
      _vector_anims_pig -> push_back(animStatePig);
    }
    _lanzaranimationPig = false;
  }
  

  for (int i = 0; i < 3; ++i){
      Ogre::AnimationState* animStatePig = _vector_anims_pig->at(i);
      if (animStatePig != NULL){
        if (animStatePig->hasEnded()){
          animStatePig->setTimePosition(0.0);
          animStatePig->setEnabled(false);
        }else{
          animStatePig->addTime(_deltaT);
        }
      }
  }
   std::cout << "animation" << std::endl;
  //RecorreVectorTAOAnadirMovimientoConstante();
  //std::cout << "Hasta aqui todo bien 1" << std::endl;

  return true;
  
}
	void AnimationTask::execute(unsigned long timeDelta)
	{
		double deltaSec;
		std::list<memUInt> finishedAnimations;
		std::list<memUInt>::iterator finishedAnimationsIter;
		AnimationMapIterator iter;
		Value val;

		if (getState() != TS_RUNNING)
		{
			setState(TS_RUNNING);
		}

		// Dispatch all waiting messages of this task
		NotificationManager::getSingleton().dispatchQueuedNotifications((memUInt) this);

		deltaSec = ((double) timeDelta) / MICROSECONDS_IN_SECOND;

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, false);
			// Update animations
			for (iter = activeAnimations.begin(); iter != activeAnimations.end(); ++iter)
			{
				AnimationMapValueEntry entry = iter->second;
				Ogre::AnimationState *animationState = entry.first;

				// Check if the animation has ended, and add it to a list of animations to be removed from the active list
				if ((animationState->hasEnded()) || (!animationState->getEnabled()))
				{
					finishedAnimations.push_back(iter->first);
					animationState->setEnabled(false);

					// If the animation has a stop callback, call it
					callCallback(animationState, &mStopCallbacks);
				}
				else
				{
					// Add the time since the last update to the animation
					animationState->addTime(deltaSec);

					// Check if this animation is just starting, if it is call its start callback
					if (mStartingAnimations.erase(reinterpret_cast<memUInt>(animationState)) == 1)
					{
						callCallback(animationState, &mStartCallbacks);
					}
				}
			}
		}

		mStartingAnimations.clear();

		{
			Poco::ScopedRWLock lock(mRWLockActiveAnimations, true);
			Poco::ScopedRWLock lockCallbacks(mRWLockCallbacks, true);

			// Remove the animations that have ended from the list of active animations
			for (finishedAnimationsIter = finishedAnimations.begin(); finishedAnimationsIter != finishedAnimations.end(); ++finishedAnimationsIter)
			{
				memUInt animationAddress = *finishedAnimationsIter;
				activeAnimations.erase(animationAddress);

				// Remove any callbacks associated with this animation
				mStartCallbacks.erase(animationAddress);
				mStopCallbacks.erase(animationAddress);
			}
		}
	}
示例#18
0
    void EC_OgreAnimationController::Update(f64 frametime)
    {
        Ogre::Entity* entity = GetEntity();
        if (!entity) return;
        
        std::vector<std::string> erase_list;
        
        // Loop through all animations & update them as necessary
        for (AnimationMap::iterator i = animations_.begin(); i != animations_.end(); ++i)
        {
            Ogre::AnimationState* animstate = GetAnimationState(entity, i->first);
            if (!animstate)
                continue;
                
            switch(i->second.phase_)
            {
            case PHASE_FADEIN:
                // If period is infinitely fast, skip to full weight & PLAY status
                if (i->second.fade_period_ == 0.0f)
                {
                    i->second.weight_ = 1.0f;
                    i->second.phase_ = PHASE_PLAY;
                }   
                else
                {
                    i->second.weight_ += (1.0f / i->second.fade_period_) * frametime;
                    if (i->second.weight_ >= 1.0f)
                    {
                        i->second.weight_ = 1.0f;
                        i->second.phase_ = PHASE_PLAY;
                    }
                }
                break;

            case PHASE_PLAY:
                if (i->second.auto_stop_ || i->second.num_repeats_ != 1)
                {
                    if ((i->second.speed_factor_ >= 0.f && animstate->getTimePosition() >= animstate->getLength()) ||
                        (i->second.speed_factor_ < 0.f && animstate->getTimePosition() <= 0.f))
                    {
                        if (i->second.num_repeats_ != 1)
                        {
                            if (i->second.num_repeats_ > 1)
                                i->second.num_repeats_--;

                            Ogre::Real rewindpos = i->second.speed_factor_ >= 0.f ? (animstate->getTimePosition() - animstate->getLength()) : animstate->getLength();
                            animstate->setTimePosition(rewindpos);
                        }
                        else
                        {
                            i->second.phase_ = PHASE_FADEOUT;
                        }
                    }
                }
                break;	

            case PHASE_FADEOUT:
                // If period is infinitely fast, skip to disabled status immediately
                if (i->second.fade_period_ == 0.0f)
                {
                    i->second.weight_ = 0.0f;
                    i->second.phase_ = PHASE_STOP;
                }
                else
                {
                    i->second.weight_ -= (1.0f / i->second.fade_period_) * frametime;
                    if (i->second.weight_ <= 0.0f)
                    {
                        i->second.weight_ = 0.0f;
                        i->second.phase_ = PHASE_STOP;
                    }
                }
                break;
            }

            // Set weight & step the animation forward
            if (i->second.phase_ != PHASE_STOP)
            {
                Ogre::Real advance = i->second.speed_factor_ * frametime;
                Ogre::Real new_weight = i->second.weight_ * i->second.weight_factor_;
                
                if (new_weight != animstate->getWeight())
                    animstate->setWeight((Ogre::Real)i->second.weight_ * i->second.weight_factor_);
                if (advance != 0.0f)
                    animstate->addTime((Ogre::Real)(i->second.speed_factor_ * frametime));
                if (!animstate->getEnabled())
                    animstate->setEnabled(true);
            }
            else
            {
                // If stopped, disable & remove this animation from list
                animstate->setEnabled(false);
                erase_list.push_back(i->first);
            }
        }
        
        for (uint i = 0; i < erase_list.size(); ++i)
        {
            animations_.erase(erase_list[i]);
        }
        
        // High-priority/low-priority blending code
        if (entity->hasSkeleton())
        {
            Ogre::SkeletonInstance* skel = entity->getSkeleton();
            if (!skel)
                return;
                
		    if (highpriority_mask_.size() != skel->getNumBones())
			    highpriority_mask_.resize(skel->getNumBones());
		    if (lowpriority_mask_.size() != skel->getNumBones())
			    lowpriority_mask_.resize(skel->getNumBones());

            for (uint i = 0; i < skel->getNumBones(); ++i)
            {
                highpriority_mask_[i] = 1.0;
                lowpriority_mask_[i] = 1.0;
            }

		    // Loop through all high priority animations & update the lowpriority-blendmask based on their active tracks
            for (AnimationMap::iterator i = animations_.begin(); i != animations_.end(); ++i)
	        {
                Ogre::AnimationState* animstate = GetAnimationState(entity, i->first);
                if (!animstate)
                    continue;	        
                // Create blend mask if animstate doesn't have it yet
                if (!animstate->hasBlendMask())
                    animstate->createBlendMask(skel->getNumBones());

                if ((i->second.high_priority_) && (i->second.weight_ > 0.0))
                {
				    // High-priority animations get the full weight blend mask
                    animstate->_setBlendMaskData(&highpriority_mask_[0]);
                    if (!skel->hasAnimation(animstate->getAnimationName()))
                        continue;
                        
                    Ogre::Animation* anim = skel->getAnimation(animstate->getAnimationName());
                    
                    Ogre::Animation::NodeTrackIterator it = anim->getNodeTrackIterator();
                    while (it.hasMoreElements())
                    {
					    Ogre::NodeAnimationTrack* track = it.getNext();
					    unsigned id = track->getHandle();
					    // For each active track, reduce corresponding bone weight in lowpriority-blendmask 
					    // by this animation's weight
					    if (id < lowpriority_mask_.size())
					    {
						    lowpriority_mask_[id] -= i->second.weight_;
						    if (lowpriority_mask_[id] < 0.0) lowpriority_mask_[id] = 0.0;
					    }
			        }
                }
            }

		    // Now set the calculated blendmask on low-priority animations
            for (AnimationMap::iterator i = animations_.begin(); i != animations_.end(); ++i)
	        {
                Ogre::AnimationState* animstate = GetAnimationState(entity, i->first);
                if (!animstate)
                    continue;	
                if (i->second.high_priority_ == false)	        
                    animstate->_setBlendMaskData(&lowpriority_mask_[0]);			    			   
		    }
        }
    }