1 #ifndef DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali/public-api/animation/alpha-function.h>
26 #include <dali/public-api/animation/animation.h>
27 #include <dali/public-api/animation/time-period.h>
28 #include <dali/public-api/common/constants.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/math/quaternion.h>
31 #include <dali/public-api/math/radian.h>
32 #include <dali/devel-api/common/owner-container.h>
33 #include <dali/internal/event/animation/key-frames-impl.h>
34 #include <dali/internal/event/animation/path-impl.h>
35 #include <dali/internal/update/nodes/node.h>
36 #include <dali/internal/update/common/property-base.h>
37 #include <dali/internal/update/animation/property-accessor.h>
38 #include <dali/integration-api/debug.h>
46 using Interpolation = Dali::Animation::Interpolation;
49 * AnimatorFunction base class.
50 * Needs to be declared first so AnimatorBase knows about it's destructor
51 * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
53 struct AnimatorFunctionBase
58 AnimatorFunctionBase() {}
61 * Virtual destructor (Intended as base class)
63 virtual ~AnimatorFunctionBase() {}
65 ///Stub "()" operators.
66 virtual bool operator()(float progress, const bool& property)
71 virtual float operator()(float progress, const int32_t& property)
73 return static_cast<float>( property );
76 virtual float operator()(float progress, const float& property)
81 virtual Vector2 operator()(float progress, const Vector2& property)
86 virtual Vector3 operator()(float progress, const Vector3& property)
91 virtual Vector4 operator()(float progress, const Vector4& property)
96 virtual Quaternion operator()(float progress, const Quaternion& property)
106 * An abstract base class for Animators, which can be added to scene graph animations.
107 * Each animator changes a single property of an object in the scene graph.
109 class AnimatorBase : public PropertyOwner::Observer
113 using AlphaFunc = float (*)(float progress); ///< Definition of an alpha function
116 * Observer to determine when the animator is no longer present
118 class LifecycleObserver
122 * Called shortly before the animator is destroyed.
124 virtual void ObjectDestroyed() = 0;
128 * Virtual destructor, no deletion through this interface
130 virtual ~LifecycleObserver() = default;
137 AnimatorBase( PropertyOwner* propertyOwner,
138 AnimatorFunctionBase* animatorFunction,
139 AlphaFunction alphaFunction,
140 const TimePeriod& timePeriod )
141 : mLifecycleObserver( nullptr ),
142 mPropertyOwner( propertyOwner ),
143 mAnimatorFunction( animatorFunction ),
144 mDurationSeconds( timePeriod.durationSeconds ),
145 mIntervalDelaySeconds( timePeriod.delaySeconds ),
146 mSpeedFactor( 1.0f ),
147 mCurrentProgress( 0.f ),
149 mAlphaFunction( alphaFunction ),
150 mDisconnectAction( Dali::Animation::BAKE_FINAL ),
151 mAnimationPlaying( false ),
153 mConnectedToSceneGraph( false ),
154 mAutoReverseEnabled( false )
159 * Virtual destructor.
161 ~AnimatorBase() override
163 delete mAnimatorFunction;
164 if (mPropertyOwner && mConnectedToSceneGraph)
166 mPropertyOwner->RemoveObserver(*this);
168 if( mLifecycleObserver != nullptr )
170 mLifecycleObserver->ObjectDestroyed();
174 void AddLifecycleObserver( LifecycleObserver& observer )
176 mLifecycleObserver = &observer;
179 void RemoveLifecycleObserver( LifecycleObserver& observer )
181 mLifecycleObserver = nullptr;
184 private: // From PropertyOwner::Observer
187 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected( PropertyOwner& owner )
189 void PropertyOwnerConnected( PropertyOwner& owner ) final
195 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
197 void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) final
199 // If we are active, then bake the value if required
200 if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::DISCARD )
202 // Bake to target-value if BakeFinal, otherwise bake current value
203 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::BAKE ? mCurrentProgress : 1.0f ), true );
210 * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed( PropertyOwner& owner )
212 void PropertyOwnerDestroyed( PropertyOwner& owner ) final
214 mPropertyOwner = nullptr;
219 * Called when Animator is added to the scene-graph in update-thread.
221 void ConnectToSceneGraph()
223 mConnectedToSceneGraph = true;
224 mPropertyOwner->AddObserver(*this);
228 * Set the duration of the animator.
229 * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
230 * @param [in] seconds Duration in seconds.
232 void SetDuration(float seconds)
234 DALI_ASSERT_DEBUG(seconds >= 0.0f);
236 mDurationSeconds = seconds;
240 * Retrieve the duration of the animator.
241 * @return The duration in seconds.
243 float GetDuration() const
245 return mDurationSeconds;
248 void SetSpeedFactor( float factor )
250 mSpeedFactor = factor;
253 void SetLoopCount(int32_t loopCount)
255 mLoopCount = loopCount;
258 float SetProgress( float progress )
262 if( mAutoReverseEnabled )
264 if( mSpeedFactor > 0.0f )
266 value = 1.0f - 2.0f * std::abs( progress - 0.5f );
269 else if( mSpeedFactor < 0.0f )
271 value = 2.0f * std::abs( progress - 0.5f );
283 * Set the delay before the animator should take effect.
284 * The default is zero i.e. no delay.
285 * @param [in] seconds The delay in seconds.
287 void SetIntervalDelay(float seconds)
289 mIntervalDelaySeconds = seconds;
293 * Retrieve the delay before the animator should take effect.
294 * @return The delay in seconds.
296 float GetIntervalDelay() const
298 return mIntervalDelaySeconds;
302 * Set the alpha function for an animator.
303 * @param [in] alphaFunc The alpha function to apply to the animation progress.
305 void SetAlphaFunction(const AlphaFunction& alphaFunction)
307 mAlphaFunction = alphaFunction;
311 * Retrieve the alpha function of an animator.
312 * @return The function.
314 AlphaFunction GetAlphaFunction() const
316 return mAlphaFunction;
320 * Applies the alpha function to the specified progress
321 * @param[in] Current progress
322 * @return The progress after the alpha function has been aplied
324 float ApplyAlphaFunction( float progress ) const
326 float result = progress;
328 AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() );
329 if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION )
331 switch(mAlphaFunction.GetBuiltinFunction())
333 case AlphaFunction::DEFAULT:
334 case AlphaFunction::LINEAR:
338 case AlphaFunction::REVERSE:
340 result = 1.0f-progress;
343 case AlphaFunction::EASE_IN_SQUARE:
345 result = progress * progress;
348 case AlphaFunction::EASE_OUT_SQUARE:
350 result = 1.0f - (1.0f-progress) * (1.0f-progress);
353 case AlphaFunction::EASE_IN:
355 result = progress * progress * progress;
358 case AlphaFunction::EASE_OUT:
360 result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f;
363 case AlphaFunction::EASE_IN_OUT:
365 result = progress*progress*(3.0f-2.0f*progress);
368 case AlphaFunction::EASE_IN_SINE:
370 result = -1.0f * cosf(progress * Math::PI_2) + 1.0f;
373 case AlphaFunction::EASE_OUT_SINE:
375 result = sinf(progress * Math::PI_2);
378 case AlphaFunction::EASE_IN_OUT_SINE:
380 result = -0.5f * (cosf(Math::PI * progress) - 1.0f);
383 case AlphaFunction::BOUNCE:
385 result = sinf(progress * Math::PI);
388 case AlphaFunction::SIN:
390 result = 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
393 case AlphaFunction::EASE_OUT_BACK:
395 const float sqrt2 = 1.70158f;
397 result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
400 case AlphaFunction::COUNT:
406 else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION )
408 AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction();
411 result = customFunction(progress);
416 //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will
417 //be almost 0 or almost 1 respectively
418 if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) )
420 Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints();
422 static const float tolerance = 0.001f; //10 iteration max
424 //Perform a binary search on the curve
425 float lowerBound(0.0f);
426 float upperBound(1.0f);
427 float currentT(0.5f);
428 float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
429 while( fabsf( progress - currentX ) > tolerance )
431 if( progress > currentX )
433 lowerBound = currentT;
437 upperBound = currentT;
439 currentT = (upperBound+lowerBound)*0.5f;
440 currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
442 result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT);
450 * Whether to bake the animation if attached property owner is disconnected.
451 * Property is only baked if the animator is active.
452 * @param [in] action The disconnect action.
454 void SetDisconnectAction( Dali::Animation::EndAction action )
456 mDisconnectAction = action;
460 * Retrieve the disconnect action of an animator.
461 * @return The disconnect action.
463 Dali::Animation::EndAction GetDisconnectAction() const
465 return mDisconnectAction;
469 * Whether the animator is active or not.
470 * @param [in] active The new active state.
471 * @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
472 * @note When the property owner is disconnected, the active state is set to false.
474 void SetActive( bool active )
476 mAnimationPlaying = active;
480 * Whether the animator's target object is valid and on the stage.
481 * @return The enabled state.
483 bool IsEnabled() const
489 * @brief Sets the looping mode.
490 * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
492 void SetLoopingMode( bool loopingMode )
494 mAutoReverseEnabled = loopingMode;
498 * Returns wheter the target object of the animator is still valid
499 * or has been destroyed.
500 * @return True if animator is orphan, false otherwise *
501 * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
505 return (mPropertyOwner == nullptr);
509 * Update the scene object attached to the animator.
510 * @param[in] bufferIndex The buffer to animate.
511 * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
512 * @param[in] bake Bake.
514 void Update( BufferIndex bufferIndex, float progress, bool bake )
516 if( mLoopCount >= 0 )
518 // Update the progress value
519 progress = SetProgress( progress );
524 mPropertyOwner->SetUpdated( true );
527 float alpha = ApplyAlphaFunction( progress );
529 // PropertyType specific part
530 DoUpdate( bufferIndex, bake, alpha );
532 mCurrentProgress = progress;
536 * Type specific part of the animator
537 * @param bufferIndex index to use
538 * @param bake whether to bake or not
539 * @param alpha value from alpha based on progress
541 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0;
546 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
547 * @param[in] p0 First control point of the bezier curve
548 * @param[in] p1 Second control point of the bezier curve
549 * @param[in] t A floating point value between 0.0 and 1.0
550 * @return Value of the curve at progress t
552 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
555 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
558 LifecycleObserver* mLifecycleObserver;
559 PropertyOwner* mPropertyOwner;
560 AnimatorFunctionBase* mAnimatorFunction;
561 float mDurationSeconds;
562 float mIntervalDelaySeconds;
564 float mCurrentProgress;
568 AlphaFunction mAlphaFunction;
570 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
571 bool mAnimationPlaying:1; ///< whether disconnect has been applied while it's running.
572 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
573 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
574 bool mAutoReverseEnabled:1;
578 * An animator for a specific property type PropertyType.
580 template < typename PropertyType, typename PropertyAccessorType >
581 class Animator : public AnimatorBase
586 * Construct a new property animator.
587 * @param[in] property The animatable property; only valid while the Animator is attached.
588 * @param[in] animatorFunction The function used to animate the property.
589 * @param[in] alphaFunction The alpha function to apply.
590 * @param[in] timePeriod The time period of this animation.
591 * @return A newly allocated animator.
593 static AnimatorBase* New( const PropertyOwner& propertyOwner,
594 const PropertyBase& property,
595 AnimatorFunctionBase* animatorFunction,
596 AlphaFunction alphaFunction,
597 const TimePeriod& timePeriod )
599 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
600 return new Animator( const_cast<PropertyOwner*>( &propertyOwner ),
601 const_cast<PropertyBase*>( &property ),
608 * Virtual destructor.
615 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
617 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
619 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
621 // need to cast the return value in case property is integer
622 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
626 mPropertyAccessor.Bake( bufferIndex, result );
630 mPropertyAccessor.Set( bufferIndex, result );
637 * Private constructor; see also Animator::New().
639 Animator( PropertyOwner* propertyOwner,
640 PropertyBase* property,
641 AnimatorFunctionBase* animatorFunction,
642 AlphaFunction alphaFunction,
643 const TimePeriod& timePeriod )
644 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
645 mPropertyAccessor( property )
647 // WARNING - this object is created in the event-thread
648 // The scene-graph mPropertyOwner object cannot be observed here
652 Animator( const Animator& );
655 Animator& operator=( const Animator& );
659 PropertyAccessorType mPropertyAccessor;
666 * An animator for a specific property type PropertyType.
668 template <typename PropertyType, typename PropertyAccessorType>
669 class AnimatorTransformProperty : public AnimatorBase
674 * Construct a new property animator.
675 * @param[in] property The animatable property; only valid while the Animator is attached.
676 * @param[in] animatorFunction The function used to animate the property.
677 * @param[in] alphaFunction The alpha function to apply.
678 * @param[in] timePeriod The time period of this animation.
679 * @return A newly allocated animator.
681 static AnimatorBase* New( const PropertyOwner& propertyOwner,
682 const PropertyBase& property,
683 AnimatorFunctionBase* animatorFunction,
684 AlphaFunction alphaFunction,
685 const TimePeriod& timePeriod )
688 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
689 return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
690 const_cast<PropertyBase*>( &property ),
697 * Virtual destructor.
699 ~AnimatorTransformProperty() override
704 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
706 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
708 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
710 // need to cast the return value in case property is integer
711 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
715 mPropertyAccessor.Bake( bufferIndex, result );
719 mPropertyAccessor.Set( bufferIndex, result );
726 * Private constructor; see also Animator::New().
728 AnimatorTransformProperty( PropertyOwner* propertyOwner,
729 PropertyBase* property,
730 AnimatorFunctionBase* animatorFunction,
731 AlphaFunction alphaFunction,
732 const TimePeriod& timePeriod )
733 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
734 mPropertyAccessor( property )
736 // WARNING - this object is created in the event-thread
737 // The scene-graph mPropertyOwner object cannot be observed here
741 AnimatorTransformProperty() = delete;
742 AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
743 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
747 PropertyAccessorType mPropertyAccessor;
751 } // namespace SceneGraph
755 struct AnimateByInteger : public AnimatorFunctionBase
757 AnimateByInteger(const int& relativeValue)
758 : mRelative(relativeValue)
762 using AnimatorFunctionBase::operator();
763 float operator()(float alpha, const int32_t& property) override
765 // integers need to be correctly rounded
766 return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
772 struct AnimateToInteger : public AnimatorFunctionBase
774 AnimateToInteger(const int& targetValue)
775 : mTarget(targetValue)
779 using AnimatorFunctionBase::operator();
780 float operator()(float alpha, const int32_t& property) override
782 // integers need to be correctly rounded
783 return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
789 struct AnimateByFloat : public AnimatorFunctionBase
791 AnimateByFloat(const float& relativeValue)
792 : mRelative(relativeValue)
796 using AnimatorFunctionBase::operator();
797 float operator()(float alpha, const float& property) override
799 return float(property + mRelative * alpha);
805 struct AnimateToFloat : public AnimatorFunctionBase
807 AnimateToFloat(const float& targetValue)
808 : mTarget(targetValue)
812 using AnimatorFunctionBase::operator();
813 float operator()(float alpha, const float& property) override
815 return float(property + ((mTarget - property) * alpha));
821 struct AnimateByVector2 : public AnimatorFunctionBase
823 AnimateByVector2(const Vector2& relativeValue)
824 : mRelative(relativeValue)
828 using AnimatorFunctionBase::operator();
829 Vector2 operator()(float alpha, const Vector2& property) override
831 return Vector2(property + mRelative * alpha);
837 struct AnimateToVector2 : public AnimatorFunctionBase
839 AnimateToVector2(const Vector2& targetValue)
840 : mTarget(targetValue)
844 using AnimatorFunctionBase::operator();
845 Vector2 operator()(float alpha, const Vector2& property) override
847 return Vector2(property + ((mTarget - property) * alpha));
853 struct AnimateByVector3 : public AnimatorFunctionBase
855 AnimateByVector3(const Vector3& relativeValue)
856 : mRelative(relativeValue)
860 using AnimatorFunctionBase::operator();
861 Vector3 operator()(float alpha, const Vector3& property) override
863 return Vector3(property + mRelative * alpha);
869 struct AnimateToVector3 : public AnimatorFunctionBase
871 AnimateToVector3(const Vector3& targetValue)
872 : mTarget(targetValue)
876 using AnimatorFunctionBase::operator();
877 Vector3 operator()(float alpha, const Vector3& property) override
879 return Vector3(property + ((mTarget - property) * alpha));
885 struct AnimateByVector4 : public AnimatorFunctionBase
887 AnimateByVector4(const Vector4& relativeValue)
888 : mRelative(relativeValue)
892 using AnimatorFunctionBase::operator();
893 Vector4 operator()(float alpha, const Vector4& property) override
895 return Vector4(property + mRelative * alpha);
901 struct AnimateToVector4 : public AnimatorFunctionBase
903 AnimateToVector4(const Vector4& targetValue)
904 : mTarget(targetValue)
908 using AnimatorFunctionBase::operator();
909 Vector4 operator()(float alpha, const Vector4& property) override
911 return Vector4(property + ((mTarget - property) * alpha));
917 struct AnimateByOpacity : public AnimatorFunctionBase
919 AnimateByOpacity(const float& relativeValue)
920 : mRelative(relativeValue)
924 using AnimatorFunctionBase::operator();
925 Vector4 operator()(float alpha, const Vector4& property) override
927 Vector4 result(property);
928 result.a += mRelative * alpha;
936 struct AnimateToOpacity : public AnimatorFunctionBase
938 AnimateToOpacity(const float& targetValue)
939 : mTarget(targetValue)
943 using AnimatorFunctionBase::operator();
944 Vector4 operator()(float alpha, const Vector4& property) override
946 Vector4 result(property);
947 result.a = property.a + ((mTarget - property.a) * alpha);
955 struct AnimateByBoolean : public AnimatorFunctionBase
957 AnimateByBoolean(bool relativeValue)
958 : mRelative(relativeValue)
962 using AnimatorFunctionBase::operator();
963 bool operator()(float alpha, const bool& property) override
965 // Alpha is not useful here, just keeping to the same template as other update functors
966 return bool(alpha >= 1.0f ? (property || mRelative) : property);
972 struct AnimateToBoolean : public AnimatorFunctionBase
974 AnimateToBoolean(bool targetValue)
975 : mTarget(targetValue)
979 using AnimatorFunctionBase::operator();
980 bool operator()(float alpha, const bool& property) override
982 // Alpha is not useful here, just keeping to the same template as other update functors
983 return bool(alpha >= 1.0f ? mTarget : property);
989 struct RotateByAngleAxis : public AnimatorFunctionBase
991 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
992 : mAngleRadians( angleRadians ),
993 mAxis(axis.x, axis.y, axis.z)
997 using AnimatorFunctionBase::operator();
998 Quaternion operator()(float alpha, const Quaternion& rotation) override
1002 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1008 Radian mAngleRadians;
1012 struct RotateToQuaternion : public AnimatorFunctionBase
1014 RotateToQuaternion(const Quaternion& targetValue)
1015 : mTarget(targetValue)
1019 using AnimatorFunctionBase::operator();
1020 Quaternion operator()(float alpha, const Quaternion& rotation) override
1022 return Quaternion::Slerp(rotation, mTarget, alpha);
1029 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1031 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1032 : mKeyFrames(keyFrames)
1036 using AnimatorFunctionBase::operator();
1037 bool operator()(float progress, const bool& property) override
1039 if(mKeyFrames->IsActive(progress))
1041 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1046 KeyFrameBooleanPtr mKeyFrames;
1049 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1051 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1052 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1056 using AnimatorFunctionBase::operator();
1057 float operator()(float progress, const int32_t& property) override
1059 if(mKeyFrames->IsActive(progress))
1061 return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
1063 return static_cast<float>( property );
1066 KeyFrameIntegerPtr mKeyFrames;
1067 Interpolation mInterpolation;
1070 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1072 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1073 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1077 using AnimatorFunctionBase::operator();
1078 float operator()(float progress, const float& property) override
1080 if(mKeyFrames->IsActive(progress))
1082 return mKeyFrames->GetValue(progress, mInterpolation);
1087 KeyFrameNumberPtr mKeyFrames;
1088 Interpolation mInterpolation;
1091 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1093 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1094 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1098 using AnimatorFunctionBase::operator();
1099 Vector2 operator()(float progress, const Vector2& property) override
1101 if(mKeyFrames->IsActive(progress))
1103 return mKeyFrames->GetValue(progress, mInterpolation);
1108 KeyFrameVector2Ptr mKeyFrames;
1109 Interpolation mInterpolation;
1113 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1115 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1116 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1120 using AnimatorFunctionBase::operator();
1121 Vector3 operator()(float progress, const Vector3& property) override
1123 if(mKeyFrames->IsActive(progress))
1125 return mKeyFrames->GetValue(progress, mInterpolation);
1130 KeyFrameVector3Ptr mKeyFrames;
1131 Interpolation mInterpolation;
1134 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1136 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1137 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1141 using AnimatorFunctionBase::operator();
1142 Vector4 operator()(float progress, const Vector4& property) override
1144 if(mKeyFrames->IsActive(progress))
1146 return mKeyFrames->GetValue(progress, mInterpolation);
1151 KeyFrameVector4Ptr mKeyFrames;
1152 Interpolation mInterpolation;
1155 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1157 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1158 : mKeyFrames(keyFrames)
1162 using AnimatorFunctionBase::operator();
1163 Quaternion operator()(float progress, const Quaternion& property) override
1165 if(mKeyFrames->IsActive(progress))
1167 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1172 KeyFrameQuaternionPtr mKeyFrames;
1175 struct PathPositionFunctor : public AnimatorFunctionBase
1177 PathPositionFunctor( PathPtr path )
1182 using AnimatorFunctionBase::operator();
1183 Vector3 operator()(float progress, const Vector3& property) override
1185 Vector3 position(property);
1186 static_cast<void>( mPath->SamplePosition(progress, position) );
1193 struct PathRotationFunctor : public AnimatorFunctionBase
1195 PathRotationFunctor( PathPtr path, const Vector3& forward )
1199 mForward.Normalize();
1202 using AnimatorFunctionBase::operator();
1203 Quaternion operator()(float progress, const Quaternion& property) override
1206 if( mPath->SampleTangent(progress, tangent) )
1208 return Quaternion( mForward, tangent );
1220 } // namespace Internal
1224 #endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H