yake motion manager...

来源:互联网 发布:考试酷软件下载 编辑:程序博客网 时间:2024/05/19 01:11
这个设计来自yake论坛fenris的贴... http://www.yake.org/forum/index.php/topic,908.0.html
主要功能
handle simplifying motion/animation sequencing over time. 
组成
1) SequenceElements which can be animations, translations, rotations (at this point), relative (to the sequence) start/stop times, loop iterations and so on
2) Sequences which are lists of 1) kept in time order sorted by start, then stop, times.  It is planned that elements, sequences and nodes will be able to be added/updated/deleted dynamicaly
3) MotionNodes which are (so far) scene nodes/skeleton containers.  They also keep track of their own local time so that several nodes may be at in flight along a given sequence at once.  They are kept sorted by sequence to batch things up as best I can.  They can be active/inactive at any time and can be assigned a 'portal id' for further elimination of un-needed work.  Will be able to be dynamically added/updated and deleted as well.
The MotionManager algorithm basically walks each active node and then walks each matching sequence element proportionally applying those that fit the motion nodes's current time + elapsed time since the last frame was rendered.  It correctly handles cases where curent + elapsed time spans accross, or even completely skips, sequence elements and so on.
代码演示
    // Instantiate it
     MM = new GlobalMotionManager();

     . . .

      
// Use it
      
// Add Sequence
      
// bool GlobalMotionManager::InsertSequence(const std::string &SeqName, int Loops)
      MM->InsertSequence( "NinjaDance"1 );

      
// Add Sequence Elements - tType 1=translate, 2=rotate, 4=animate
      
// bool GlobalMotionManager::InsertSequenceElement(const std::string& SeqName, 
     
// const std::string &SeqElName, real tStart, real tStop, 
     
// int tLoops, int tType, const yake::math::Vector3& tVector, 
     
// real tData1, const std::string& tAnimName )
     MM->InsertSequenceElement( "NinjaDance""NinAttack1"0.02.034,
    Vector3::kUnitZ, 
0"Attack1");
     MM
->InsertSequenceElement( "NinjaDance""NinAttack2"2.03.014,
Vector3::kUnitZ, 
0"Attack2");
     MM
->InsertSequenceElement( "NinjaDance""NinWalk"3.04.024,
Vector3::kUnitZ, 
0"Walk");
     MM
->InsertSequenceElement( "NinjaDance""NinMove1"3.04.011,
Vector3(
0.0,0.0,-0.3), (real)0.0"");
     MM
->InsertSequenceElement( "NinjaDance""NinSpin"4.06.012,
Vector3::kUnitZ, (real)
1.707"");
     MM
->InsertSequenceElement( "NinjaDance""NinSpin2"6.18.012,
Vector3::kUnitY, (real)
1.707"");
     MM
->InsertSequenceElement( "NinjaDance""NinMove2"8.010.011,
Vector3(
-.3,0.0,0.0), (real)0.0"");

      
// Add node and mesh to a new MM node
      
// bool GlobalMotionManager::InsertMotionNode(const std::string& SeqName, 
     
// const std::string& MotNodeName, int tPortal, bool tActive, real tTime, 
     
// int tType, graphics::ISceneNode *tNode, graphics::ISkeleton *tSkel )
     MM->InsertMotionNode( "NinjaDance""Look_Ma-I_Am_A_Ninja"1true0.01, nSN, Skel );

     
// debug stuff
     MM->DumpStatus();

     ...

     
// update - in this case in Raf onframe()
    MM->ProcessActiveSequences(timeElapsed);

扩展考虑

1) Already mentioned creation of base / derived sequence element classes. And nodes while I am at it (positioning/moving sound would be nice as well)
2) Wired for scripting?
3) Impliment time controllers.  Right now time is applied linearly, but various wave applications would be nice.  Example?  Running starts slow, speeds up to a steady state and then slows down as we are about to stop again.  Given the current linear time progression through the animation, it would require several sequence elements to make this look good now.  But, with a time controller attached to the sequence element, it probably would not
原创粉丝点击