1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 10:53:54 +00:00

Specify the text key to reset animations to

This commit is contained in:
Chris Robinson 2013-01-22 00:31:45 -08:00
parent d836b3d0ff
commit 05f8b8c283
2 changed files with 17 additions and 34 deletions

View file

@ -134,14 +134,20 @@ Ogre::Vector3 Animation::updatePosition(float time)
return posdiff;
}
void Animation::resetPosition(float time)
void Animation::reset(const std::string &marker)
{
mAnimState->setTimePosition(time);
mNextKey = mCurrentKeys->begin();
while(mNextKey != mCurrentKeys->end() && mNextKey->first < time)
while(mNextKey != mCurrentKeys->end() && mNextKey->second != marker)
mNextKey++;
if(mNextKey != mCurrentKeys->end())
mAnimState->setTimePosition(mNextKey->first);
else
{
mNextKey = mCurrentKeys->begin();
mAnimState->setTimePosition(0.0f);
}
if(mNonAccumRoot)
{
mEntityList.mSkelBase->getSkeleton()->setAnimationState(*mAnimState->getParent());
@ -151,29 +157,6 @@ void Animation::resetPosition(float time)
}
float Animation::findStart(const std::string &groupname, const std::string &start)
{
mNextKey = mCurrentKeys->end();
if(mCurrentKeys->size() == 0)
return 0.0f;
if(groupname == "all")
{
mNextKey = mCurrentKeys->begin();
return 0.0f;
}
std::string startmarker = groupname+": "+start;
NifOgre::TextKeyMap::const_iterator iter;
for(iter = mCurrentKeys->begin();iter != mCurrentKeys->end();iter++)
{
if(iter->second == startmarker)
return iter->first;
}
return 0.0f;
}
void Animation::play(const std::string &groupname, const std::string &start, bool loop)
{
try {
@ -181,10 +164,10 @@ void Animation::play(const std::string &groupname, const std::string &start, boo
mAnimState->setEnabled(false);
mAnimState = mEntityList.mSkelBase->getAnimationState(groupname);
mAnimState->setEnabled(true);
mCurrentKeys = &mTextKeys[groupname];
mLooping = loop;
resetPosition(findStart(groupname, start));
reset(start);
}
catch(std::exception &e) {
std::cerr<< e.what() <<std::endl;
@ -220,7 +203,7 @@ Ogre::Vector3 Animation::runAnimation(float timepassed)
{
if(mLooping)
{
resetPosition(findStart(mAnimState->getAnimationName(), "loop start"));
reset("loop start");
if(mAnimState->getTimePosition() >= time)
break;
}
@ -230,7 +213,7 @@ Ogre::Vector3 Animation::runAnimation(float timepassed)
{
if(mLooping)
{
resetPosition(findStart(mAnimState->getAnimationName(), "loop start"));
reset("loop start");
if(mAnimState->getTimePosition() >= time)
break;
}

View file

@ -38,10 +38,10 @@ protected:
/* Updates the animation to the specified time, and returns the movement
* vector since the last update or reset. */
Ogre::Vector3 updatePosition(float time);
/* Updates the animation to the specified time, without moving anything. */
void resetPosition(float time);
float findStart(const std::string &groupname, const std::string &start);
/* Resets the animation to the time of the specified marker, without moving
* anything. If the marker is not found, it resets to the beginning. */
void reset(const std::string &marker);
void createEntityList(Ogre::SceneNode *node, const std::string &model);