Motion.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /******************************************************************************
  2. Use 'Motion' to simplify applying a single animation on a skeleton.
  3. /******************************************************************************/
  4. struct Motion // Animation Motion, helper class for playing a single Animation
  5. {
  6. Flt time , // animation time position
  7. blend ; // animation blend value
  8. SkelAnim *skel_anim; // skeleton animation pointer
  9. // manage
  10. Motion& clear( ); // clear animation
  11. Motion& set (AnimatedSkeleton &anim_skel, C Str &anim_name); // set animation, 'anim_skel'=animated skeleton to be used with this motion, 'anim_name'=animation file name
  12. Motion& set (AnimatedSkeleton &anim_skel, C UID &anim_id ); // set animation, 'anim_skel'=animated skeleton to be used with this motion, 'anim_id' =animation file name ID
  13. // get
  14. Bool is()C {return skel_anim!=null;} // if Motion is valid
  15. C Animation* animation ()C {return skel_anim ? skel_anim->animation() : null ;} // get animation
  16. UID animationID()C {return skel_anim ? skel_anim->id () : UIDZero;} // get animation ID
  17. Flt animBlend()C {return SmoothCube(blend);} // get blend factor used for animating
  18. Int eventCount(CChar8 *name)C {return skel_anim ? skel_anim->eventCount(name) : 0;} // get number of events with specified name in this animation
  19. Bool eventAfter (CChar8 *name )C; // if motion 'time' is after 'name' event (in the animation)
  20. Bool eventAfter (Flt event_time )C; // if motion 'time' is after event time
  21. Bool eventOccurred(CChar8 *name )C; // if 'name' event (in the animation) occurred in current frame
  22. Bool eventOccurred(Flt event_time )C; // if event time occurred in current frame
  23. Bool eventBetween (CChar8 *from, CChar8 *to)C; // if motion 'time' is between event 'from' and 'to'
  24. Bool eventBetween (Flt from, Flt to)C; // if motion 'time' is between event 'from' and 'to' times
  25. Flt eventProgress(CChar8 *from, CChar8 *to)C; // get motion 'time' progress between 'from' and 'to' , 0 on fail
  26. Flt eventProgress(Flt from, Flt to)C; // get motion 'time' progress between 'from' and 'to' times, 0 on fail
  27. // update
  28. Bool updateAuto(Flt blend_in_speed, Flt blend_out_speed, Flt time_speed=1); // update (blend in -> play animation -> blend out), returns false when animation finished playing and blending out
  29. Bool updateIn (Flt blend_in_speed, Flt time_speed=1); // update (blend in -> play animation ), returns false when animation finished playing
  30. Bool updateOut ( Flt blend_out_speed ); // update ( blend out), returns false when animation finished blending out
  31. // io
  32. Bool save(File &f )C; // save, false on fail
  33. Bool load(File &f, C AnimatedSkeleton &anim_skel) ; // load, false on fail
  34. Motion() {clear();}
  35. private:
  36. Flt time_prev, time_delta;
  37. };
  38. /******************************************************************************/