BlockAnimation.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "BlockAnimation.h"
  2. BlockAnimation::BlockAnimation(
  3. Block* block, Framework::SkeletonAnimation* animation)
  4. : ReferenceCounter(),
  5. block(block),
  6. animation(animation)
  7. {}
  8. BlockAnimation::~BlockAnimation() {
  9. block->release();
  10. if(animation) animation->release();
  11. }
  12. void BlockAnimation::appendAnimation(int boneId,
  13. double time,
  14. Framework::Vec3<float> pos,
  15. Framework::Vec3<float> rot)
  16. {
  17. BoneAnimation* ba = animation->zAnimation(boneId);
  18. if (ba)
  19. {
  20. ba->addKeyFrame(ba->getMaxTime() + time, pos, rot);
  21. }
  22. else
  23. {
  24. Bone* bone = block->zSkeleton()->zBone(boneId);
  25. animation->addAnimation(
  26. boneId, bone->getPosition(), bone->getRotation());
  27. animation->addKeyFrame(boneId, time, pos, rot);
  28. }
  29. }
  30. bool BlockAnimation::tick(double time) {
  31. if (animation)
  32. {
  33. animation->tick(time);
  34. animation->apply(block->zSkeleton());
  35. if (animation->isFinished())
  36. {
  37. animation->release();
  38. animation = 0;
  39. }
  40. return 1;
  41. }
  42. return 0;
  43. }
  44. bool BlockAnimation::isFinished() const {
  45. return animation == 0;
  46. }
  47. Block* BlockAnimation::zBlock() const {
  48. return block;
  49. }