1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
5 * Copyright (c) 2017 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/devel-api/common/owner-container.h>
23 #include <dali/internal/event/animation/key-frames-impl.h>
24 #include <dali/internal/event/animation/path-impl.h>
25 #include <dali/internal/update/nodes/node.h>
26 #include <dali/internal/update/common/property-base.h>
27 #include <dali/public-api/animation/alpha-function.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/animation/time-period.h>
30 #include <dali/public-api/common/constants.h>
31 #include <dali/public-api/common/dali-common.h>
32 #include <dali/public-api/math/quaternion.h>
33 #include <dali/public-api/math/radian.h>
34 #include <dali/internal/update/animation/property-accessor.h>
35 #include <dali/integration-api/debug.h>
43 typedef Dali::Animation::Interpolation Interpolation;
45 struct AnimatorFunctionBase;
52 typedef OwnerContainer< AnimatorBase* > AnimatorContainer;
54 typedef AnimatorContainer::Iterator AnimatorIter;
55 typedef AnimatorContainer::ConstIterator AnimatorConstIter;
58 * An abstract base class for Animators, which can be added to scene graph animations.
59 * Each animator changes a single property of an object in the scene graph.
65 typedef float (*AlphaFunc)(float progress); ///< Definition of an alpha function
71 : mDurationSeconds(1.0f),
72 mIntervalDelaySeconds(0.0f),
75 mAlphaFunction(AlphaFunction::DEFAULT),
76 mDisconnectAction(Dali::Animation::BakeFinal),
79 mConnectedToSceneGraph(false),
80 mAutoReverseEnabled( false )
87 virtual ~AnimatorBase()
92 * Called when Animator is added to the scene-graph in update-thread.
94 virtual void ConnectToSceneGraph() = 0;
97 * Set the duration of the animator.
98 * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
99 * @param [in] seconds Duration in seconds.
101 void SetDuration(float seconds)
103 DALI_ASSERT_DEBUG(seconds >= 0.0f);
105 mDurationSeconds = seconds;
109 * Retrieve the duration of the animator.
110 * @return The duration in seconds.
112 float GetDuration() const
114 return mDurationSeconds;
117 void SetSpeedFactor( float factor )
119 mSpeedFactor = factor;
122 void SetLoopCount(int loopCount)
124 mLoopCount = loopCount;
127 float SetProgress( float progress )
131 if( mAutoReverseEnabled )
133 if( mSpeedFactor > 0.0f )
135 value = 1.0f - 2.0f * std::abs( progress - 0.5f );
138 else if( mSpeedFactor < 0.0f )
140 value = 2.0f * std::abs( progress - 0.5f );
152 * Set the delay before the animator should take effect.
153 * The default is zero i.e. no delay.
154 * @param [in] seconds The delay in seconds.
156 void SetIntervalDelay(float seconds)
158 mIntervalDelaySeconds = seconds;
162 * Retrieve the delay before the animator should take effect.
163 * @return The delay in seconds.
165 float GetIntervalDelay() const
167 return mIntervalDelaySeconds;
171 * Set the alpha function for an animator.
172 * @param [in] alphaFunc The alpha function to apply to the animation progress.
174 void SetAlphaFunction(const AlphaFunction& alphaFunction)
176 mAlphaFunction = alphaFunction;
180 * Retrieve the alpha function of an animator.
181 * @return The function.
183 AlphaFunction GetAlphaFunction() const
185 return mAlphaFunction;
189 * Applies the alpha function to the specified progress
190 * @param[in] Current progress
191 * @return The progress after the alpha function has been aplied
193 float ApplyAlphaFunction( float progress ) const
195 float result = progress;
197 AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() );
198 if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION )
200 switch(mAlphaFunction.GetBuiltinFunction())
202 case AlphaFunction::DEFAULT:
203 case AlphaFunction::LINEAR:
207 case AlphaFunction::REVERSE:
209 result = 1.0f-progress;
212 case AlphaFunction::EASE_IN_SQUARE:
214 result = progress * progress;
217 case AlphaFunction::EASE_OUT_SQUARE:
219 result = 1.0f - (1.0f-progress) * (1.0f-progress);
222 case AlphaFunction::EASE_IN:
224 result = progress * progress * progress;
227 case AlphaFunction::EASE_OUT:
229 result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f;
232 case AlphaFunction::EASE_IN_OUT:
234 result = progress*progress*(3.0f-2.0f*progress);
237 case AlphaFunction::EASE_IN_SINE:
239 result = -1.0f * cosf(progress * Math::PI_2) + 1.0f;
242 case AlphaFunction::EASE_OUT_SINE:
244 result = sinf(progress * Math::PI_2);
247 case AlphaFunction::EASE_IN_OUT_SINE:
249 result = -0.5f * (cosf(Math::PI * progress) - 1.0f);
252 case AlphaFunction::BOUNCE:
254 result = sinf(progress * Math::PI);
257 case AlphaFunction::SIN:
259 result = 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
262 case AlphaFunction::EASE_OUT_BACK:
264 const float sqrt2 = 1.70158f;
266 result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
269 case AlphaFunction::COUNT:
275 else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION )
277 AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction();
280 result = customFunction(progress);
285 //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will
286 //be almost 0 or almost 1 respectively
287 if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) )
289 Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints();
291 static const float tolerance = 0.001f; //10 iteration max
293 //Perform a binary search on the curve
294 float lowerBound(0.0f);
295 float upperBound(1.0f);
296 float currentT(0.5f);
297 float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
298 while( fabs( progress - currentX ) > tolerance )
300 if( progress > currentX )
302 lowerBound = currentT;
306 upperBound = currentT;
308 currentT = (upperBound+lowerBound)*0.5f;
309 currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
311 result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT);
319 * Whether to bake the animation if attached property owner is disconnected.
320 * Property is only baked if the animator is active.
321 * @param [in] action The disconnect action.
323 void SetDisconnectAction( Dali::Animation::EndAction action )
325 mDisconnectAction = action;
329 * Retrieve the disconnect action of an animator.
330 * @return The disconnect action.
332 Dali::Animation::EndAction GetDisconnectAction() const
334 return mDisconnectAction;
338 * Whether the animator is active or not.
339 * @param [in] active The new active state.
340 * @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
341 * @note When the property owner is disconnected, the active state is set to false.
343 void SetActive( bool active )
349 * Retrieve whether the animator has been set to active or not.
350 * @return The active state.
352 bool GetActive() const
358 * Retrive wheter the animator's target object is valid and on the stage.
359 * @return The enabled state.
361 bool IsEnabled() const
367 * @brief Sets the looping mode.
368 * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
370 void SetLoopingMode( bool loopingMode )
372 mAutoReverseEnabled = loopingMode;
376 * Returns wheter the target object of the animator is still valid
377 * or has been destroyed.
378 * @return True if animator is orphan, false otherwise *
379 * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
381 virtual bool Orphan() = 0;
384 * Update the scene object attached to the animator.
385 * @param[in] bufferIndex The buffer to animate.
386 * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
387 * @param[in] bake Bake.
389 virtual void Update(BufferIndex bufferIndex, float progress, bool bake) = 0;
394 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
395 * @param[in] p0 First control point of the bezier curve
396 * @param[in] p1 Second control point of the bezier curve
397 * @param[in] t A floating point value between 0.0 and 1.0
398 * @return Value of the curve at progress t
400 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
403 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
406 float mDurationSeconds;
407 float mIntervalDelaySeconds;
412 AlphaFunction mAlphaFunction;
414 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
415 bool mActive:1; ///< Animator is "active" while it's running.
416 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
417 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
418 bool mAutoReverseEnabled:1;
422 * An animator for a specific property type PropertyType.
424 template < typename PropertyType, typename PropertyAccessorType >
425 class Animator : public AnimatorBase, public PropertyOwner::Observer
430 * Construct a new property animator.
431 * @param[in] property The animatable property; only valid while the Animator is attached.
432 * @param[in] animatorFunction The function used to animate the property.
433 * @param[in] alphaFunction The alpha function to apply.
434 * @param[in] timePeriod The time period of this animation.
435 * @return A newly allocated animator.
437 static AnimatorBase* New( const PropertyOwner& propertyOwner,
438 const PropertyBase& property,
439 AnimatorFunctionBase* animatorFunction,
440 AlphaFunction alphaFunction,
441 const TimePeriod& timePeriod )
443 typedef Animator< PropertyType, PropertyAccessorType > AnimatorType;
445 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
446 AnimatorType* animator = new AnimatorType( const_cast<PropertyOwner*>( &propertyOwner ),
447 const_cast<PropertyBase*>( &property ),
450 animator->SetAlphaFunction( alphaFunction );
451 animator->SetIntervalDelay( timePeriod.delaySeconds );
452 animator->SetDuration( timePeriod.durationSeconds );
458 * Virtual destructor.
462 if (mPropertyOwner && mConnectedToSceneGraph)
464 mPropertyOwner->RemoveObserver(*this);
467 delete mAnimatorFunction;
471 * Called when Animator is added to the scene-graph in update-thread.
473 virtual void ConnectToSceneGraph()
475 mConnectedToSceneGraph = true;
476 mPropertyOwner->AddObserver(*this);
480 * Called when mPropertyOwner is connected to the scene graph.
482 virtual void PropertyOwnerConnected( PropertyOwner& owner )
488 * Called when mPropertyOwner is disconnected from the scene graph.
490 virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
492 // If we are active, then bake the value if required
493 if ( mActive && mDisconnectAction != Dali::Animation::Discard )
495 // Bake to target-value if BakeFinal, otherwise bake current value
496 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
504 * Called shortly before mPropertyOwner is destroyed
506 virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
508 mPropertyOwner = NULL;
514 virtual 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 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
526 const PropertyType result = (*mAnimatorFunction)( alpha, current );
529 mPropertyAccessor.Bake( bufferIndex, result );
533 mPropertyAccessor.Set( bufferIndex, result );
536 mCurrentProgress = progress;
542 virtual bool Orphan()
544 return (mPropertyOwner == NULL);
550 * Private constructor; see also Animator::New().
552 Animator( PropertyOwner* propertyOwner,
553 PropertyBase* property,
554 AnimatorFunctionBase* animatorFunction )
555 : mPropertyOwner( propertyOwner ),
556 mPropertyAccessor( property ),
557 mAnimatorFunction( animatorFunction ),
558 mCurrentProgress( 0.0f )
560 // WARNING - this object is created in the event-thread
561 // The scene-graph mPropertyOwner object cannot be observed here
565 Animator( const Animator& );
568 Animator& operator=( const Animator& );
572 PropertyOwner* mPropertyOwner;
573 PropertyAccessorType mPropertyAccessor;
575 AnimatorFunctionBase* mAnimatorFunction;
576 float mCurrentProgress;
582 * An animator for a specific property type PropertyType.
584 template <typename T, typename PropertyAccessorType>
585 class AnimatorTransformProperty : public AnimatorBase, public PropertyOwner::Observer
590 * Construct a new property animator.
591 * @param[in] property The animatable property; only valid while the Animator is attached.
592 * @param[in] animatorFunction The function used to animate the property.
593 * @param[in] alphaFunction The alpha function to apply.
594 * @param[in] timePeriod The time period of this animation.
595 * @return A newly allocated animator.
597 static AnimatorBase* New( const PropertyOwner& propertyOwner,
598 const PropertyBase& property,
599 AnimatorFunctionBase* animatorFunction,
600 AlphaFunction alphaFunction,
601 const TimePeriod& timePeriod )
604 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
605 AnimatorTransformProperty* animator = new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
606 const_cast<PropertyBase*>( &property ),
609 animator->SetAlphaFunction( alphaFunction );
610 animator->SetIntervalDelay( timePeriod.delaySeconds );
611 animator->SetDuration( timePeriod.durationSeconds );
617 * Virtual destructor.
619 virtual ~AnimatorTransformProperty()
621 if (mPropertyOwner && mConnectedToSceneGraph)
623 mPropertyOwner->RemoveObserver(*this);
626 delete mAnimatorFunction;
630 * Called when Animator is added to the scene-graph in update-thread.
632 virtual void ConnectToSceneGraph()
634 mConnectedToSceneGraph = true;
635 mPropertyOwner->AddObserver(*this);
639 * Called when mPropertyOwner is connected to the scene graph.
641 virtual void PropertyOwnerConnected( PropertyOwner& owner )
647 * Called when mPropertyOwner is disconnected from the scene graph.
649 virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
651 // If we are active, then bake the value if required
652 if ( mActive && mDisconnectAction != Dali::Animation::Discard )
654 // Bake to target-value if BakeFinal, otherwise bake current value
655 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
663 * Called shortly before mPropertyOwner is destroyed
665 virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
667 mPropertyOwner = NULL;
673 virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
675 if( mLoopCount >= 0 )
677 // Update the progress value
678 progress = SetProgress( progress );
681 float alpha = ApplyAlphaFunction( progress );
683 const T& current = mPropertyAccessor.Get( bufferIndex );
685 const T result = (*mAnimatorFunction)( alpha, current );
690 mPropertyAccessor.Bake( bufferIndex, result );
694 mPropertyAccessor.Set( bufferIndex, result );
697 mCurrentProgress = progress;
703 virtual bool Orphan()
705 return (mPropertyOwner == NULL);
711 * Private constructor; see also Animator::New().
713 AnimatorTransformProperty( PropertyOwner* propertyOwner,
714 PropertyBase* property,
715 AnimatorFunctionBase* animatorFunction )
716 : mPropertyOwner( propertyOwner ),
717 mPropertyAccessor( property ),
718 mAnimatorFunction( animatorFunction ),
719 mCurrentProgress( 0.0f )
721 // WARNING - this object is created in the event-thread
722 // The scene-graph mPropertyOwner object cannot be observed here
726 AnimatorTransformProperty( const AnimatorTransformProperty& );
729 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& );
733 PropertyOwner* mPropertyOwner;
734 PropertyAccessorType mPropertyAccessor;
736 AnimatorFunctionBase* mAnimatorFunction;
737 float mCurrentProgress;
740 } // namespace SceneGraph
743 * AnimatorFunction base class.
744 * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
746 struct AnimatorFunctionBase
751 AnimatorFunctionBase(){}
754 * Virtual destructor (Intended as base class)
756 virtual ~AnimatorFunctionBase(){}
758 ///Stub "()" operators.
759 virtual bool operator()(float progress, const bool& property)
764 virtual float operator()(float progress, const int& property)
769 virtual float operator()(float progress, const unsigned int& property)
774 virtual float operator()(float progress, const float& property)
779 virtual Vector2 operator()(float progress, const Vector2& property)
784 virtual Vector3 operator()(float progress, const Vector3& property)
789 virtual Vector4 operator()(float progress, const Vector4& property)
794 virtual Quaternion operator()(float progress, const Quaternion& property)
802 struct AnimateByInteger : public AnimatorFunctionBase
804 AnimateByInteger(const int& relativeValue)
805 : mRelative(relativeValue)
809 using AnimatorFunctionBase::operator();
810 float operator()(float alpha, const int& property)
812 return int(property + mRelative * alpha + 0.5f );
818 struct AnimateToInteger : public AnimatorFunctionBase
820 AnimateToInteger(const int& targetValue)
821 : mTarget(targetValue)
825 using AnimatorFunctionBase::operator();
826 float operator()(float alpha, const int& property)
828 return int(property + ((mTarget - property) * alpha) + 0.5f);
834 struct AnimateByFloat : public AnimatorFunctionBase
836 AnimateByFloat(const float& relativeValue)
837 : mRelative(relativeValue)
841 using AnimatorFunctionBase::operator();
842 float operator()(float alpha, const float& property)
844 return float(property + mRelative * alpha);
850 struct AnimateToFloat : public AnimatorFunctionBase
852 AnimateToFloat(const float& targetValue)
853 : mTarget(targetValue)
857 using AnimatorFunctionBase::operator();
858 float operator()(float alpha, const float& property)
860 return float(property + ((mTarget - property) * alpha));
866 struct AnimateByVector2 : public AnimatorFunctionBase
868 AnimateByVector2(const Vector2& relativeValue)
869 : mRelative(relativeValue)
873 using AnimatorFunctionBase::operator();
874 Vector2 operator()(float alpha, const Vector2& property)
876 return Vector2(property + mRelative * alpha);
882 struct AnimateToVector2 : public AnimatorFunctionBase
884 AnimateToVector2(const Vector2& targetValue)
885 : mTarget(targetValue)
889 using AnimatorFunctionBase::operator();
890 Vector2 operator()(float alpha, const Vector2& property)
892 return Vector2(property + ((mTarget - property) * alpha));
898 struct AnimateByVector3 : public AnimatorFunctionBase
900 AnimateByVector3(const Vector3& relativeValue)
901 : mRelative(relativeValue)
905 using AnimatorFunctionBase::operator();
906 Vector3 operator()(float alpha, const Vector3& property)
908 return Vector3(property + mRelative * alpha);
914 struct AnimateToVector3 : public AnimatorFunctionBase
916 AnimateToVector3(const Vector3& targetValue)
917 : mTarget(targetValue)
921 using AnimatorFunctionBase::operator();
922 Vector3 operator()(float alpha, const Vector3& property)
924 return Vector3(property + ((mTarget - property) * alpha));
930 struct AnimateByVector4 : public AnimatorFunctionBase
932 AnimateByVector4(const Vector4& relativeValue)
933 : mRelative(relativeValue)
937 using AnimatorFunctionBase::operator();
938 Vector4 operator()(float alpha, const Vector4& property)
940 return Vector4(property + mRelative * alpha);
946 struct AnimateToVector4 : public AnimatorFunctionBase
948 AnimateToVector4(const Vector4& targetValue)
949 : mTarget(targetValue)
953 using AnimatorFunctionBase::operator();
954 Vector4 operator()(float alpha, const Vector4& property)
956 return Vector4(property + ((mTarget - property) * alpha));
962 struct AnimateByOpacity : public AnimatorFunctionBase
964 AnimateByOpacity(const float& relativeValue)
965 : mRelative(relativeValue)
969 using AnimatorFunctionBase::operator();
970 Vector4 operator()(float alpha, const Vector4& property)
972 Vector4 result(property);
973 result.a += mRelative * alpha;
981 struct AnimateToOpacity : public AnimatorFunctionBase
983 AnimateToOpacity(const float& targetValue)
984 : mTarget(targetValue)
988 using AnimatorFunctionBase::operator();
989 Vector4 operator()(float alpha, const Vector4& property)
991 Vector4 result(property);
992 result.a = property.a + ((mTarget - property.a) * alpha);
1000 struct AnimateByBoolean : public AnimatorFunctionBase
1002 AnimateByBoolean(bool relativeValue)
1003 : mRelative(relativeValue)
1007 using AnimatorFunctionBase::operator();
1008 bool operator()(float alpha, const bool& property)
1010 // Alpha is not useful here, just keeping to the same template as other update functors
1011 return bool(alpha >= 1.0f ? (property || mRelative) : property);
1017 struct AnimateToBoolean : public AnimatorFunctionBase
1019 AnimateToBoolean(bool targetValue)
1020 : mTarget(targetValue)
1024 using AnimatorFunctionBase::operator();
1025 bool operator()(float alpha, const bool& property)
1027 // Alpha is not useful here, just keeping to the same template as other update functors
1028 return bool(alpha >= 1.0f ? mTarget : property);
1034 struct RotateByAngleAxis : public AnimatorFunctionBase
1036 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
1037 : mAngleRadians( angleRadians ),
1038 mAxis(axis.x, axis.y, axis.z)
1042 using AnimatorFunctionBase::operator();
1043 Quaternion operator()(float alpha, const Quaternion& rotation)
1047 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1053 Radian mAngleRadians;
1057 struct RotateToQuaternion : public AnimatorFunctionBase
1059 RotateToQuaternion(const Quaternion& targetValue)
1060 : mTarget(targetValue)
1064 using AnimatorFunctionBase::operator();
1065 Quaternion operator()(float alpha, const Quaternion& rotation)
1067 return Quaternion::Slerp(rotation, mTarget, alpha);
1074 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1076 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1077 : mKeyFrames(keyFrames)
1081 using AnimatorFunctionBase::operator();
1082 bool operator()(float progress, const bool& property)
1084 if(mKeyFrames->IsActive(progress))
1086 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1091 KeyFrameBooleanPtr mKeyFrames;
1094 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1096 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1097 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1101 using AnimatorFunctionBase::operator();
1102 float operator()(float progress, const int& property)
1104 if(mKeyFrames->IsActive(progress))
1106 return mKeyFrames->GetValue(progress, mInterpolation);
1111 KeyFrameIntegerPtr mKeyFrames;
1112 Interpolation mInterpolation;
1115 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1117 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1118 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1122 using AnimatorFunctionBase::operator();
1123 float operator()(float progress, const float& property)
1125 if(mKeyFrames->IsActive(progress))
1127 return mKeyFrames->GetValue(progress, mInterpolation);
1132 KeyFrameNumberPtr mKeyFrames;
1133 Interpolation mInterpolation;
1136 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1138 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1139 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1143 using AnimatorFunctionBase::operator();
1144 Vector2 operator()(float progress, const Vector2& property)
1146 if(mKeyFrames->IsActive(progress))
1148 return mKeyFrames->GetValue(progress, mInterpolation);
1153 KeyFrameVector2Ptr mKeyFrames;
1154 Interpolation mInterpolation;
1158 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1160 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1161 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1165 using AnimatorFunctionBase::operator();
1166 Vector3 operator()(float progress, const Vector3& property)
1168 if(mKeyFrames->IsActive(progress))
1170 return mKeyFrames->GetValue(progress, mInterpolation);
1175 KeyFrameVector3Ptr mKeyFrames;
1176 Interpolation mInterpolation;
1179 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1181 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1182 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1186 using AnimatorFunctionBase::operator();
1187 Vector4 operator()(float progress, const Vector4& property)
1189 if(mKeyFrames->IsActive(progress))
1191 return mKeyFrames->GetValue(progress, mInterpolation);
1196 KeyFrameVector4Ptr mKeyFrames;
1197 Interpolation mInterpolation;
1200 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1202 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1203 : mKeyFrames(keyFrames)
1207 using AnimatorFunctionBase::operator();
1208 Quaternion operator()(float progress, const Quaternion& property)
1210 if(mKeyFrames->IsActive(progress))
1212 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1217 KeyFrameQuaternionPtr mKeyFrames;
1220 struct PathPositionFunctor : public AnimatorFunctionBase
1222 PathPositionFunctor( PathPtr path )
1227 using AnimatorFunctionBase::operator();
1228 Vector3 operator()(float progress, const Vector3& property)
1230 Vector3 position(property);
1231 static_cast<void>( mPath->SamplePosition(progress, position) );
1238 struct PathRotationFunctor : public AnimatorFunctionBase
1240 PathRotationFunctor( PathPtr path, const Vector3& forward )
1244 mForward.Normalize();
1247 using AnimatorFunctionBase::operator();
1248 Quaternion operator()(float progress, const Quaternion& property)
1251 if( mPath->SampleTangent(progress, tangent) )
1253 return Quaternion( mForward, tangent );
1265 } // namespace Internal
1269 #endif // __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__