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::BakeFinal ),
151 mAnimationPlaying( false ),
153 mConnectedToSceneGraph( false ),
154 mAutoReverseEnabled( false )
159 * Virtual destructor.
161 virtual ~AnimatorBase()
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 ) override final
195 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
197 void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) override 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 ) override 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 );
522 float alpha = ApplyAlphaFunction( progress );
524 // PropertyType specific part
525 DoUpdate( bufferIndex, bake, alpha );
527 mCurrentProgress = progress;
531 * Type specific part of the animator
532 * @param bufferIndex index to use
533 * @param bake whether to bake or not
534 * @param alpha value from alpha based on progress
536 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0;
541 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
542 * @param[in] p0 First control point of the bezier curve
543 * @param[in] p1 Second control point of the bezier curve
544 * @param[in] t A floating point value between 0.0 and 1.0
545 * @return Value of the curve at progress t
547 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
550 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
553 LifecycleObserver* mLifecycleObserver;
554 PropertyOwner* mPropertyOwner;
555 AnimatorFunctionBase* mAnimatorFunction;
556 float mDurationSeconds;
557 float mIntervalDelaySeconds;
559 float mCurrentProgress;
563 AlphaFunction mAlphaFunction;
565 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
566 bool mAnimationPlaying:1; ///< whether disconnect has been applied while it's running.
567 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
568 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
569 bool mAutoReverseEnabled:1;
573 * An animator for a specific property type PropertyType.
575 template < typename PropertyType, typename PropertyAccessorType >
576 class Animator : public AnimatorBase
581 * Construct a new property animator.
582 * @param[in] property The animatable property; only valid while the Animator is attached.
583 * @param[in] animatorFunction The function used to animate the property.
584 * @param[in] alphaFunction The alpha function to apply.
585 * @param[in] timePeriod The time period of this animation.
586 * @return A newly allocated animator.
588 static AnimatorBase* New( const PropertyOwner& propertyOwner,
589 const PropertyBase& property,
590 AnimatorFunctionBase* animatorFunction,
591 AlphaFunction alphaFunction,
592 const TimePeriod& timePeriod )
594 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
595 return new Animator( const_cast<PropertyOwner*>( &propertyOwner ),
596 const_cast<PropertyBase*>( &property ),
603 * Virtual destructor.
610 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
612 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
614 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
616 // need to cast the return value in case property is integer
617 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
621 mPropertyAccessor.Bake( bufferIndex, result );
625 mPropertyAccessor.Set( bufferIndex, result );
632 * Private constructor; see also Animator::New().
634 Animator( PropertyOwner* propertyOwner,
635 PropertyBase* property,
636 AnimatorFunctionBase* animatorFunction,
637 AlphaFunction alphaFunction,
638 const TimePeriod& timePeriod )
639 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
640 mPropertyAccessor( property )
642 // WARNING - this object is created in the event-thread
643 // The scene-graph mPropertyOwner object cannot be observed here
647 Animator( const Animator& );
650 Animator& operator=( const Animator& );
654 PropertyAccessorType mPropertyAccessor;
661 * An animator for a specific property type PropertyType.
663 template <typename PropertyType, typename PropertyAccessorType>
664 class AnimatorTransformProperty : public AnimatorBase
669 * Construct a new property animator.
670 * @param[in] property The animatable property; only valid while the Animator is attached.
671 * @param[in] animatorFunction The function used to animate the property.
672 * @param[in] alphaFunction The alpha function to apply.
673 * @param[in] timePeriod The time period of this animation.
674 * @return A newly allocated animator.
676 static AnimatorBase* New( const PropertyOwner& propertyOwner,
677 const PropertyBase& property,
678 AnimatorFunctionBase* animatorFunction,
679 AlphaFunction alphaFunction,
680 const TimePeriod& timePeriod )
683 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
684 return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
685 const_cast<PropertyBase*>( &property ),
692 * Virtual destructor.
694 virtual ~AnimatorTransformProperty()
699 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
701 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
703 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
705 // need to cast the return value in case property is integer
706 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
710 mPropertyAccessor.Bake( bufferIndex, result );
714 mPropertyAccessor.Set( bufferIndex, result );
721 * Private constructor; see also Animator::New().
723 AnimatorTransformProperty( PropertyOwner* propertyOwner,
724 PropertyBase* property,
725 AnimatorFunctionBase* animatorFunction,
726 AlphaFunction alphaFunction,
727 const TimePeriod& timePeriod )
728 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
729 mPropertyAccessor( property )
731 // WARNING - this object is created in the event-thread
732 // The scene-graph mPropertyOwner object cannot be observed here
736 AnimatorTransformProperty() = delete;
737 AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
738 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
742 PropertyAccessorType mPropertyAccessor;
746 } // namespace SceneGraph
750 struct AnimateByInteger : public AnimatorFunctionBase
752 AnimateByInteger(const int& relativeValue)
753 : mRelative(relativeValue)
757 using AnimatorFunctionBase::operator();
758 float operator()(float alpha, const int32_t& property)
760 // integers need to be correctly rounded
761 return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
767 struct AnimateToInteger : public AnimatorFunctionBase
769 AnimateToInteger(const int& targetValue)
770 : mTarget(targetValue)
774 using AnimatorFunctionBase::operator();
775 float operator()(float alpha, const int32_t& property)
777 // integers need to be correctly rounded
778 return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
784 struct AnimateByFloat : public AnimatorFunctionBase
786 AnimateByFloat(const float& relativeValue)
787 : mRelative(relativeValue)
791 using AnimatorFunctionBase::operator();
792 float operator()(float alpha, const float& property)
794 return float(property + mRelative * alpha);
800 struct AnimateToFloat : public AnimatorFunctionBase
802 AnimateToFloat(const float& targetValue)
803 : mTarget(targetValue)
807 using AnimatorFunctionBase::operator();
808 float operator()(float alpha, const float& property)
810 return float(property + ((mTarget - property) * alpha));
816 struct AnimateByVector2 : public AnimatorFunctionBase
818 AnimateByVector2(const Vector2& relativeValue)
819 : mRelative(relativeValue)
823 using AnimatorFunctionBase::operator();
824 Vector2 operator()(float alpha, const Vector2& property)
826 return Vector2(property + mRelative * alpha);
832 struct AnimateToVector2 : public AnimatorFunctionBase
834 AnimateToVector2(const Vector2& targetValue)
835 : mTarget(targetValue)
839 using AnimatorFunctionBase::operator();
840 Vector2 operator()(float alpha, const Vector2& property)
842 return Vector2(property + ((mTarget - property) * alpha));
848 struct AnimateByVector3 : public AnimatorFunctionBase
850 AnimateByVector3(const Vector3& relativeValue)
851 : mRelative(relativeValue)
855 using AnimatorFunctionBase::operator();
856 Vector3 operator()(float alpha, const Vector3& property)
858 return Vector3(property + mRelative * alpha);
864 struct AnimateToVector3 : public AnimatorFunctionBase
866 AnimateToVector3(const Vector3& targetValue)
867 : mTarget(targetValue)
871 using AnimatorFunctionBase::operator();
872 Vector3 operator()(float alpha, const Vector3& property)
874 return Vector3(property + ((mTarget - property) * alpha));
880 struct AnimateByVector4 : public AnimatorFunctionBase
882 AnimateByVector4(const Vector4& relativeValue)
883 : mRelative(relativeValue)
887 using AnimatorFunctionBase::operator();
888 Vector4 operator()(float alpha, const Vector4& property)
890 return Vector4(property + mRelative * alpha);
896 struct AnimateToVector4 : public AnimatorFunctionBase
898 AnimateToVector4(const Vector4& targetValue)
899 : mTarget(targetValue)
903 using AnimatorFunctionBase::operator();
904 Vector4 operator()(float alpha, const Vector4& property)
906 return Vector4(property + ((mTarget - property) * alpha));
912 struct AnimateByOpacity : public AnimatorFunctionBase
914 AnimateByOpacity(const float& relativeValue)
915 : mRelative(relativeValue)
919 using AnimatorFunctionBase::operator();
920 Vector4 operator()(float alpha, const Vector4& property)
922 Vector4 result(property);
923 result.a += mRelative * alpha;
931 struct AnimateToOpacity : public AnimatorFunctionBase
933 AnimateToOpacity(const float& targetValue)
934 : mTarget(targetValue)
938 using AnimatorFunctionBase::operator();
939 Vector4 operator()(float alpha, const Vector4& property)
941 Vector4 result(property);
942 result.a = property.a + ((mTarget - property.a) * alpha);
950 struct AnimateByBoolean : public AnimatorFunctionBase
952 AnimateByBoolean(bool relativeValue)
953 : mRelative(relativeValue)
957 using AnimatorFunctionBase::operator();
958 bool operator()(float alpha, const bool& property)
960 // Alpha is not useful here, just keeping to the same template as other update functors
961 return bool(alpha >= 1.0f ? (property || mRelative) : property);
967 struct AnimateToBoolean : public AnimatorFunctionBase
969 AnimateToBoolean(bool targetValue)
970 : mTarget(targetValue)
974 using AnimatorFunctionBase::operator();
975 bool operator()(float alpha, const bool& property)
977 // Alpha is not useful here, just keeping to the same template as other update functors
978 return bool(alpha >= 1.0f ? mTarget : property);
984 struct RotateByAngleAxis : public AnimatorFunctionBase
986 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
987 : mAngleRadians( angleRadians ),
988 mAxis(axis.x, axis.y, axis.z)
992 using AnimatorFunctionBase::operator();
993 Quaternion operator()(float alpha, const Quaternion& rotation)
997 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1003 Radian mAngleRadians;
1007 struct RotateToQuaternion : public AnimatorFunctionBase
1009 RotateToQuaternion(const Quaternion& targetValue)
1010 : mTarget(targetValue)
1014 using AnimatorFunctionBase::operator();
1015 Quaternion operator()(float alpha, const Quaternion& rotation)
1017 return Quaternion::Slerp(rotation, mTarget, alpha);
1024 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1026 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1027 : mKeyFrames(keyFrames)
1031 using AnimatorFunctionBase::operator();
1032 bool operator()(float progress, const bool& property)
1034 if(mKeyFrames->IsActive(progress))
1036 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1041 KeyFrameBooleanPtr mKeyFrames;
1044 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1046 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1047 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1051 using AnimatorFunctionBase::operator();
1052 float operator()(float progress, const int32_t& property)
1054 if(mKeyFrames->IsActive(progress))
1056 return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
1058 return static_cast<float>( property );
1061 KeyFrameIntegerPtr mKeyFrames;
1062 Interpolation mInterpolation;
1065 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1067 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1068 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1072 using AnimatorFunctionBase::operator();
1073 float operator()(float progress, const float& property)
1075 if(mKeyFrames->IsActive(progress))
1077 return mKeyFrames->GetValue(progress, mInterpolation);
1082 KeyFrameNumberPtr mKeyFrames;
1083 Interpolation mInterpolation;
1086 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1088 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1089 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1093 using AnimatorFunctionBase::operator();
1094 Vector2 operator()(float progress, const Vector2& property)
1096 if(mKeyFrames->IsActive(progress))
1098 return mKeyFrames->GetValue(progress, mInterpolation);
1103 KeyFrameVector2Ptr mKeyFrames;
1104 Interpolation mInterpolation;
1108 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1110 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1111 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1115 using AnimatorFunctionBase::operator();
1116 Vector3 operator()(float progress, const Vector3& property)
1118 if(mKeyFrames->IsActive(progress))
1120 return mKeyFrames->GetValue(progress, mInterpolation);
1125 KeyFrameVector3Ptr mKeyFrames;
1126 Interpolation mInterpolation;
1129 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1131 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1132 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1136 using AnimatorFunctionBase::operator();
1137 Vector4 operator()(float progress, const Vector4& property)
1139 if(mKeyFrames->IsActive(progress))
1141 return mKeyFrames->GetValue(progress, mInterpolation);
1146 KeyFrameVector4Ptr mKeyFrames;
1147 Interpolation mInterpolation;
1150 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1152 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1153 : mKeyFrames(keyFrames)
1157 using AnimatorFunctionBase::operator();
1158 Quaternion operator()(float progress, const Quaternion& property)
1160 if(mKeyFrames->IsActive(progress))
1162 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1167 KeyFrameQuaternionPtr mKeyFrames;
1170 struct PathPositionFunctor : public AnimatorFunctionBase
1172 PathPositionFunctor( PathPtr path )
1177 using AnimatorFunctionBase::operator();
1178 Vector3 operator()(float progress, const Vector3& property)
1180 Vector3 position(property);
1181 static_cast<void>( mPath->SamplePosition(progress, position) );
1188 struct PathRotationFunctor : public AnimatorFunctionBase
1190 PathRotationFunctor( PathPtr path, const Vector3& forward )
1194 mForward.Normalize();
1197 using AnimatorFunctionBase::operator();
1198 Quaternion operator()(float progress, const Quaternion& property)
1201 if( mPath->SampleTangent(progress, tangent) )
1203 return Quaternion( mForward, tangent );
1215 } // namespace Internal
1219 #endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H