mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
Scale animation speed using the direction length
The direction length doesn't currently give a good speed, but it's something.
This commit is contained in:
parent
aecfc0829a
commit
0b68953f0d
4 changed files with 21 additions and 12 deletions
|
@ -118,6 +118,17 @@ void CharacterController::markerEvent(float time, const std::string &evt)
|
|||
}
|
||||
|
||||
|
||||
void CharacterController::setDirection(const Ogre::Vector3 &dir)
|
||||
{
|
||||
// HACK: The direction length we get is too large.
|
||||
float mult = dir.length() / 32.0f;
|
||||
mult = std::max(1.0f, mult);
|
||||
if(mAnimation)
|
||||
mAnimation->setSpeedMult(mult);
|
||||
mDirection = dir.normalisedCopy();
|
||||
}
|
||||
|
||||
|
||||
Ogre::Vector3 CharacterController::update(float duration)
|
||||
{
|
||||
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||
|
@ -125,17 +136,10 @@ Ogre::Vector3 CharacterController::update(float duration)
|
|||
movement += mAnimation->runAnimation(duration);
|
||||
mSkipAnim = false;
|
||||
|
||||
if(getState() == CharState_SpecialIdle || getState() == CharState_Idle ||
|
||||
getState() == CharState_Dead)
|
||||
if(!(getState() == CharState_SpecialIdle || getState() == CharState_Idle ||
|
||||
getState() == CharState_Dead))
|
||||
{
|
||||
// FIXME: mDirection shouldn't influence the movement here.
|
||||
movement += mDirection;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: mDirection should be normalized after setting the speed of
|
||||
// the animation in setDirection, rather than here.
|
||||
movement = mDirection.normalisedCopy() * movement.length();
|
||||
movement = mDirection * movement.length();
|
||||
}
|
||||
|
||||
return movement;
|
||||
|
|
|
@ -54,8 +54,7 @@ public:
|
|||
void playGroup(const std::string &groupname, int mode, int count);
|
||||
void skipAnim();
|
||||
|
||||
void setDirection(const Ogre::Vector3 &dir)
|
||||
{ mDirection = dir; }
|
||||
void setDirection(const Ogre::Vector3 &dir);
|
||||
|
||||
void setState(CharacterState state);
|
||||
CharacterState getState() const
|
||||
|
|
|
@ -26,6 +26,7 @@ Animation::Animation(const MWWorld::Ptr &ptr)
|
|||
, mLastPosition(0.0f)
|
||||
, mCurrentKeys(NULL)
|
||||
, mAnimState(NULL)
|
||||
, mAnimSpeedMult(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -207,6 +208,7 @@ void Animation::play(const std::string &groupname, const std::string &start)
|
|||
Ogre::Vector3 Animation::runAnimation(float timepassed)
|
||||
{
|
||||
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||
timepassed *= mAnimSpeedMult;
|
||||
while(mAnimState && timepassed > 0.0f)
|
||||
{
|
||||
float targetTime = mAnimState->getTimePosition() + timepassed;
|
||||
|
|
|
@ -31,6 +31,7 @@ protected:
|
|||
NifOgre::TextKeyMap *mCurrentKeys;
|
||||
NifOgre::TextKeyMap::const_iterator mNextKey;
|
||||
Ogre::AnimationState *mAnimState;
|
||||
float mAnimSpeedMult;
|
||||
|
||||
/* Updates the animation to the specified time, and returns the movement
|
||||
* vector since the last update or reset. */
|
||||
|
@ -54,6 +55,9 @@ public:
|
|||
// should be on the scale of 0 to 1.
|
||||
void setAccumulation(const Ogre::Vector3 &accum);
|
||||
|
||||
void setSpeedMult(float speedmult)
|
||||
{ mAnimSpeedMult = speedmult; }
|
||||
|
||||
void play(const std::string &groupname, const std::string &start);
|
||||
virtual Ogre::Vector3 runAnimation(float timepassed);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue