mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 05:45:33 +00:00
Don't explicitly track the last position
This commit is contained in:
parent
7c3b014193
commit
5a9c1e1245
2 changed files with 10 additions and 24 deletions
|
@ -51,7 +51,6 @@ Animation::Animation(const MWWorld::Ptr &ptr)
|
||||||
, mNonAccumRoot(NULL)
|
, mNonAccumRoot(NULL)
|
||||||
, mNonAccumCtrl(NULL)
|
, mNonAccumCtrl(NULL)
|
||||||
, mAccumulate(0.0f)
|
, mAccumulate(0.0f)
|
||||||
, mLastPosition(0.0f)
|
|
||||||
, mAnimVelocity(0.0f)
|
, mAnimVelocity(0.0f)
|
||||||
, mAnimSpeedMult(1.0f)
|
, mAnimSpeedMult(1.0f)
|
||||||
{
|
{
|
||||||
|
@ -221,7 +220,6 @@ void Animation::clearAnimSources()
|
||||||
mNonAccumCtrl = NULL;
|
mNonAccumCtrl = NULL;
|
||||||
mAnimVelocity = 0.0f;
|
mAnimVelocity = 0.0f;
|
||||||
|
|
||||||
mLastPosition = Ogre::Vector3(0.0f);
|
|
||||||
mAccumRoot = NULL;
|
mAccumRoot = NULL;
|
||||||
mNonAccumRoot = NULL;
|
mNonAccumRoot = NULL;
|
||||||
|
|
||||||
|
@ -357,19 +355,16 @@ void Animation::updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Og
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Animation::updatePosition(float time, Ogre::Vector3 &position)
|
void Animation::updatePosition(float oldtime, float newtime, Ogre::Vector3 &position)
|
||||||
{
|
{
|
||||||
Ogre::Vector3 posdiff;
|
|
||||||
|
|
||||||
/* Get the non-accumulation root's difference from the last update, and move the position
|
/* Get the non-accumulation root's difference from the last update, and move the position
|
||||||
* accordingly.
|
* accordingly.
|
||||||
*/
|
*/
|
||||||
posdiff = (mNonAccumCtrl->getTranslation(time) - mLastPosition) * mAccumulate;
|
Ogre::Vector3 off = mNonAccumCtrl->getTranslation(newtime)*mAccumulate;
|
||||||
position += posdiff;
|
position += off - mNonAccumCtrl->getTranslation(oldtime)*mAccumulate;
|
||||||
|
|
||||||
/* Translate the accumulation root back to compensate for the move. */
|
/* Translate the accumulation root back to compensate for the move. */
|
||||||
mLastPosition += posdiff;
|
mAccumRoot->setPosition(-off);
|
||||||
mAccumRoot->setPosition(-mLastPosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint)
|
bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint)
|
||||||
|
@ -471,11 +466,6 @@ bool Animation::handleTextKey(AnimState &state, const std::string &groupname, co
|
||||||
if(state.mTime >= time)
|
if(state.mTime >= time)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ugly
|
|
||||||
if(mNonAccumCtrl && groupname == mAnimationValuePtr[0]->getAnimName())
|
|
||||||
mLastPosition = mNonAccumCtrl->getTranslation(state.mTime) * mAccumulate;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,7 +536,6 @@ bool Animation::resetActiveGroups()
|
||||||
|
|
||||||
mNonAccumCtrl = NULL;
|
mNonAccumCtrl = NULL;
|
||||||
mAnimVelocity = 0.0f;
|
mAnimVelocity = 0.0f;
|
||||||
mLastPosition = Ogre::Vector3(0.0f);
|
|
||||||
|
|
||||||
if(!mNonAccumRoot || mAccumulate == Ogre::Vector3(0.0f))
|
if(!mNonAccumRoot || mAccumulate == Ogre::Vector3(0.0f))
|
||||||
return false;
|
return false;
|
||||||
|
@ -568,8 +557,6 @@ bool Animation::resetActiveGroups()
|
||||||
mAnimVelocity = calcAnimVelocity(keys, dstval, mAccumulate, state->first);
|
mAnimVelocity = calcAnimVelocity(keys, dstval, mAccumulate, state->first);
|
||||||
ismoving = (mAnimVelocity > 1.0f);
|
ismoving = (mAnimVelocity > 1.0f);
|
||||||
|
|
||||||
mLastPosition = dstval->getTranslation(state->second.mTime) * mAccumulate;
|
|
||||||
|
|
||||||
mNonAccumCtrl = dstval;
|
mNonAccumCtrl = dstval;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -613,16 +600,16 @@ Ogre::Vector3 Animation::runAnimation(float duration)
|
||||||
float targetTime = state.mTime + timepassed;
|
float targetTime = state.mTime + timepassed;
|
||||||
if(state.mNextKey->first > targetTime)
|
if(state.mNextKey->first > targetTime)
|
||||||
{
|
{
|
||||||
state.mTime = targetTime;
|
|
||||||
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
||||||
updatePosition(state.mTime, movement);
|
updatePosition(state.mTime, targetTime, movement);
|
||||||
|
state.mTime = targetTime;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NifOgre::TextKeyMap::const_iterator key(state.mNextKey++);
|
NifOgre::TextKeyMap::const_iterator key(state.mNextKey++);
|
||||||
state.mTime = key->first;
|
|
||||||
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
if(mNonAccumCtrl && stateiter->first == mAnimationValuePtr[0]->getAnimName())
|
||||||
updatePosition(state.mTime, movement);
|
updatePosition(state.mTime, key->first, movement);
|
||||||
|
state.mTime = key->first;
|
||||||
|
|
||||||
state.mPlaying = (key != state.mStopKey);
|
state.mPlaying = (key != state.mStopKey);
|
||||||
timepassed = targetTime - state.mTime;
|
timepassed = targetTime - state.mTime;
|
||||||
|
|
|
@ -80,7 +80,6 @@ protected:
|
||||||
Ogre::Node *mNonAccumRoot;
|
Ogre::Node *mNonAccumRoot;
|
||||||
NifOgre::NodeTargetValue<Ogre::Real> *mNonAccumCtrl;
|
NifOgre::NodeTargetValue<Ogre::Real> *mNonAccumCtrl;
|
||||||
Ogre::Vector3 mAccumulate;
|
Ogre::Vector3 mAccumulate;
|
||||||
Ogre::Vector3 mLastPosition;
|
|
||||||
|
|
||||||
float mAnimVelocity;
|
float mAnimVelocity;
|
||||||
float mAnimSpeedMult;
|
float mAnimSpeedMult;
|
||||||
|
@ -106,8 +105,8 @@ protected:
|
||||||
void updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel);
|
void updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel);
|
||||||
|
|
||||||
/* Updates the position of the accum root node for the given time, and
|
/* Updates the position of the accum root node for the given time, and
|
||||||
* returns the wanted movement vector from the previous update. */
|
* returns the wanted movement vector from the previous time. */
|
||||||
void updatePosition(float time, Ogre::Vector3 &position);
|
void updatePosition(float oldtime, float newtime, Ogre::Vector3 &position);
|
||||||
|
|
||||||
static NifOgre::TextKeyMap::const_iterator findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname);
|
static NifOgre::TextKeyMap::const_iterator findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue