ValueAnimationInfo.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // Copyright (c) 2008-2017 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. #pragma once
  23. #include "../Container/Ptr.h"
  24. #include "../Container/RefCounted.h"
  25. #include "../Container/Vector.h"
  26. #include "../Scene/AnimationDefs.h"
  27. namespace Urho3D
  28. {
  29. class Object;
  30. class ValueAnimation;
  31. class Variant;
  32. struct VAnimEventFrame;
  33. /// Base class for a value animation instance, which includes animation runtime information and updates the target object's value automatically.
  34. class URHO3D_API ValueAnimationInfo : public RefCounted
  35. {
  36. public:
  37. /// Construct without target object.
  38. ValueAnimationInfo(ValueAnimation* animation, WrapMode wrapMode, float speed);
  39. /// Construct with target object.
  40. ValueAnimationInfo(Object* target, ValueAnimation* animation, WrapMode wrapMode, float speed);
  41. /// Copy construct.
  42. ValueAnimationInfo(const ValueAnimationInfo& other);
  43. /// Destruct.
  44. ~ValueAnimationInfo();
  45. /// Advance time position and apply. Return true when the animation is finished. No-op when the target object is not defined.
  46. bool Update(float timeStep);
  47. /// Set time position and apply. Return true when the animation is finished. No-op when the target object is not defined.
  48. bool SetTime(float time);
  49. /// Set wrap mode.
  50. void SetWrapMode(WrapMode wrapMode) { wrapMode_ = wrapMode; }
  51. /// Set speed.
  52. void SetSpeed(float speed) { speed_ = speed; }
  53. /// Return target object.
  54. Object* GetTarget() const;
  55. /// Return animation.
  56. ValueAnimation* GetAnimation() const { return animation_; }
  57. /// Return wrap mode.
  58. WrapMode GetWrapMode() const { return wrapMode_; }
  59. /// Return time position.
  60. float GetTime() const { return currentTime_; }
  61. /// Return speed.
  62. float GetSpeed() const { return speed_; }
  63. protected:
  64. /// Apply new animation value to the target object. Called by Update().
  65. virtual void ApplyValue(const Variant& newValue);
  66. /// Calculate scaled time.
  67. float CalculateScaledTime(float currentTime, bool& finished) const;
  68. /// Return event frames.
  69. void GetEventFrames(float beginTime, float endTime, PODVector<const VAnimEventFrame*>& eventFrames);
  70. /// Target object.
  71. WeakPtr<Object> target_;
  72. /// Attribute animation.
  73. SharedPtr<ValueAnimation> animation_;
  74. /// Wrap mode.
  75. WrapMode wrapMode_;
  76. /// Animation speed.
  77. float speed_;
  78. /// Current time.
  79. float currentTime_;
  80. /// Last scaled time.
  81. float lastScaledTime_;
  82. };
  83. }