1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-06 11:45:35 +00:00

Adjust the FirstPersonNeckController to follow the camera with a reduced factor (Fixes #1784)

This commit is contained in:
scrawl 2015-11-10 01:01:41 +01:00
parent 3c338b9da9
commit 637cd3a628
4 changed files with 26 additions and 2 deletions

View file

@ -1479,6 +1479,8 @@ bool CharacterController::updateWeaponState()
} }
} }
mAnimation->setAccurateAiming(mUpperBodyState > UpperCharState_WeapEquiped);
return forcestateupdate; return forcestateupdate;
} }

View file

@ -439,6 +439,7 @@ public:
virtual void setHeadYaw(float yawRadians); virtual void setHeadYaw(float yawRadians);
virtual float getHeadPitch() const; virtual float getHeadPitch() const;
virtual float getHeadYaw() const; virtual float getHeadYaw() const;
virtual void setAccurateAiming(bool enabled) {}
private: private:
Animation(const Animation&); Animation(const Animation&);

View file

@ -281,7 +281,9 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> par
mShowWeapons(false), mShowWeapons(false),
mShowCarriedLeft(true), mShowCarriedLeft(true),
mNpcType(Type_Normal), mNpcType(Type_Normal),
mSoundsDisabled(disableSounds) mSoundsDisabled(disableSounds),
mAccurateAiming(false),
mAimingFactor(0.f)
{ {
mNpc = mPtr.get<ESM::NPC>()->mBase; mNpc = mPtr.get<ESM::NPC>()->mBase;
@ -726,7 +728,14 @@ osg::Vec3f NpcAnimation::runAnimation(float timepassed)
if (mFirstPersonNeckController) if (mFirstPersonNeckController)
{ {
mFirstPersonNeckController->setRotate(osg::Quat(mPtr.getRefData().getPosition().rot[0], osg::Vec3f(-1,0,0))); if (mAccurateAiming)
mAimingFactor = 1.f;
else
mAimingFactor = std::max(0.f, mAimingFactor - timepassed * 0.5f);
float rotateFactor = 0.75f + 0.25f * mAimingFactor;
mFirstPersonNeckController->setRotate(osg::Quat(mPtr.getRefData().getPosition().rot[0] * rotateFactor, osg::Vec3f(-1,0,0)));
mFirstPersonNeckController->setOffset(mFirstPersonOffset); mFirstPersonNeckController->setOffset(mFirstPersonOffset);
} }
@ -1072,4 +1081,9 @@ void NpcAnimation::updatePtr(const MWWorld::Ptr &updated)
mHeadAnimationTime->updatePtr(updated); mHeadAnimationTime->updatePtr(updated);
} }
void NpcAnimation::setAccurateAiming(bool enabled)
{
mAccurateAiming = enabled;
}
} }

View file

@ -67,6 +67,9 @@ private:
bool mSoundsDisabled; bool mSoundsDisabled;
bool mAccurateAiming;
float mAimingFactor;
void updateNpcBase(); void updateNpcBase();
PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename, PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename,
@ -104,6 +107,10 @@ public:
virtual void enableHeadAnimation(bool enable); virtual void enableHeadAnimation(bool enable);
/// 1: the first person meshes follow the camera's rotation completely
/// 0: the first person meshes follow the camera with a reduced factor, so you can look down at your own hands
virtual void setAccurateAiming(bool enabled);
virtual void setWeaponGroup(const std::string& group); virtual void setWeaponGroup(const std::string& group);
virtual osg::Vec3f runAnimation(float timepassed); virtual osg::Vec3f runAnimation(float timepassed);