mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +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
@ -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 CharacterController::update(float duration)
|
||||||
{
|
{
|
||||||
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||||
@ -125,17 +136,10 @@ Ogre::Vector3 CharacterController::update(float duration)
|
|||||||
movement += mAnimation->runAnimation(duration);
|
movement += mAnimation->runAnimation(duration);
|
||||||
mSkipAnim = false;
|
mSkipAnim = false;
|
||||||
|
|
||||||
if(getState() == CharState_SpecialIdle || getState() == CharState_Idle ||
|
if(!(getState() == CharState_SpecialIdle || getState() == CharState_Idle ||
|
||||||
getState() == CharState_Dead)
|
getState() == CharState_Dead))
|
||||||
{
|
{
|
||||||
// FIXME: mDirection shouldn't influence the movement here.
|
movement = mDirection * movement.length();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return movement;
|
return movement;
|
||||||
|
@ -54,8 +54,7 @@ public:
|
|||||||
void playGroup(const std::string &groupname, int mode, int count);
|
void playGroup(const std::string &groupname, int mode, int count);
|
||||||
void skipAnim();
|
void skipAnim();
|
||||||
|
|
||||||
void setDirection(const Ogre::Vector3 &dir)
|
void setDirection(const Ogre::Vector3 &dir);
|
||||||
{ mDirection = dir; }
|
|
||||||
|
|
||||||
void setState(CharacterState state);
|
void setState(CharacterState state);
|
||||||
CharacterState getState() const
|
CharacterState getState() const
|
||||||
|
@ -26,6 +26,7 @@ Animation::Animation(const MWWorld::Ptr &ptr)
|
|||||||
, mLastPosition(0.0f)
|
, mLastPosition(0.0f)
|
||||||
, mCurrentKeys(NULL)
|
, mCurrentKeys(NULL)
|
||||||
, mAnimState(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 Animation::runAnimation(float timepassed)
|
||||||
{
|
{
|
||||||
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
Ogre::Vector3 movement = Ogre::Vector3::ZERO;
|
||||||
|
timepassed *= mAnimSpeedMult;
|
||||||
while(mAnimState && timepassed > 0.0f)
|
while(mAnimState && timepassed > 0.0f)
|
||||||
{
|
{
|
||||||
float targetTime = mAnimState->getTimePosition() + timepassed;
|
float targetTime = mAnimState->getTimePosition() + timepassed;
|
||||||
|
@ -31,6 +31,7 @@ protected:
|
|||||||
NifOgre::TextKeyMap *mCurrentKeys;
|
NifOgre::TextKeyMap *mCurrentKeys;
|
||||||
NifOgre::TextKeyMap::const_iterator mNextKey;
|
NifOgre::TextKeyMap::const_iterator mNextKey;
|
||||||
Ogre::AnimationState *mAnimState;
|
Ogre::AnimationState *mAnimState;
|
||||||
|
float mAnimSpeedMult;
|
||||||
|
|
||||||
/* Updates the animation to the specified time, and returns the movement
|
/* Updates the animation to the specified time, and returns the movement
|
||||||
* vector since the last update or reset. */
|
* vector since the last update or reset. */
|
||||||
@ -54,6 +55,9 @@ 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)
|
||||||
|
{ mAnimSpeedMult = speedmult; }
|
||||||
|
|
||||||
void play(const std::string &groupname, const std::string &start);
|
void play(const std::string &groupname, const std::string &start);
|
||||||
virtual Ogre::Vector3 runAnimation(float timepassed);
|
virtual Ogre::Vector3 runAnimation(float timepassed);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user