ValueAnimationInfo.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "ValueAnimation.h"
  24. #include "ValueAnimationInfo.h"
  25. #include "Log.h"
  26. #include "DebugNew.h"
  27. namespace Urho3D
  28. {
  29. ValueAnimationInfo::ValueAnimationInfo(ValueAnimation* animation, WrapMode wrapMode, float speed) :
  30. animation_(animation),
  31. wrapMode_(wrapMode),
  32. speed_(speed)
  33. {
  34. speed_ = Max(0.0f, speed_);
  35. }
  36. ValueAnimationInfo::ValueAnimationInfo(const ValueAnimationInfo& other) :
  37. animation_(other.animation_),
  38. wrapMode_(other.wrapMode_),
  39. speed_(other.speed_)
  40. {
  41. }
  42. ValueAnimationInfo::~ValueAnimationInfo()
  43. {
  44. }
  45. float ValueAnimationInfo::CalculateScaledTime(float currentTime, bool& finished) const
  46. {
  47. float beginTime = animation_->GetBeginTime();
  48. float endTime = animation_->GetEndTime();
  49. switch (wrapMode_)
  50. {
  51. case WM_LOOP:
  52. {
  53. float span = endTime - beginTime;
  54. float time = fmodf(currentTime - beginTime, span);
  55. if (time < 0.0f)
  56. time += span;
  57. return beginTime + time;
  58. }
  59. case WM_ONCE:
  60. finished = (currentTime >= endTime);
  61. // Fallthrough
  62. case WM_CLAMP:
  63. return Clamp(currentTime, beginTime, endTime);
  64. default:
  65. LOGERROR("Unsupported attribute animation wrap mode");
  66. return beginTime;
  67. }
  68. }
  69. void ValueAnimationInfo::GetEventFrames(float beginTime, float endTime, PODVector<const VAnimEventFrame*>& eventFrames)
  70. {
  71. switch (wrapMode_)
  72. {
  73. case WM_LOOP:
  74. if (beginTime < endTime)
  75. animation_->GetEventFrames(beginTime, endTime, eventFrames);
  76. else
  77. {
  78. animation_->GetEventFrames(beginTime, animation_->GetEndTime(), eventFrames);
  79. animation_->GetEventFrames(animation_->GetBeginTime(), endTime, eventFrames);
  80. }
  81. break;
  82. case WM_ONCE:
  83. case WM_CLAMP:
  84. animation_->GetEventFrames(beginTime, endTime, eventFrames);
  85. break;
  86. }
  87. }
  88. }