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.
22 #include <dali/public-api/animation/alpha-function.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/animation/time-period.h>
25 #include <dali/public-api/common/constants.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/quaternion.h>
28 #include <dali/public-api/math/radian.h>
29 #include <dali/devel-api/common/owner-container.h>
30 #include <dali/internal/event/animation/key-frames-impl.h>
31 #include <dali/internal/event/animation/path-impl.h>
32 #include <dali/internal/update/nodes/node.h>
33 #include <dali/internal/update/common/property-base.h>
34 #include <dali/internal/update/animation/property-accessor.h>
35 #include <dali/integration-api/debug.h>
43 using Interpolation = Dali::Animation::Interpolation;
46 * AnimatorFunction base class.
47 * Needs to be declared first so AnimatorBase knows about it's destructor
48 * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
50 struct AnimatorFunctionBase
55 AnimatorFunctionBase() {}
58 * Virtual destructor (Intended as base class)
60 virtual ~AnimatorFunctionBase() {}
62 ///Stub "()" operators.
63 virtual bool operator()(float progress, const bool& property)
68 virtual float operator()(float progress, const int32_t& property)
70 return static_cast<float>( property );
73 virtual float operator()(float progress, const float& property)
78 virtual Vector2 operator()(float progress, const Vector2& property)
83 virtual Vector3 operator()(float progress, const Vector3& property)
88 virtual Vector4 operator()(float progress, const Vector4& property)
93 virtual Quaternion operator()(float progress, const Quaternion& property)
103 * An abstract base class for Animators, which can be added to scene graph animations.
104 * Each animator changes a single property of an object in the scene graph.
106 class AnimatorBase : public PropertyOwner::Observer
110 using AlphaFunc = float (*)(float progress); ///< Definition of an alpha function
113 * Observer to determine when the animator is no longer present
115 class LifecycleObserver
119 * Called shortly before the animator is destroyed.
121 virtual void ObjectDestroyed() = 0;
125 * Virtual destructor, no deletion through this interface
127 virtual ~LifecycleObserver() = default;
134 AnimatorBase( PropertyOwner* propertyOwner,
135 AnimatorFunctionBase* animatorFunction,
136 AlphaFunction alphaFunction,
137 const TimePeriod& timePeriod )
138 : mLifecycleObserver( nullptr ),
139 mPropertyOwner( propertyOwner ),
140 mAnimatorFunction( animatorFunction ),
141 mDurationSeconds( timePeriod.durationSeconds ),
142 mIntervalDelaySeconds( timePeriod.delaySeconds ),
143 mSpeedFactor( 1.0f ),
144 mCurrentProgress( 0.f ),
146 mAlphaFunction( alphaFunction ),
147 mDisconnectAction( Dali::Animation::BakeFinal ),
148 mAnimationPlaying( false ),
150 mConnectedToSceneGraph( false ),
151 mAutoReverseEnabled( false )
156 * Virtual destructor.
158 virtual ~AnimatorBase()
160 delete mAnimatorFunction;
161 if (mPropertyOwner && mConnectedToSceneGraph)
163 mPropertyOwner->RemoveObserver(*this);
165 if( mLifecycleObserver != nullptr )
167 mLifecycleObserver->ObjectDestroyed();
171 void AddLifecycleObserver( LifecycleObserver& observer )
173 mLifecycleObserver = &observer;
176 void RemoveLifecycleObserver( LifecycleObserver& observer )
178 mLifecycleObserver = nullptr;
181 private: // From PropertyOwner::Observer
184 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected( PropertyOwner& owner )
186 void PropertyOwnerConnected( PropertyOwner& owner ) override final
192 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
194 void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) override final
196 // If we are active, then bake the value if required
197 if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
199 // Bake to target-value if BakeFinal, otherwise bake current value
200 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
207 * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed( PropertyOwner& owner )
209 void PropertyOwnerDestroyed( PropertyOwner& owner ) override final
211 mPropertyOwner = nullptr;
216 * Called when Animator is added to the scene-graph in update-thread.
218 void ConnectToSceneGraph()
220 mConnectedToSceneGraph = true;
221 mPropertyOwner->AddObserver(*this);
225 * Set the duration of the animator.
226 * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
227 * @param [in] seconds Duration in seconds.
229 void SetDuration(float seconds)
231 DALI_ASSERT_DEBUG(seconds >= 0.0f);
233 mDurationSeconds = seconds;
237 * Retrieve the duration of the animator.
238 * @return The duration in seconds.
240 float GetDuration() const
242 return mDurationSeconds;
245 void SetSpeedFactor( float factor )
247 mSpeedFactor = factor;
250 void SetLoopCount(int32_t loopCount)
252 mLoopCount = loopCount;
255 float SetProgress( float progress )
259 if( mAutoReverseEnabled )
261 if( mSpeedFactor > 0.0f )
263 value = 1.0f - 2.0f * std::abs( progress - 0.5f );
266 else if( mSpeedFactor < 0.0f )
268 value = 2.0f * std::abs( progress - 0.5f );
280 * Set the delay before the animator should take effect.
281 * The default is zero i.e. no delay.
282 * @param [in] seconds The delay in seconds.
284 void SetIntervalDelay(float seconds)
286 mIntervalDelaySeconds = seconds;
290 * Retrieve the delay before the animator should take effect.
291 * @return The delay in seconds.
293 float GetIntervalDelay() const
295 return mIntervalDelaySeconds;
299 * Set the alpha function for an animator.
300 * @param [in] alphaFunc The alpha function to apply to the animation progress.
302 void SetAlphaFunction(const AlphaFunction& alphaFunction)
304 mAlphaFunction = alphaFunction;
308 * Retrieve the alpha function of an animator.
309 * @return The function.
311 AlphaFunction GetAlphaFunction() const
313 return mAlphaFunction;
317 * Applies the alpha function to the specified progress
318 * @param[in] Current progress
319 * @return The progress after the alpha function has been aplied
321 float ApplyAlphaFunction( float progress ) const
323 float result = progress;
325 AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() );
326 if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION )
328 switch(mAlphaFunction.GetBuiltinFunction())
330 case AlphaFunction::DEFAULT:
331 case AlphaFunction::LINEAR:
335 case AlphaFunction::REVERSE:
337 result = 1.0f-progress;
340 case AlphaFunction::EASE_IN_SQUARE:
342 result = progress * progress;
345 case AlphaFunction::EASE_OUT_SQUARE:
347 result = 1.0f - (1.0f-progress) * (1.0f-progress);
350 case AlphaFunction::EASE_IN:
352 result = progress * progress * progress;
355 case AlphaFunction::EASE_OUT:
357 result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f;
360 case AlphaFunction::EASE_IN_OUT:
362 result = progress*progress*(3.0f-2.0f*progress);
365 case AlphaFunction::EASE_IN_SINE:
367 result = -1.0f * cosf(progress * Math::PI_2) + 1.0f;
370 case AlphaFunction::EASE_OUT_SINE:
372 result = sinf(progress * Math::PI_2);
375 case AlphaFunction::EASE_IN_OUT_SINE:
377 result = -0.5f * (cosf(Math::PI * progress) - 1.0f);
380 case AlphaFunction::BOUNCE:
382 result = sinf(progress * Math::PI);
385 case AlphaFunction::SIN:
387 result = 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
390 case AlphaFunction::EASE_OUT_BACK:
392 const float sqrt2 = 1.70158f;
394 result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
397 case AlphaFunction::COUNT:
403 else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION )
405 AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction();
408 result = customFunction(progress);
413 //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will
414 //be almost 0 or almost 1 respectively
415 if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) )
417 Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints();
419 static const float tolerance = 0.001f; //10 iteration max
421 //Perform a binary search on the curve
422 float lowerBound(0.0f);
423 float upperBound(1.0f);
424 float currentT(0.5f);
425 float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
426 while( fabsf( progress - currentX ) > tolerance )
428 if( progress > currentX )
430 lowerBound = currentT;
434 upperBound = currentT;
436 currentT = (upperBound+lowerBound)*0.5f;
437 currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
439 result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT);
447 * Whether to bake the animation if attached property owner is disconnected.
448 * Property is only baked if the animator is active.
449 * @param [in] action The disconnect action.
451 void SetDisconnectAction( Dali::Animation::EndAction action )
453 mDisconnectAction = action;
457 * Retrieve the disconnect action of an animator.
458 * @return The disconnect action.
460 Dali::Animation::EndAction GetDisconnectAction() const
462 return mDisconnectAction;
466 * Whether the animator is active or not.
467 * @param [in] active The new active state.
468 * @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
469 * @note When the property owner is disconnected, the active state is set to false.
471 void SetActive( bool active )
473 mAnimationPlaying = active;
477 * Whether the animator's target object is valid and on the stage.
478 * @return The enabled state.
480 bool IsEnabled() const
486 * @brief Sets the looping mode.
487 * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
489 void SetLoopingMode( bool loopingMode )
491 mAutoReverseEnabled = loopingMode;
495 * Returns wheter the target object of the animator is still valid
496 * or has been destroyed.
497 * @return True if animator is orphan, false otherwise *
498 * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
502 return (mPropertyOwner == nullptr);
506 * Update the scene object attached to the animator.
507 * @param[in] bufferIndex The buffer to animate.
508 * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
509 * @param[in] bake Bake.
511 void Update( BufferIndex bufferIndex, float progress, bool bake )
513 if( mLoopCount >= 0 )
515 // Update the progress value
516 progress = SetProgress( progress );
519 float alpha = ApplyAlphaFunction( progress );
521 // PropertyType specific part
522 DoUpdate( bufferIndex, bake, alpha );
524 mCurrentProgress = progress;
528 * Type specific part of the animator
529 * @param bufferIndex index to use
530 * @param bake whether to bake or not
531 * @param alpha value from alpha based on progress
533 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0;
538 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
539 * @param[in] p0 First control point of the bezier curve
540 * @param[in] p1 Second control point of the bezier curve
541 * @param[in] t A floating point value between 0.0 and 1.0
542 * @return Value of the curve at progress t
544 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
547 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
550 LifecycleObserver* mLifecycleObserver;
551 PropertyOwner* mPropertyOwner;
552 AnimatorFunctionBase* mAnimatorFunction;
553 float mDurationSeconds;
554 float mIntervalDelaySeconds;
556 float mCurrentProgress;
560 AlphaFunction mAlphaFunction;
562 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
563 bool mAnimationPlaying:1; ///< whether disconnect has been applied while it's running.
564 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
565 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
566 bool mAutoReverseEnabled:1;
570 * An animator for a specific property type PropertyType.
572 template < typename PropertyType, typename PropertyAccessorType >
573 class Animator : public AnimatorBase
578 * Construct a new property animator.
579 * @param[in] property The animatable property; only valid while the Animator is attached.
580 * @param[in] animatorFunction The function used to animate the property.
581 * @param[in] alphaFunction The alpha function to apply.
582 * @param[in] timePeriod The time period of this animation.
583 * @return A newly allocated animator.
585 static AnimatorBase* New( const PropertyOwner& propertyOwner,
586 const PropertyBase& property,
587 AnimatorFunctionBase* animatorFunction,
588 AlphaFunction alphaFunction,
589 const TimePeriod& timePeriod )
591 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
592 return new Animator( const_cast<PropertyOwner*>( &propertyOwner ),
593 const_cast<PropertyBase*>( &property ),
600 * Virtual destructor.
607 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
609 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
611 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
613 // need to cast the return value in case property is integer
614 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
618 mPropertyAccessor.Bake( bufferIndex, result );
622 mPropertyAccessor.Set( bufferIndex, result );
629 * Private constructor; see also Animator::New().
631 Animator( PropertyOwner* propertyOwner,
632 PropertyBase* property,
633 AnimatorFunctionBase* animatorFunction,
634 AlphaFunction alphaFunction,
635 const TimePeriod& timePeriod )
636 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
637 mPropertyAccessor( property )
639 // WARNING - this object is created in the event-thread
640 // The scene-graph mPropertyOwner object cannot be observed here
644 Animator( const Animator& );
647 Animator& operator=( const Animator& );
651 PropertyAccessorType mPropertyAccessor;
658 * An animator for a specific property type PropertyType.
660 template <typename PropertyType, typename PropertyAccessorType>
661 class AnimatorTransformProperty : public AnimatorBase
666 * Construct a new property animator.
667 * @param[in] property The animatable property; only valid while the Animator is attached.
668 * @param[in] animatorFunction The function used to animate the property.
669 * @param[in] alphaFunction The alpha function to apply.
670 * @param[in] timePeriod The time period of this animation.
671 * @return A newly allocated animator.
673 static AnimatorBase* New( const PropertyOwner& propertyOwner,
674 const PropertyBase& property,
675 AnimatorFunctionBase* animatorFunction,
676 AlphaFunction alphaFunction,
677 const TimePeriod& timePeriod )
680 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
681 return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
682 const_cast<PropertyBase*>( &property ),
689 * Virtual destructor.
691 virtual ~AnimatorTransformProperty()
696 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
698 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
700 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
702 // need to cast the return value in case property is integer
703 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
707 mPropertyAccessor.Bake( bufferIndex, result );
711 mPropertyAccessor.Set( bufferIndex, result );
718 * Private constructor; see also Animator::New().
720 AnimatorTransformProperty( PropertyOwner* propertyOwner,
721 PropertyBase* property,
722 AnimatorFunctionBase* animatorFunction,
723 AlphaFunction alphaFunction,
724 const TimePeriod& timePeriod )
725 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
726 mPropertyAccessor( property )
728 // WARNING - this object is created in the event-thread
729 // The scene-graph mPropertyOwner object cannot be observed here
733 AnimatorTransformProperty() = delete;
734 AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
735 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
739 PropertyAccessorType mPropertyAccessor;
743 } // namespace SceneGraph
747 struct AnimateByInteger : public AnimatorFunctionBase
749 AnimateByInteger(const int& relativeValue)
750 : mRelative(relativeValue)
754 using AnimatorFunctionBase::operator();
755 float operator()(float alpha, const int32_t& property)
757 // integers need to be correctly rounded
758 return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
764 struct AnimateToInteger : public AnimatorFunctionBase
766 AnimateToInteger(const int& targetValue)
767 : mTarget(targetValue)
771 using AnimatorFunctionBase::operator();
772 float operator()(float alpha, const int32_t& property)
774 // integers need to be correctly rounded
775 return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
781 struct AnimateByFloat : public AnimatorFunctionBase
783 AnimateByFloat(const float& relativeValue)
784 : mRelative(relativeValue)
788 using AnimatorFunctionBase::operator();
789 float operator()(float alpha, const float& property)
791 return float(property + mRelative * alpha);
797 struct AnimateToFloat : public AnimatorFunctionBase
799 AnimateToFloat(const float& targetValue)
800 : mTarget(targetValue)
804 using AnimatorFunctionBase::operator();
805 float operator()(float alpha, const float& property)
807 return float(property + ((mTarget - property) * alpha));
813 struct AnimateByVector2 : public AnimatorFunctionBase
815 AnimateByVector2(const Vector2& relativeValue)
816 : mRelative(relativeValue)
820 using AnimatorFunctionBase::operator();
821 Vector2 operator()(float alpha, const Vector2& property)
823 return Vector2(property + mRelative * alpha);
829 struct AnimateToVector2 : public AnimatorFunctionBase
831 AnimateToVector2(const Vector2& targetValue)
832 : mTarget(targetValue)
836 using AnimatorFunctionBase::operator();
837 Vector2 operator()(float alpha, const Vector2& property)
839 return Vector2(property + ((mTarget - property) * alpha));
845 struct AnimateByVector3 : public AnimatorFunctionBase
847 AnimateByVector3(const Vector3& relativeValue)
848 : mRelative(relativeValue)
852 using AnimatorFunctionBase::operator();
853 Vector3 operator()(float alpha, const Vector3& property)
855 return Vector3(property + mRelative * alpha);
861 struct AnimateToVector3 : public AnimatorFunctionBase
863 AnimateToVector3(const Vector3& targetValue)
864 : mTarget(targetValue)
868 using AnimatorFunctionBase::operator();
869 Vector3 operator()(float alpha, const Vector3& property)
871 return Vector3(property + ((mTarget - property) * alpha));
877 struct AnimateByVector4 : public AnimatorFunctionBase
879 AnimateByVector4(const Vector4& relativeValue)
880 : mRelative(relativeValue)
884 using AnimatorFunctionBase::operator();
885 Vector4 operator()(float alpha, const Vector4& property)
887 return Vector4(property + mRelative * alpha);
893 struct AnimateToVector4 : public AnimatorFunctionBase
895 AnimateToVector4(const Vector4& targetValue)
896 : mTarget(targetValue)
900 using AnimatorFunctionBase::operator();
901 Vector4 operator()(float alpha, const Vector4& property)
903 return Vector4(property + ((mTarget - property) * alpha));
909 struct AnimateByOpacity : public AnimatorFunctionBase
911 AnimateByOpacity(const float& relativeValue)
912 : mRelative(relativeValue)
916 using AnimatorFunctionBase::operator();
917 Vector4 operator()(float alpha, const Vector4& property)
919 Vector4 result(property);
920 result.a += mRelative * alpha;
928 struct AnimateToOpacity : public AnimatorFunctionBase
930 AnimateToOpacity(const float& targetValue)
931 : mTarget(targetValue)
935 using AnimatorFunctionBase::operator();
936 Vector4 operator()(float alpha, const Vector4& property)
938 Vector4 result(property);
939 result.a = property.a + ((mTarget - property.a) * alpha);
947 struct AnimateByBoolean : public AnimatorFunctionBase
949 AnimateByBoolean(bool relativeValue)
950 : mRelative(relativeValue)
954 using AnimatorFunctionBase::operator();
955 bool operator()(float alpha, const bool& property)
957 // Alpha is not useful here, just keeping to the same template as other update functors
958 return bool(alpha >= 1.0f ? (property || mRelative) : property);
964 struct AnimateToBoolean : public AnimatorFunctionBase
966 AnimateToBoolean(bool targetValue)
967 : mTarget(targetValue)
971 using AnimatorFunctionBase::operator();
972 bool operator()(float alpha, const bool& property)
974 // Alpha is not useful here, just keeping to the same template as other update functors
975 return bool(alpha >= 1.0f ? mTarget : property);
981 struct RotateByAngleAxis : public AnimatorFunctionBase
983 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
984 : mAngleRadians( angleRadians ),
985 mAxis(axis.x, axis.y, axis.z)
989 using AnimatorFunctionBase::operator();
990 Quaternion operator()(float alpha, const Quaternion& rotation)
994 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1000 Radian mAngleRadians;
1004 struct RotateToQuaternion : public AnimatorFunctionBase
1006 RotateToQuaternion(const Quaternion& targetValue)
1007 : mTarget(targetValue)
1011 using AnimatorFunctionBase::operator();
1012 Quaternion operator()(float alpha, const Quaternion& rotation)
1014 return Quaternion::Slerp(rotation, mTarget, alpha);
1021 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1023 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1024 : mKeyFrames(keyFrames)
1028 using AnimatorFunctionBase::operator();
1029 bool operator()(float progress, const bool& property)
1031 if(mKeyFrames->IsActive(progress))
1033 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1038 KeyFrameBooleanPtr mKeyFrames;
1041 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1043 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1044 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1048 using AnimatorFunctionBase::operator();
1049 float operator()(float progress, const int32_t& property)
1051 if(mKeyFrames->IsActive(progress))
1053 return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
1055 return static_cast<float>( property );
1058 KeyFrameIntegerPtr mKeyFrames;
1059 Interpolation mInterpolation;
1062 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1064 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1065 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1069 using AnimatorFunctionBase::operator();
1070 float operator()(float progress, const float& property)
1072 if(mKeyFrames->IsActive(progress))
1074 return mKeyFrames->GetValue(progress, mInterpolation);
1079 KeyFrameNumberPtr mKeyFrames;
1080 Interpolation mInterpolation;
1083 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1085 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1086 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1090 using AnimatorFunctionBase::operator();
1091 Vector2 operator()(float progress, const Vector2& property)
1093 if(mKeyFrames->IsActive(progress))
1095 return mKeyFrames->GetValue(progress, mInterpolation);
1100 KeyFrameVector2Ptr mKeyFrames;
1101 Interpolation mInterpolation;
1105 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1107 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1108 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1112 using AnimatorFunctionBase::operator();
1113 Vector3 operator()(float progress, const Vector3& property)
1115 if(mKeyFrames->IsActive(progress))
1117 return mKeyFrames->GetValue(progress, mInterpolation);
1122 KeyFrameVector3Ptr mKeyFrames;
1123 Interpolation mInterpolation;
1126 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1128 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1129 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1133 using AnimatorFunctionBase::operator();
1134 Vector4 operator()(float progress, const Vector4& property)
1136 if(mKeyFrames->IsActive(progress))
1138 return mKeyFrames->GetValue(progress, mInterpolation);
1143 KeyFrameVector4Ptr mKeyFrames;
1144 Interpolation mInterpolation;
1147 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1149 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1150 : mKeyFrames(keyFrames)
1154 using AnimatorFunctionBase::operator();
1155 Quaternion operator()(float progress, const Quaternion& property)
1157 if(mKeyFrames->IsActive(progress))
1159 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1164 KeyFrameQuaternionPtr mKeyFrames;
1167 struct PathPositionFunctor : public AnimatorFunctionBase
1169 PathPositionFunctor( PathPtr path )
1174 using AnimatorFunctionBase::operator();
1175 Vector3 operator()(float progress, const Vector3& property)
1177 Vector3 position(property);
1178 static_cast<void>( mPath->SamplePosition(progress, position) );
1185 struct PathRotationFunctor : public AnimatorFunctionBase
1187 PathRotationFunctor( PathPtr path, const Vector3& forward )
1191 mForward.Normalize();
1194 using AnimatorFunctionBase::operator();
1195 Quaternion operator()(float progress, const Quaternion& property)
1198 if( mPath->SampleTangent(progress, tangent) )
1200 return Quaternion( mForward, tangent );
1212 } // namespace Internal
1216 #endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H