Implement NPC eye blinking (Fixes #1721)

deque
scrawl 11 years ago
parent 598c0c4ae7
commit 625f9a35e6

@ -67,19 +67,45 @@ namespace MWRender
{
HeadAnimationTime::HeadAnimationTime(MWWorld::Ptr reference)
: mReference(reference), mTalkStart(0), mTalkStop(0), mBlinkStart(0), mBlinkStop(0)
: mReference(reference), mTalkStart(0), mTalkStop(0), mBlinkStart(0), mBlinkStop(0), mValue(0)
{
resetBlinkTimer();
}
float HeadAnimationTime::getValue() const
void HeadAnimationTime::resetBlinkTimer()
{
mBlinkTimer = -(2 + (std::rand() / double(RAND_MAX*1.0)) * 6);
}
void HeadAnimationTime::update(float dt)
{
// TODO: Handle eye blinking
if (MWBase::Environment::get().getSoundManager()->sayDone(mReference))
return mBlinkStop;
{
mBlinkTimer += dt;
float duration = mBlinkStop - mBlinkStart;
if (mBlinkTimer >= 0 && mBlinkTimer <= duration)
{
mValue = mBlinkStart + mBlinkTimer;
}
else
mValue = mBlinkStop;
if (mBlinkTimer > duration)
resetBlinkTimer();
}
else
return mTalkStart +
{
mValue = mTalkStart +
(mTalkStop - mTalkStart) *
std::min(1.f, MWBase::Environment::get().getSoundManager()->getSaySoundLoudness(mReference)*4); // Rescale a bit (most voices are not very loud)
}
}
float HeadAnimationTime::getValue() const
{
return mValue;
}
void HeadAnimationTime::setTalkStart(float value)
@ -541,6 +567,8 @@ Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
{
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
mHeadAnimationTime->update(timepassed);
Ogre::SkeletonInstance *baseinst = mSkelBase->getSkeleton();
if(mViewMode == VM_FirstPerson)
{

@ -23,9 +23,17 @@ private:
float mTalkStop;
float mBlinkStart;
float mBlinkStop;
float mBlinkTimer;
float mValue;
private:
void resetBlinkTimer();
public:
HeadAnimationTime(MWWorld::Ptr reference);
void update(float dt);
void setTalkStart(float value);
void setTalkStop(float value);
void setBlinkStart(float value);

Loading…
Cancel
Save