Move head tracking from NpcAnimation to Animation (Bug #2720)

c++11
scrawl 10 years ago
parent a5670b5133
commit 24bfb44b13

@ -41,6 +41,7 @@
#include "vismask.hpp"
#include "util.hpp"
#include "rotatecontroller.hpp"
namespace
{
@ -257,6 +258,8 @@ namespace MWRender
, mResourceSystem(resourceSystem)
, mAccumulate(1.f, 1.f, 0.f)
, mTextKeyListener(NULL)
, mHeadYawRadians(0.f)
, mHeadPitchRadians(0.f)
{
for(size_t i = 0;i < sNumGroups;i++)
mAnimationTimePtr[i].reset(new AnimationTime);
@ -900,6 +903,15 @@ namespace MWRender
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;
}
@ -1212,6 +1224,42 @@ namespace MWRender
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*)
{
if (mTimePtr)

@ -25,6 +25,7 @@ namespace MWRender
{
class ResetAccumRootCallback;
class RotateController;
class EffectAnimationTime : public SceneUtil::ControllerSource
{
@ -197,6 +198,10 @@ protected:
TextKeyListener* mTextKeyListener;
osg::ref_ptr<RotateController> mHeadController;
float mHeadYawRadians;
float mHeadPitchRadians;
/* Sets the appropriate animations on the bone groups based on priority.
*/
void resetActiveGroups();
@ -243,7 +248,7 @@ protected:
* 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.
*/
virtual void addControllers() {}
virtual void addControllers();
osg::Vec4f getEnchantmentColor(MWWorld::Ptr item);
@ -374,10 +379,10 @@ public:
/// @param effect Controls the radius and intensity of the light.
virtual void setLightEffect(float effect) {}
virtual void setHeadPitch(float pitchRadians) {}
virtual void setHeadYaw(float yawRadians) {}
virtual float getHeadPitch() const {return 0.f;}
virtual float getHeadYaw() const {return 0.f;}
virtual void setHeadPitch(float pitchRadians);
virtual void setHeadYaw(float yawRadians);
virtual float getHeadPitch() const;
virtual float getHeadYaw() const;
private:
Animation(const Animation&);

@ -174,6 +174,7 @@ Resource::ResourceSystem *CreatureWeaponAnimation::getResourceSystem()
void CreatureWeaponAnimation::addControllers()
{
Animation::addControllers();
WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get());
}

@ -243,9 +243,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr<osg::Group> par
mShowCarriedLeft(true),
mNpcType(Type_Normal),
mAlpha(1.f),
mSoundsDisabled(disableSounds),
mHeadYawRadians(0.f),
mHeadPitchRadians(0.f)
mSoundsDisabled(disableSounds)
{
mNpc = mPtr.get<ESM::NPC>()->mBase;
@ -650,40 +648,11 @@ osg::Vec3f NpcAnimation::runAnimation(float timepassed)
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]);
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)
{
mPartPriorities[type] = 0;
@ -843,6 +812,8 @@ void NpcAnimation::addPartGroup(int group, int priority, const std::vector<ESM::
void NpcAnimation::addControllers()
{
Animation::addControllers();
mFirstPersonNeckController = NULL;
mHeadController = NULL;
WeaponAnimation::deleteControllers();
@ -860,15 +831,6 @@ void NpcAnimation::addControllers()
}
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());
}
}

@ -49,7 +49,6 @@ public:
};
class NeckController;
class RotateController;
class NpcAnimation : public Animation, public WeaponAnimation, public MWWorld::InventoryStoreListener
{
@ -101,9 +100,6 @@ private:
float mAlpha;
bool mSoundsDisabled;
float mHeadYawRadians;
float mHeadPitchRadians;
void updateNpcBase();
PartHolderPtr insertBoundedPart(const std::string &model, const std::string &bonename,
@ -119,7 +115,6 @@ private:
bool enchantedGlow=false, osg::Vec4f* glowColor=NULL);
osg::ref_ptr<NeckController> mFirstPersonNeckController;
osg::ref_ptr<RotateController> mHeadController;
protected:
virtual void addControllers();
@ -151,11 +146,6 @@ public:
/// to indicate the facing orientation of the character.
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 showCarriedLeft(bool show);

Loading…
Cancel
Save