forked from mirror/openmw-tes3mp
Implement NPC eye blinking (Fixes #1721)
This commit is contained in:
parent
598c0c4ae7
commit
625f9a35e6
2 changed files with 44 additions and 8 deletions
|
@ -67,19 +67,45 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
HeadAnimationTime::HeadAnimationTime(MWWorld::Ptr reference)
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeadAnimationTime::resetBlinkTimer()
|
||||||
|
{
|
||||||
|
mBlinkTimer = -(2 + (std::rand() / double(RAND_MAX*1.0)) * 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeadAnimationTime::update(float dt)
|
||||||
|
{
|
||||||
|
if (MWBase::Environment::get().getSoundManager()->sayDone(mReference))
|
||||||
|
{
|
||||||
|
mBlinkTimer += dt;
|
||||||
|
|
||||||
|
float duration = mBlinkStop - mBlinkStart;
|
||||||
|
|
||||||
|
if (mBlinkTimer >= 0 && mBlinkTimer <= duration)
|
||||||
|
{
|
||||||
|
mValue = mBlinkStart + mBlinkTimer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mValue = mBlinkStop;
|
||||||
|
|
||||||
|
if (mBlinkTimer > duration)
|
||||||
|
resetBlinkTimer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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
|
float HeadAnimationTime::getValue() const
|
||||||
{
|
{
|
||||||
// TODO: Handle eye blinking
|
return mValue;
|
||||||
if (MWBase::Environment::get().getSoundManager()->sayDone(mReference))
|
|
||||||
return mBlinkStop;
|
|
||||||
else
|
|
||||||
return mTalkStart +
|
|
||||||
(mTalkStop - mTalkStart) *
|
|
||||||
std::min(1.f, MWBase::Environment::get().getSoundManager()->getSaySoundLoudness(mReference)*4); // Rescale a bit (most voices are not very loud)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadAnimationTime::setTalkStart(float value)
|
void HeadAnimationTime::setTalkStart(float value)
|
||||||
|
@ -541,6 +567,8 @@ Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
|
||||||
{
|
{
|
||||||
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
|
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
|
||||||
|
|
||||||
|
mHeadAnimationTime->update(timepassed);
|
||||||
|
|
||||||
Ogre::SkeletonInstance *baseinst = mSkelBase->getSkeleton();
|
Ogre::SkeletonInstance *baseinst = mSkelBase->getSkeleton();
|
||||||
if(mViewMode == VM_FirstPerson)
|
if(mViewMode == VM_FirstPerson)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,9 +23,17 @@ private:
|
||||||
float mTalkStop;
|
float mTalkStop;
|
||||||
float mBlinkStart;
|
float mBlinkStart;
|
||||||
float mBlinkStop;
|
float mBlinkStop;
|
||||||
|
|
||||||
|
float mBlinkTimer;
|
||||||
|
|
||||||
|
float mValue;
|
||||||
|
private:
|
||||||
|
void resetBlinkTimer();
|
||||||
public:
|
public:
|
||||||
HeadAnimationTime(MWWorld::Ptr reference);
|
HeadAnimationTime(MWWorld::Ptr reference);
|
||||||
|
|
||||||
|
void update(float dt);
|
||||||
|
|
||||||
void setTalkStart(float value);
|
void setTalkStart(float value);
|
||||||
void setTalkStop(float value);
|
void setTalkStop(float value);
|
||||||
void setBlinkStart(float value);
|
void setBlinkStart(float value);
|
||||||
|
|
Loading…
Reference in a new issue