mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 06:36:44 +00:00
Move head tracking from NpcAnimation to Animation (Bug #2720)
This commit is contained in:
parent
a5670b5133
commit
24bfb44b13
5 changed files with 62 additions and 56 deletions
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#include "vismask.hpp"
|
#include "vismask.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
#include "rotatecontroller.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -257,6 +258,8 @@ namespace MWRender
|
||||||
, mResourceSystem(resourceSystem)
|
, mResourceSystem(resourceSystem)
|
||||||
, mAccumulate(1.f, 1.f, 0.f)
|
, mAccumulate(1.f, 1.f, 0.f)
|
||||||
, mTextKeyListener(NULL)
|
, mTextKeyListener(NULL)
|
||||||
|
, mHeadYawRadians(0.f)
|
||||||
|
, mHeadPitchRadians(0.f)
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < sNumGroups;i++)
|
for(size_t i = 0;i < sNumGroups;i++)
|
||||||
mAnimationTimePtr[i].reset(new AnimationTime);
|
mAnimationTimePtr[i].reset(new AnimationTime);
|
||||||
|
@ -900,6 +903,15 @@ namespace MWRender
|
||||||
|
|
||||||
updateEffects(duration);
|
updateEffects(duration);
|
||||||
|
|
||||||
|
if (mHeadController)
|
||||||
|
{
|
||||||
|
const float epsilon = 0.001f;
|
||||||
|
bool enable = (std::abs(mHeadPitchRadians) > epsilon || std::abs(mHeadYawRadians) > epsilon);
|
||||||
|
mHeadController->setEnabled(enable);
|
||||||
|
if (enable)
|
||||||
|
mHeadController->setRotate(osg::Quat(mHeadPitchRadians, osg::Vec3f(1,0,0)) * osg::Quat(mHeadYawRadians, osg::Vec3f(0,0,1)));
|
||||||
|
}
|
||||||
|
|
||||||
return movement;
|
return movement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1212,6 +1224,42 @@ namespace MWRender
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animation::addControllers()
|
||||||
|
{
|
||||||
|
mHeadController = NULL;
|
||||||
|
|
||||||
|
NodeMap::iterator found = mNodeMap.find("bip01 head");
|
||||||
|
if (found != mNodeMap.end() && dynamic_cast<osg::MatrixTransform*>(found->second.get()))
|
||||||
|
{
|
||||||
|
osg::Node* node = found->second;
|
||||||
|
mHeadController = new RotateController(mObjectRoot.get());
|
||||||
|
node->addUpdateCallback(mHeadController);
|
||||||
|
mActiveControllers.insert(std::make_pair(node, mHeadController));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::setHeadPitch(float pitchRadians)
|
||||||
|
{
|
||||||
|
mHeadPitchRadians = pitchRadians;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animation::setHeadYaw(float yawRadians)
|
||||||
|
{
|
||||||
|
mHeadYawRadians = yawRadians;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::getHeadPitch() const
|
||||||
|
{
|
||||||
|
return mHeadPitchRadians;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Animation::getHeadYaw() const
|
||||||
|
{
|
||||||
|
return mHeadYawRadians;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
float Animation::AnimationTime::getValue(osg::NodeVisitor*)
|
float Animation::AnimationTime::getValue(osg::NodeVisitor*)
|
||||||
{
|
{
|
||||||
if (mTimePtr)
|
if (mTimePtr)
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
class ResetAccumRootCallback;
|
class ResetAccumRootCallback;
|
||||||
|
class RotateController;
|
||||||
|
|
||||||
class EffectAnimationTime : public SceneUtil::ControllerSource
|
class EffectAnimationTime : public SceneUtil::ControllerSource
|
||||||
{
|
{
|
||||||
|
@ -197,6 +198,10 @@ protected:
|
||||||
|
|
||||||
TextKeyListener* mTextKeyListener;
|
TextKeyListener* mTextKeyListener;
|
||||||
|
|
||||||
|
osg::ref_ptr<RotateController> mHeadController;
|
||||||
|
float mHeadYawRadians;
|
||||||
|
float mHeadPitchRadians;
|
||||||
|
|
||||||
/* Sets the appropriate animations on the bone groups based on priority.
|
/* Sets the appropriate animations on the bone groups based on priority.
|
||||||
*/
|
*/
|
||||||
void resetActiveGroups();
|
void resetActiveGroups();
|
||||||
|
@ -243,7 +248,7 @@ protected:
|
||||||
* Provided to allow derived classes adding their own controllers. Note, the controllers must be added to mActiveControllers
|
* Provided to allow derived classes adding their own controllers. Note, the controllers must be added to mActiveControllers
|
||||||
* so they get cleaned up properly on the next controller rebuild. A controller rebuild may be necessary to ensure correct ordering.
|
* so they get cleaned up properly on the next controller rebuild. A controller rebuild may be necessary to ensure correct ordering.
|
||||||
*/
|
*/
|
||||||
virtual void addControllers() {}
|
virtual void addControllers();
|
||||||
|
|
||||||
osg::Vec4f getEnchantmentColor(MWWorld::Ptr item);
|
osg::Vec4f getEnchantmentColor(MWWorld::Ptr item);
|
||||||
|
|
||||||
|
@ -374,10 +379,10 @@ public:
|
||||||
/// @param effect Controls the radius and intensity of the light.
|
/// @param effect Controls the radius and intensity of the light.
|
||||||
virtual void setLightEffect(float effect) {}
|
virtual void setLightEffect(float effect) {}
|
||||||
|
|
||||||
virtual void setHeadPitch(float pitchRadians) {}
|
virtual void setHeadPitch(float pitchRadians);
|
||||||
virtual void setHeadYaw(float yawRadians) {}
|
virtual void setHeadYaw(float yawRadians);
|
||||||
virtual float getHeadPitch() const {return 0.f;}
|
virtual float getHeadPitch() const;
|
||||||
virtual float getHeadYaw() const {return 0.f;}
|
virtual float getHeadYaw() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Animation(const Animation&);
|
Animation(const Animation&);
|
||||||
|
|
|
@ -174,6 +174,7 @@ Resource::ResourceSystem *CreatureWeaponAnimation::getResourceSystem()
|
||||||
|
|
||||||
void CreatureWeaponAnimation::addControllers()
|
void CreatureWeaponAnimation::addControllers()
|
||||||
{
|
{
|
||||||
|
Animation::addControllers();
|
||||||
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
|
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,9 +243,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> par
|
||||||
mShowCarriedLeft(true),
|
mShowCarriedLeft(true),
|
||||||
mNpcType(Type_Normal),
|
mNpcType(Type_Normal),
|
||||||
mAlpha(1.f),
|
mAlpha(1.f),
|
||||||
mSoundsDisabled(disableSounds),
|
mSoundsDisabled(disableSounds)
|
||||||
mHeadYawRadians(0.f),
|
|
||||||
mHeadPitchRadians(0.f)
|
|
||||||
{
|
{
|
||||||
mNpc = mPtr.get<ESM::NPC>()->mBase;
|
mNpc = mPtr.get<ESM::NPC>()->mBase;
|
||||||
|
|
||||||
|
@ -650,40 +648,11 @@ osg::Vec3f NpcAnimation::runAnimation(float timepassed)
|
||||||
mFirstPersonNeckController->setOffset(mFirstPersonOffset);
|
mFirstPersonNeckController->setOffset(mFirstPersonOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHeadController)
|
|
||||||
{
|
|
||||||
const float epsilon = 0.001f;
|
|
||||||
bool enable = (std::abs(mHeadPitchRadians) > epsilon || std::abs(mHeadYawRadians) > epsilon);
|
|
||||||
mHeadController->setEnabled(enable);
|
|
||||||
if (enable)
|
|
||||||
mHeadController->setRotate(osg::Quat(mHeadPitchRadians, osg::Vec3f(1,0,0)) * osg::Quat(mHeadYawRadians, osg::Vec3f(0,0,1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
WeaponAnimation::configureControllers(mPtr.getRefData().getPosition().rot[0]);
|
WeaponAnimation::configureControllers(mPtr.getRefData().getPosition().rot[0]);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NpcAnimation::setHeadPitch(float pitchRadians)
|
|
||||||
{
|
|
||||||
mHeadPitchRadians = pitchRadians;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NpcAnimation::setHeadYaw(float yawRadians)
|
|
||||||
{
|
|
||||||
mHeadYawRadians = yawRadians;
|
|
||||||
}
|
|
||||||
|
|
||||||
float NpcAnimation::getHeadPitch() const
|
|
||||||
{
|
|
||||||
return mHeadPitchRadians;
|
|
||||||
}
|
|
||||||
|
|
||||||
float NpcAnimation::getHeadYaw() const
|
|
||||||
{
|
|
||||||
return mHeadYawRadians;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type)
|
void NpcAnimation::removeIndividualPart(ESM::PartReferenceType type)
|
||||||
{
|
{
|
||||||
mPartPriorities[type] = 0;
|
mPartPriorities[type] = 0;
|
||||||
|
@ -843,6 +812,8 @@ void NpcAnimation::addPartGroup(int group, int priority, const std::vector<ESM::
|
||||||
|
|
||||||
void NpcAnimation::addControllers()
|
void NpcAnimation::addControllers()
|
||||||
{
|
{
|
||||||
|
Animation::addControllers();
|
||||||
|
|
||||||
mFirstPersonNeckController = NULL;
|
mFirstPersonNeckController = NULL;
|
||||||
mHeadController = NULL;
|
mHeadController = NULL;
|
||||||
WeaponAnimation::deleteControllers();
|
WeaponAnimation::deleteControllers();
|
||||||
|
@ -860,15 +831,6 @@ void NpcAnimation::addControllers()
|
||||||
}
|
}
|
||||||
else if (mViewMode == VM_Normal)
|
else if (mViewMode == VM_Normal)
|
||||||
{
|
{
|
||||||
NodeMap::iterator found = mNodeMap.find("bip01 head");
|
|
||||||
if (found != mNodeMap.end() && dynamic_cast<osg::MatrixTransform*>(found->second.get()))
|
|
||||||
{
|
|
||||||
osg::Node* node = found->second;
|
|
||||||
mHeadController = new RotateController(mObjectRoot.get());
|
|
||||||
node->addUpdateCallback(mHeadController);
|
|
||||||
mActiveControllers.insert(std::make_pair(node, mHeadController));
|
|
||||||
}
|
|
||||||
|
|
||||||
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
|
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class NeckController;
|
class NeckController;
|
||||||
class RotateController;
|
|
||||||
|
|
||||||
class NpcAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener
|
class NpcAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener
|
||||||
{
|
{
|
||||||
|
@ -101,9 +100,6 @@ private:
|
||||||
float mAlpha;
|
float mAlpha;
|
||||||
bool mSoundsDisabled;
|
bool mSoundsDisabled;
|
||||||
|
|
||||||
float mHeadYawRadians;
|
|
||||||
float mHeadPitchRadians;
|
|
||||||
|
|
||||||
void updateNpcBase();
|
void updateNpcBase();
|
||||||
|
|
||||||
PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename,
|
PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename,
|
||||||
|
@ -119,7 +115,6 @@ private:
|
||||||
bool enchantedGlow=false, osg::Vec4f* glowColor=NULL);
|
bool enchantedGlow=false, osg::Vec4f* glowColor=NULL);
|
||||||
|
|
||||||
osg::ref_ptr<NeckController> mFirstPersonNeckController;
|
osg::ref_ptr<NeckController> mFirstPersonNeckController;
|
||||||
osg::ref_ptr<RotateController> mHeadController;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void addControllers();
|
virtual void addControllers();
|
||||||
|
@ -151,11 +146,6 @@ public:
|
||||||
/// to indicate the facing orientation of the character.
|
/// to indicate the facing orientation of the character.
|
||||||
virtual void setPitchFactor(float factor) { mPitchFactor = factor; }
|
virtual void setPitchFactor(float factor) { mPitchFactor = factor; }
|
||||||
|
|
||||||
virtual void setHeadPitch(float pitchRadians);
|
|
||||||
virtual void setHeadYaw(float yawRadians);
|
|
||||||
virtual float getHeadPitch() const;
|
|
||||||
virtual float getHeadYaw() const;
|
|
||||||
|
|
||||||
virtual void showWeapons(bool showWeapon);
|
virtual void showWeapons(bool showWeapon);
|
||||||
virtual void showCarriedLeft(bool show);
|
virtual void showCarriedLeft(bool show);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue