diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 3801cf6fc..5955fc4cf 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -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(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) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d80fd96a4..1140fb172 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -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 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&); diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 9d1fccdb2..ec4ee99e4 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -174,6 +174,7 @@ Resource::ResourceSystem *CreatureWeaponAnimation::getResourceSystem() void CreatureWeaponAnimation::addControllers() { + Animation::addControllers(); WeaponAnimation::addControllers(mNodeMap, mActiveControllers, mObjectRoot.get()); } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 21ec8d535..2f2015432 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -243,9 +243,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, osg::ref_ptr par mShowCarriedLeft(true), mNpcType(Type_Normal), mAlpha(1.f), - mSoundsDisabled(disableSounds), - mHeadYawRadians(0.f), - mHeadPitchRadians(0.f) + mSoundsDisabled(disableSounds) { mNpc = mPtr.get()->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(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()); } } diff --git a/apps/openmw/mwrender/npcanimation.hpp b/apps/openmw/mwrender/npcanimation.hpp index 3eb4c4754..726d88605 100644 --- a/apps/openmw/mwrender/npcanimation.hpp +++ b/apps/openmw/mwrender/npcanimation.hpp @@ -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 mFirstPersonNeckController; - osg::ref_ptr 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);