#include "animation.hpp" #include #include #include #include #include #include namespace MWRender { std::map Animation::sUniqueIDs; Animation::Animation(OEngine::Render::OgreRenderer& _rend) : mInsert(NULL) , mRend(_rend) , mTime(0.0f) , mAnimate(0) , mSkipFrame(false) { } Animation::~Animation() { Ogre::SceneManager *sceneMgr = mInsert->getCreator(); for(size_t i = 0;i < mEntityList.mEntities.size();i++) sceneMgr->destroyEntity(mEntityList.mEntities[i]); mEntityList.mEntities.clear(); } void Animation::playGroup(std::string groupname, int mode, int loops) { if(groupname == "all") { mAnimate = loops; mTime = 0.0f; } } void Animation::skipAnim() { mSkipFrame = true; } void Animation::runAnimation(float timepassed) { if(mAnimate != 0 && !mSkipFrame) { mTime += timepassed; if(mEntityList.mSkelBase) { Ogre::AnimationStateSet *aset = mEntityList.mSkelBase->getAllAnimationStates(); Ogre::AnimationStateIterator as = aset->getAnimationStateIterator(); while(as.hasMoreElements()) { Ogre::AnimationState *state = as.getNext(); state->setTimePosition(mTime); if(mTime >= state->getLength()) { if(mAnimate != -1) mAnimate--; //std::cout << "Stopping the animation\n"; if(mAnimate == 0) mTime = state->getLength(); else mTime = mTime - state->getLength(); } } } } mSkipFrame = false; } }