forked from mirror/openmw-tes3mp
Scale the animation speed based on the animation velocity and movement speed
This may not be totoally correct since it takes the whole animation into account, rather than just the looping portion. But it's good enough for now.
This commit is contained in:
parent
e1a1530774
commit
ff0099fa6e
3 changed files with 37 additions and 5 deletions
|
@ -172,6 +172,7 @@ Ogre::Vector3 CharacterController::update(float duration)
|
||||||
{
|
{
|
||||||
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
||||||
const Ogre::Vector3 &vec = cls.getMovementVector(mPtr);
|
const Ogre::Vector3 &vec = cls.getMovementVector(mPtr);
|
||||||
|
const float speed = cls.getSpeed(mPtr);
|
||||||
|
|
||||||
bool inwater = MWBase::Environment::get().getWorld()->isSwimming(mPtr);
|
bool inwater = MWBase::Environment::get().getWorld()->isSwimming(mPtr);
|
||||||
bool isrunning = cls.getStance(mPtr, MWWorld::Class::Run);
|
bool isrunning = cls.getStance(mPtr, MWWorld::Class::Run);
|
||||||
|
@ -204,9 +205,7 @@ Ogre::Vector3 CharacterController::update(float duration)
|
||||||
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||||
if(mAnimation && !mSkipAnim)
|
if(mAnimation && !mSkipAnim)
|
||||||
{
|
{
|
||||||
// FIXME: The speed should actually be determined by the character's
|
mAnimation->setSpeed(speed);
|
||||||
// stance (running, sneaking, etc) and stats
|
|
||||||
mAnimation->setSpeedMult(1.0f);
|
|
||||||
movement += mAnimation->runAnimation(duration);
|
movement += mAnimation->runAnimation(duration);
|
||||||
}
|
}
|
||||||
mSkipAnim = false;
|
mSkipAnim = false;
|
||||||
|
|
|
@ -28,6 +28,7 @@ Animation::Animation(const MWWorld::Ptr &ptr)
|
||||||
, mCurrentTime(0.0f)
|
, mCurrentTime(0.0f)
|
||||||
, mPlaying(false)
|
, mPlaying(false)
|
||||||
, mLooping(false)
|
, mLooping(false)
|
||||||
|
, mAnimVelocity(0.0f)
|
||||||
, mAnimSpeedMult(1.0f)
|
, mAnimSpeedMult(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -161,6 +162,13 @@ void Animation::setAccumulation(const Ogre::Vector3 &accum)
|
||||||
mAccumulate = accum;
|
mAccumulate = accum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::setSpeed(float speed)
|
||||||
|
{
|
||||||
|
mAnimSpeedMult = 1.0f;
|
||||||
|
if(mAnimVelocity > 1.0f && speed > 0.0f)
|
||||||
|
mAnimSpeedMult = speed / mAnimVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Animation::applyAnimation(const Ogre::Animation *anim, float time, Ogre::SkeletonInstance *skel)
|
void Animation::applyAnimation(const Ogre::Animation *anim, float time, Ogre::SkeletonInstance *skel)
|
||||||
{
|
{
|
||||||
|
@ -255,6 +263,31 @@ void Animation::play(const std::string &groupname, const std::string &start, boo
|
||||||
{
|
{
|
||||||
mCurrentAnim = (*iter)->getAnimation(groupname);
|
mCurrentAnim = (*iter)->getAnimation(groupname);
|
||||||
mCurrentKeys = &mTextKeys[groupname];
|
mCurrentKeys = &mTextKeys[groupname];
|
||||||
|
mAnimVelocity = 0.0f;
|
||||||
|
|
||||||
|
if(mNonAccumRoot)
|
||||||
|
{
|
||||||
|
const Ogre::NodeAnimationTrack *track = 0;
|
||||||
|
|
||||||
|
Ogre::Animation::NodeTrackIterator trackiter = mCurrentAnim->getNodeTrackIterator();
|
||||||
|
while(!track && trackiter.hasMoreElements())
|
||||||
|
{
|
||||||
|
const Ogre::NodeAnimationTrack *cur = trackiter.getNext();
|
||||||
|
if(cur->getAssociatedNode()->getName() == mNonAccumRoot->getName())
|
||||||
|
track = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(track && track->getNumKeyFrames() > 1)
|
||||||
|
{
|
||||||
|
const Ogre::TransformKeyFrame *startkf, *endkf;
|
||||||
|
startkf = static_cast<const Ogre::TransformKeyFrame*>(track->getKeyFrame(0));
|
||||||
|
endkf = static_cast<const Ogre::TransformKeyFrame*>(track->getKeyFrame(track->getNumKeyFrames() - 1));
|
||||||
|
|
||||||
|
mAnimVelocity = startkf->getTranslate().distance(endkf->getTranslate()) /
|
||||||
|
mCurrentAnim->getLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ protected:
|
||||||
bool mPlaying;
|
bool mPlaying;
|
||||||
bool mLooping;
|
bool mLooping;
|
||||||
|
|
||||||
|
float mAnimVelocity;
|
||||||
float mAnimSpeedMult;
|
float mAnimSpeedMult;
|
||||||
|
|
||||||
/* Applies the given animation to the given skeleton instance, using the specified time. */
|
/* Applies the given animation to the given skeleton instance, using the specified time. */
|
||||||
|
@ -73,8 +74,7 @@ public:
|
||||||
// should be on the scale of 0 to 1.
|
// should be on the scale of 0 to 1.
|
||||||
void setAccumulation(const Ogre::Vector3 &accum);
|
void setAccumulation(const Ogre::Vector3 &accum);
|
||||||
|
|
||||||
void setSpeedMult(float speedmult)
|
void setSpeed(float speed);
|
||||||
{ mAnimSpeedMult = speedmult; }
|
|
||||||
|
|
||||||
void play(const std::string &groupname, const std::string &start, bool loop);
|
void play(const std::string &groupname, const std::string &start, bool loop);
|
||||||
virtual Ogre::Vector3 runAnimation(float timepassed);
|
virtual Ogre::Vector3 runAnimation(float timepassed);
|
||||||
|
|
Loading…
Reference in a new issue