void PlayerCharacter::updateAnimations(Ogre::Real deltaTime) { Ogre::Real baseAnimSpeed = 2.5f; mTimer += deltaTime; // increment the current base and top animation times if (mBaseAnimID != ANIM_NONE) mAnims[mBaseAnimID]->addTime(deltaTime * baseAnimSpeed); // apply smooth transitioning between our animations fadeAnimations(deltaTime); }
//------------------------------------------------------------------------------------- void EntityComplex::updateAnimations(Real deltaTime) { Real baseAnimSpeed = 1; Real topAnimSpeed = 1; mTimer += deltaTime; if (mTopAnimID == ANIM_DRAW_SWORDS) { // flip the draw swords animation if we need to put it back topAnimSpeed = mSwordsDrawn ? -1 : 1; // half-way through the animation is when the hand grasps the handles... if (mTimer >= mAnims[mTopAnimID]->getLength() / 2 && mTimer - deltaTime < mAnims[mTopAnimID]->getLength() / 2) { // so transfer the swords from the sheaths to the hands mBodyEnt->detachAllObjectsFromBone(); mBodyEnt->attachObjectToBone(mSwordsDrawn ? "Sheath.L" : "Handle.L", mSword1); mBodyEnt->attachObjectToBone(mSwordsDrawn ? "Sheath.R" : "Handle.R", mSword2); // change the hand state to grab or let go mAnims[ANIM_HANDS_CLOSED]->setEnabled(!mSwordsDrawn); mAnims[ANIM_HANDS_RELAXED]->setEnabled(mSwordsDrawn); // toggle sword trails if (mSwordsDrawn) { mSwordTrail->setVisible(false); mSwordTrail->removeNode(mSword1->getParentNode()); mSwordTrail->removeNode(mSword2->getParentNode()); if(pWeaponTrailRight_) pWeaponTrailRight_->setActive(false); if(pWeaponTrailLeft_) pWeaponTrailLeft_->setActive(false); } else { mSwordTrail->setVisible(true); mSwordTrail->addNode(mSword1->getParentNode()); mSwordTrail->addNode(mSword2->getParentNode()); if(pWeaponTrailRight_) pWeaponTrailRight_->setActive(true); if(pWeaponTrailLeft_) pWeaponTrailLeft_->setActive(true); } } if (mTimer >= mAnims[mTopAnimID]->getLength()) { // animation is finished, so return to what we were doing before if (mBaseAnimID == ANIM_IDLE_BASE) setTopAnimation(ANIM_IDLE_TOP); else { setTopAnimation(ANIM_RUN_TOP); mAnims[ANIM_RUN_TOP]->setTimePosition(mAnims[ANIM_RUN_BASE]->getTimePosition()); } mSwordsDrawn = !mSwordsDrawn; } } else if (mTopAnimID == ANIM_SLICE_VERTICAL || mTopAnimID == ANIM_SLICE_HORIZONTAL) { if (mTimer >= mAnims[mTopAnimID]->getLength()) { // animation is finished, so return to what we were doing before if (mBaseAnimID == ANIM_IDLE_BASE) setTopAnimation(ANIM_IDLE_TOP); else { setTopAnimation(ANIM_RUN_TOP); mAnims[ANIM_RUN_TOP]->setTimePosition(mAnims[ANIM_RUN_BASE]->getTimePosition()); } } // don't sway hips from side to side when slicing. that's just embarrassing. if (mBaseAnimID == ANIM_IDLE_BASE) baseAnimSpeed = 0; } else if (mBaseAnimID == ANIM_JUMP_START) { if (mTimer >= mAnims[mBaseAnimID]->getLength()) { mIsJump = true; // takeoff animation finished, so time to leave the ground! setBaseAnimation(ANIM_JUMP_LOOP, true); // apply a jump acceleration to the character mVerticalVelocity = JUMP_ACCEL * mScale; } } else if (mBaseAnimID == ANIM_JUMP_END) { if (mTimer >= mAnims[mBaseAnimID]->getLength()) { mIsJump = false; // safely landed, so go back to running or idling if (mKeyDirection == Vector3::ZERO) { setBaseAnimation(ANIM_IDLE_BASE); setTopAnimation(ANIM_IDLE_TOP); } else { setBaseAnimation(ANIM_RUN_BASE, true); setTopAnimation(ANIM_RUN_TOP, true); } } } // increment the current base and top animation times if (mBaseAnimID != ANIM_NONE) mAnims[mBaseAnimID]->addTime(deltaTime * baseAnimSpeed); if (mTopAnimID != ANIM_NONE) mAnims[mTopAnimID]->addTime(deltaTime * topAnimSpeed); // apply smooth transitioning between our animations fadeAnimations(deltaTime); }