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