diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4d725b4de..1c8ceffd7 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -4,7 +4,6 @@ namespace MWRender{ std::map Animation::mUniqueIDs; Animation::~Animation(){ - base = 0; } std::string Animation::getUniqueID(std::string mesh){ int counter; @@ -320,5 +319,73 @@ namespace MWRender{ else return false; +} + + void Animation::handleAnimationTransforms(){ + Ogre::Bone* b = skel->getRootBone(); + b->setOrientation(.3,.3,.3,.3); //This is a trick + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + std::vector::iterator iter; + int slot = 0; + if(transformations){ + for(iter = transformations->begin(); iter != transformations->end(); iter++){ + if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime()) + { + continue; + } + + if(skel->hasBone(iter->getBonename())){ + Ogre::Bone* bone = skel->getBone(iter->getBonename()); + + float x; + float x2; + + std::vector quats = iter->getQuat(); + + std::vector ttime = iter->gettTime(); + std::vector::iterator ttimeiter = ttime.begin(); + + std::vector rtime = iter->getrTime(); + int rindexJ = 0; + timeIndex(time, rtime, rindexI[slot], rindexJ, x2); + int tindexJ = 0; + + + std::vector translist1 = iter->getTranslist1(); + + timeIndex(time, ttime, tindexI[slot], tindexJ, x); + + //std::cout << "X: " << x << " X2: " << x2 << "\n"; + + + if(translist1.size() > 0){ + Ogre::Vector3 v1 = translist1[tindexI[slot]]; + Ogre::Vector3 v2 = translist1[tindexJ]; + Ogre::Vector3 t = v1 + (v2 - v1) * x; + bone->setPosition(t); + } + + if(quats.size() > 0){ + Ogre::Quaternion r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); + bone->setOrientation(r); + } + + + skel->getManualBonesDirty(); + skel->_updateTransforms(); + skel->_notifyManualBonesDirty(); + + Ogre::Entity* ent = base; + + ent->getAllAnimationStates()->_notifyDirty(); + ent->_updateAnimation(); + ent->_notifyMoved(); + } + slot++; + } +} } } \ No newline at end of file diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 19635270c..acead8c07 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -40,6 +40,7 @@ class Animation{ std::map textmappings; Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); + void handleAnimationTransforms(); bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); public: