1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
5 * Copyright (c) 2018 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
68 * Observer to determine when the animator is no longer present
70 class LifecycleObserver
74 * Called shortly before the animator is destroyed.
76 virtual void ObjectDestroyed() = 0;
80 * Virtual destructor, no deletion through this interface
82 virtual ~LifecycleObserver() = default;
90 : mLifecycleObserver(nullptr),
91 mDurationSeconds(1.0f),
92 mIntervalDelaySeconds(0.0f),
95 mAlphaFunction(AlphaFunction::DEFAULT),
96 mDisconnectAction(Dali::Animation::BakeFinal),
99 mConnectedToSceneGraph(false),
100 mAutoReverseEnabled( false )
105 * Virtual destructor.
107 virtual ~AnimatorBase()
109 if( mLifecycleObserver != nullptr )
111 mLifecycleObserver->ObjectDestroyed();
115 void AddLifecycleObserver( LifecycleObserver& observer )
117 mLifecycleObserver = &observer;
120 void RemoveLifecycleObserver( LifecycleObserver& observer )
122 mLifecycleObserver = nullptr;
126 * Called when Animator is added to the scene-graph in update-thread.
128 virtual void ConnectToSceneGraph() = 0;
131 * Set the duration of the animator.
132 * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
133 * @param [in] seconds Duration in seconds.
135 void SetDuration(float seconds)
137 DALI_ASSERT_DEBUG(seconds >= 0.0f);
139 mDurationSeconds = seconds;
143 * Retrieve the duration of the animator.
144 * @return The duration in seconds.
146 float GetDuration() const
148 return mDurationSeconds;
151 void SetSpeedFactor( float factor )
153 mSpeedFactor = factor;
156 void SetLoopCount(int loopCount)
158 mLoopCount = loopCount;
161 float SetProgress( float progress )
165 if( mAutoReverseEnabled )
167 if( mSpeedFactor > 0.0f )
169 value = 1.0f - 2.0f * std::abs( progress - 0.5f );
172 else if( mSpeedFactor < 0.0f )
174 value = 2.0f * std::abs( progress - 0.5f );
186 * Set the delay before the animator should take effect.
187 * The default is zero i.e. no delay.
188 * @param [in] seconds The delay in seconds.
190 void SetIntervalDelay(float seconds)
192 mIntervalDelaySeconds = seconds;
196 * Retrieve the delay before the animator should take effect.
197 * @return The delay in seconds.
199 float GetIntervalDelay() const
201 return mIntervalDelaySeconds;
205 * Set the alpha function for an animator.
206 * @param [in] alphaFunc The alpha function to apply to the animation progress.
208 void SetAlphaFunction(const AlphaFunction& alphaFunction)
210 mAlphaFunction = alphaFunction;
214 * Retrieve the alpha function of an animator.
215 * @return The function.
217 AlphaFunction GetAlphaFunction() const
219 return mAlphaFunction;
223 * Applies the alpha function to the specified progress
224 * @param[in] Current progress
225 * @return The progress after the alpha function has been aplied
227 float ApplyAlphaFunction( float progress ) const
229 float result = progress;
231 AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() );
232 if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION )
234 switch(mAlphaFunction.GetBuiltinFunction())
236 case AlphaFunction::DEFAULT:
237 case AlphaFunction::LINEAR:
241 case AlphaFunction::REVERSE:
243 result = 1.0f-progress;
246 case AlphaFunction::EASE_IN_SQUARE:
248 result = progress * progress;
251 case AlphaFunction::EASE_OUT_SQUARE:
253 result = 1.0f - (1.0f-progress) * (1.0f-progress);
256 case AlphaFunction::EASE_IN:
258 result = progress * progress * progress;
261 case AlphaFunction::EASE_OUT:
263 result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f;
266 case AlphaFunction::EASE_IN_OUT:
268 result = progress*progress*(3.0f-2.0f*progress);
271 case AlphaFunction::EASE_IN_SINE:
273 result = -1.0f * cosf(progress * Math::PI_2) + 1.0f;
276 case AlphaFunction::EASE_OUT_SINE:
278 result = sinf(progress * Math::PI_2);
281 case AlphaFunction::EASE_IN_OUT_SINE:
283 result = -0.5f * (cosf(Math::PI * progress) - 1.0f);
286 case AlphaFunction::BOUNCE:
288 result = sinf(progress * Math::PI);
291 case AlphaFunction::SIN:
293 result = 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
296 case AlphaFunction::EASE_OUT_BACK:
298 const float sqrt2 = 1.70158f;
300 result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
303 case AlphaFunction::COUNT:
309 else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION )
311 AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction();
314 result = customFunction(progress);
319 //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will
320 //be almost 0 or almost 1 respectively
321 if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) )
323 Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints();
325 static const float tolerance = 0.001f; //10 iteration max
327 //Perform a binary search on the curve
328 float lowerBound(0.0f);
329 float upperBound(1.0f);
330 float currentT(0.5f);
331 float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
332 while( fabs( progress - currentX ) > tolerance )
334 if( progress > currentX )
336 lowerBound = currentT;
340 upperBound = currentT;
342 currentT = (upperBound+lowerBound)*0.5f;
343 currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
345 result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT);
353 * Whether to bake the animation if attached property owner is disconnected.
354 * Property is only baked if the animator is active.
355 * @param [in] action The disconnect action.
357 void SetDisconnectAction( Dali::Animation::EndAction action )
359 mDisconnectAction = action;
363 * Retrieve the disconnect action of an animator.
364 * @return The disconnect action.
366 Dali::Animation::EndAction GetDisconnectAction() const
368 return mDisconnectAction;
372 * Whether the animator is active or not.
373 * @param [in] active The new active state.
374 * @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
375 * @note When the property owner is disconnected, the active state is set to false.
377 void SetActive( bool active )
383 * Retrieve whether the animator has been set to active or not.
384 * @return The active state.
386 bool GetActive() const
392 * Retrive wheter the animator's target object is valid and on the stage.
393 * @return The enabled state.
395 bool IsEnabled() const
401 * @brief Sets the looping mode.
402 * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
404 void SetLoopingMode( bool loopingMode )
406 mAutoReverseEnabled = loopingMode;
410 * Returns wheter the target object of the animator is still valid
411 * or has been destroyed.
412 * @return True if animator is orphan, false otherwise *
413 * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
415 virtual bool Orphan() = 0;
418 * Update the scene object attached to the animator.
419 * @param[in] bufferIndex The buffer to animate.
420 * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
421 * @param[in] bake Bake.
423 virtual void Update(BufferIndex bufferIndex, float progress, bool bake) = 0;
428 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
429 * @param[in] p0 First control point of the bezier curve
430 * @param[in] p1 Second control point of the bezier curve
431 * @param[in] t A floating point value between 0.0 and 1.0
432 * @return Value of the curve at progress t
434 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
437 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
440 LifecycleObserver* mLifecycleObserver;
441 float mDurationSeconds;
442 float mIntervalDelaySeconds;
447 AlphaFunction mAlphaFunction;
449 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
450 bool mActive:1; ///< Animator is "active" while it's running.
451 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
452 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
453 bool mAutoReverseEnabled:1;
457 * An animator for a specific property type PropertyType.
459 template < typename PropertyType, typename PropertyAccessorType >
460 class Animator : public AnimatorBase, public PropertyOwner::Observer
465 * Construct a new property animator.
466 * @param[in] property The animatable property; only valid while the Animator is attached.
467 * @param[in] animatorFunction The function used to animate the property.
468 * @param[in] alphaFunction The alpha function to apply.
469 * @param[in] timePeriod The time period of this animation.
470 * @return A newly allocated animator.
472 static AnimatorBase* New( const PropertyOwner& propertyOwner,
473 const PropertyBase& property,
474 AnimatorFunctionBase* animatorFunction,
475 AlphaFunction alphaFunction,
476 const TimePeriod& timePeriod )
478 typedef Animator< PropertyType, PropertyAccessorType > AnimatorType;
480 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
481 AnimatorType* animator = new AnimatorType( const_cast<PropertyOwner*>( &propertyOwner ),
482 const_cast<PropertyBase*>( &property ),
485 animator->SetAlphaFunction( alphaFunction );
486 animator->SetIntervalDelay( timePeriod.delaySeconds );
487 animator->SetDuration( timePeriod.durationSeconds );
493 * Virtual destructor.
497 if (mPropertyOwner && mConnectedToSceneGraph)
499 mPropertyOwner->RemoveObserver(*this);
502 delete mAnimatorFunction;
506 * Called when Animator is added to the scene-graph in update-thread.
508 virtual void ConnectToSceneGraph()
510 mConnectedToSceneGraph = true;
511 mPropertyOwner->AddObserver(*this);
515 * Called when mPropertyOwner is connected to the scene graph.
517 virtual void PropertyOwnerConnected( PropertyOwner& owner )
523 * Called when mPropertyOwner is disconnected from the scene graph.
525 virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
527 // If we are active, then bake the value if required
528 if ( mActive && mDisconnectAction != Dali::Animation::Discard )
530 // Bake to target-value if BakeFinal, otherwise bake current value
531 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
539 * Called shortly before mPropertyOwner is destroyed
541 virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
543 mPropertyOwner = NULL;
549 virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
551 if( mLoopCount >= 0 )
553 // Update the progress value
554 progress = SetProgress( progress );
557 float alpha = ApplyAlphaFunction( progress );
559 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
561 const PropertyType result = (*mAnimatorFunction)( alpha, current );
564 mPropertyAccessor.Bake( bufferIndex, result );
568 mPropertyAccessor.Set( bufferIndex, result );
571 mCurrentProgress = progress;
577 virtual bool Orphan()
579 return (mPropertyOwner == NULL);
585 * Private constructor; see also Animator::New().
587 Animator( PropertyOwner* propertyOwner,
588 PropertyBase* property,
589 AnimatorFunctionBase* animatorFunction )
590 : mPropertyOwner( propertyOwner ),
591 mPropertyAccessor( property ),
592 mAnimatorFunction( animatorFunction ),
593 mCurrentProgress( 0.0f )
595 // WARNING - this object is created in the event-thread
596 // The scene-graph mPropertyOwner object cannot be observed here
600 Animator( const Animator& );
603 Animator& operator=( const Animator& );
607 PropertyOwner* mPropertyOwner;
608 PropertyAccessorType mPropertyAccessor;
610 AnimatorFunctionBase* mAnimatorFunction;
611 float mCurrentProgress;
617 * An animator for a specific property type PropertyType.
619 template <typename T, typename PropertyAccessorType>
620 class AnimatorTransformProperty : public AnimatorBase, public PropertyOwner::Observer
625 * Construct a new property animator.
626 * @param[in] property The animatable property; only valid while the Animator is attached.
627 * @param[in] animatorFunction The function used to animate the property.
628 * @param[in] alphaFunction The alpha function to apply.
629 * @param[in] timePeriod The time period of this animation.
630 * @return A newly allocated animator.
632 static AnimatorBase* New( const PropertyOwner& propertyOwner,
633 const PropertyBase& property,
634 AnimatorFunctionBase* animatorFunction,
635 AlphaFunction alphaFunction,
636 const TimePeriod& timePeriod )
639 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
640 AnimatorTransformProperty* animator = new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
641 const_cast<PropertyBase*>( &property ),
644 animator->SetAlphaFunction( alphaFunction );
645 animator->SetIntervalDelay( timePeriod.delaySeconds );
646 animator->SetDuration( timePeriod.durationSeconds );
652 * Virtual destructor.
654 virtual ~AnimatorTransformProperty()
656 if (mPropertyOwner && mConnectedToSceneGraph)
658 mPropertyOwner->RemoveObserver(*this);
661 delete mAnimatorFunction;
665 * Called when Animator is added to the scene-graph in update-thread.
667 virtual void ConnectToSceneGraph()
669 mConnectedToSceneGraph = true;
670 mPropertyOwner->AddObserver(*this);
674 * Called when mPropertyOwner is connected to the scene graph.
676 virtual void PropertyOwnerConnected( PropertyOwner& owner )
682 * Called when mPropertyOwner is disconnected from the scene graph.
684 virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
686 // If we are active, then bake the value if required
687 if ( mActive && mDisconnectAction != Dali::Animation::Discard )
689 // Bake to target-value if BakeFinal, otherwise bake current value
690 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
698 * Called shortly before mPropertyOwner is destroyed
700 virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
702 mPropertyOwner = NULL;
708 virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
710 if( mLoopCount >= 0 )
712 // Update the progress value
713 progress = SetProgress( progress );
716 float alpha = ApplyAlphaFunction( progress );
718 const T& current = mPropertyAccessor.Get( bufferIndex );
720 const T result = (*mAnimatorFunction)( alpha, current );
725 mPropertyAccessor.Bake( bufferIndex, result );
729 mPropertyAccessor.Set( bufferIndex, result );
732 mCurrentProgress = progress;
738 virtual bool Orphan()
740 return (mPropertyOwner == NULL);
746 * Private constructor; see also Animator::New().
748 AnimatorTransformProperty( PropertyOwner* propertyOwner,
749 PropertyBase* property,
750 AnimatorFunctionBase* animatorFunction )
751 : mPropertyOwner( propertyOwner ),
752 mPropertyAccessor( property ),
753 mAnimatorFunction( animatorFunction ),
754 mCurrentProgress( 0.0f )
756 // WARNING - this object is created in the event-thread
757 // The scene-graph mPropertyOwner object cannot be observed here
761 AnimatorTransformProperty( const AnimatorTransformProperty& );
764 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& );
768 PropertyOwner* mPropertyOwner;
769 PropertyAccessorType mPropertyAccessor;
771 AnimatorFunctionBase* mAnimatorFunction;
772 float mCurrentProgress;
775 } // namespace SceneGraph
778 * AnimatorFunction base class.
779 * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
781 struct AnimatorFunctionBase
786 AnimatorFunctionBase(){}
789 * Virtual destructor (Intended as base class)
791 virtual ~AnimatorFunctionBase(){}
793 ///Stub "()" operators.
794 virtual bool operator()(float progress, const bool& property)
799 virtual float operator()(float progress, const int& property)
804 virtual float operator()(float progress, const unsigned int& property)
809 virtual float operator()(float progress, const float& property)
814 virtual Vector2 operator()(float progress, const Vector2& property)
819 virtual Vector3 operator()(float progress, const Vector3& property)
824 virtual Vector4 operator()(float progress, const Vector4& property)
829 virtual Quaternion operator()(float progress, const Quaternion& property)
837 struct AnimateByInteger : public AnimatorFunctionBase
839 AnimateByInteger(const int& relativeValue)
840 : mRelative(relativeValue)
844 using AnimatorFunctionBase::operator();
845 float operator()(float alpha, const int& property)
847 return int(property + mRelative * alpha + 0.5f );
853 struct AnimateToInteger : public AnimatorFunctionBase
855 AnimateToInteger(const int& targetValue)
856 : mTarget(targetValue)
860 using AnimatorFunctionBase::operator();
861 float operator()(float alpha, const int& property)
863 return int(property + ((mTarget - property) * alpha) + 0.5f);
869 struct AnimateByFloat : public AnimatorFunctionBase
871 AnimateByFloat(const float& relativeValue)
872 : mRelative(relativeValue)
876 using AnimatorFunctionBase::operator();
877 float operator()(float alpha, const float& property)
879 return float(property + mRelative * alpha);
885 struct AnimateToFloat : public AnimatorFunctionBase
887 AnimateToFloat(const float& targetValue)
888 : mTarget(targetValue)
892 using AnimatorFunctionBase::operator();
893 float operator()(float alpha, const float& property)
895 return float(property + ((mTarget - property) * alpha));
901 struct AnimateByVector2 : public AnimatorFunctionBase
903 AnimateByVector2(const Vector2& relativeValue)
904 : mRelative(relativeValue)
908 using AnimatorFunctionBase::operator();
909 Vector2 operator()(float alpha, const Vector2& property)
911 return Vector2(property + mRelative * alpha);
917 struct AnimateToVector2 : public AnimatorFunctionBase
919 AnimateToVector2(const Vector2& targetValue)
920 : mTarget(targetValue)
924 using AnimatorFunctionBase::operator();
925 Vector2 operator()(float alpha, const Vector2& property)
927 return Vector2(property + ((mTarget - property) * alpha));
933 struct AnimateByVector3 : public AnimatorFunctionBase
935 AnimateByVector3(const Vector3& relativeValue)
936 : mRelative(relativeValue)
940 using AnimatorFunctionBase::operator();
941 Vector3 operator()(float alpha, const Vector3& property)
943 return Vector3(property + mRelative * alpha);
949 struct AnimateToVector3 : public AnimatorFunctionBase
951 AnimateToVector3(const Vector3& targetValue)
952 : mTarget(targetValue)
956 using AnimatorFunctionBase::operator();
957 Vector3 operator()(float alpha, const Vector3& property)
959 return Vector3(property + ((mTarget - property) * alpha));
965 struct AnimateByVector4 : public AnimatorFunctionBase
967 AnimateByVector4(const Vector4& relativeValue)
968 : mRelative(relativeValue)
972 using AnimatorFunctionBase::operator();
973 Vector4 operator()(float alpha, const Vector4& property)
975 return Vector4(property + mRelative * alpha);
981 struct AnimateToVector4 : public AnimatorFunctionBase
983 AnimateToVector4(const Vector4& targetValue)
984 : mTarget(targetValue)
988 using AnimatorFunctionBase::operator();
989 Vector4 operator()(float alpha, const Vector4& property)
991 return Vector4(property + ((mTarget - property) * alpha));
997 struct AnimateByOpacity : public AnimatorFunctionBase
999 AnimateByOpacity(const float& relativeValue)
1000 : mRelative(relativeValue)
1004 using AnimatorFunctionBase::operator();
1005 Vector4 operator()(float alpha, const Vector4& property)
1007 Vector4 result(property);
1008 result.a += mRelative * alpha;
1016 struct AnimateToOpacity : public AnimatorFunctionBase
1018 AnimateToOpacity(const float& targetValue)
1019 : mTarget(targetValue)
1023 using AnimatorFunctionBase::operator();
1024 Vector4 operator()(float alpha, const Vector4& property)
1026 Vector4 result(property);
1027 result.a = property.a + ((mTarget - property.a) * alpha);
1035 struct AnimateByBoolean : public AnimatorFunctionBase
1037 AnimateByBoolean(bool relativeValue)
1038 : mRelative(relativeValue)
1042 using AnimatorFunctionBase::operator();
1043 bool operator()(float alpha, const bool& property)
1045 // Alpha is not useful here, just keeping to the same template as other update functors
1046 return bool(alpha >= 1.0f ? (property || mRelative) : property);
1052 struct AnimateToBoolean : public AnimatorFunctionBase
1054 AnimateToBoolean(bool targetValue)
1055 : mTarget(targetValue)
1059 using AnimatorFunctionBase::operator();
1060 bool operator()(float alpha, const bool& property)
1062 // Alpha is not useful here, just keeping to the same template as other update functors
1063 return bool(alpha >= 1.0f ? mTarget : property);
1069 struct RotateByAngleAxis : public AnimatorFunctionBase
1071 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
1072 : mAngleRadians( angleRadians ),
1073 mAxis(axis.x, axis.y, axis.z)
1077 using AnimatorFunctionBase::operator();
1078 Quaternion operator()(float alpha, const Quaternion& rotation)
1082 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1088 Radian mAngleRadians;
1092 struct RotateToQuaternion : public AnimatorFunctionBase
1094 RotateToQuaternion(const Quaternion& targetValue)
1095 : mTarget(targetValue)
1099 using AnimatorFunctionBase::operator();
1100 Quaternion operator()(float alpha, const Quaternion& rotation)
1102 return Quaternion::Slerp(rotation, mTarget, alpha);
1109 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1111 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1112 : mKeyFrames(keyFrames)
1116 using AnimatorFunctionBase::operator();
1117 bool operator()(float progress, const bool& property)
1119 if(mKeyFrames->IsActive(progress))
1121 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1126 KeyFrameBooleanPtr mKeyFrames;
1129 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1131 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1132 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1136 using AnimatorFunctionBase::operator();
1137 float operator()(float progress, const int& property)
1139 if(mKeyFrames->IsActive(progress))
1141 return mKeyFrames->GetValue(progress, mInterpolation);
1146 KeyFrameIntegerPtr mKeyFrames;
1147 Interpolation mInterpolation;
1150 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1152 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1153 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1157 using AnimatorFunctionBase::operator();
1158 float operator()(float progress, const float& property)
1160 if(mKeyFrames->IsActive(progress))
1162 return mKeyFrames->GetValue(progress, mInterpolation);
1167 KeyFrameNumberPtr mKeyFrames;
1168 Interpolation mInterpolation;
1171 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1173 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1174 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1178 using AnimatorFunctionBase::operator();
1179 Vector2 operator()(float progress, const Vector2& property)
1181 if(mKeyFrames->IsActive(progress))
1183 return mKeyFrames->GetValue(progress, mInterpolation);
1188 KeyFrameVector2Ptr mKeyFrames;
1189 Interpolation mInterpolation;
1193 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1195 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1196 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1200 using AnimatorFunctionBase::operator();
1201 Vector3 operator()(float progress, const Vector3& property)
1203 if(mKeyFrames->IsActive(progress))
1205 return mKeyFrames->GetValue(progress, mInterpolation);
1210 KeyFrameVector3Ptr mKeyFrames;
1211 Interpolation mInterpolation;
1214 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1216 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1217 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1221 using AnimatorFunctionBase::operator();
1222 Vector4 operator()(float progress, const Vector4& property)
1224 if(mKeyFrames->IsActive(progress))
1226 return mKeyFrames->GetValue(progress, mInterpolation);
1231 KeyFrameVector4Ptr mKeyFrames;
1232 Interpolation mInterpolation;
1235 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1237 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1238 : mKeyFrames(keyFrames)
1242 using AnimatorFunctionBase::operator();
1243 Quaternion operator()(float progress, const Quaternion& property)
1245 if(mKeyFrames->IsActive(progress))
1247 return mKeyFrames->GetValue(progress, Dali::Animation::Linear);
1252 KeyFrameQuaternionPtr mKeyFrames;
1255 struct PathPositionFunctor : public AnimatorFunctionBase
1257 PathPositionFunctor( PathPtr path )
1262 using AnimatorFunctionBase::operator();
1263 Vector3 operator()(float progress, const Vector3& property)
1265 Vector3 position(property);
1266 static_cast<void>( mPath->SamplePosition(progress, position) );
1273 struct PathRotationFunctor : public AnimatorFunctionBase
1275 PathRotationFunctor( PathPtr path, const Vector3& forward )
1279 mForward.Normalize();
1282 using AnimatorFunctionBase::operator();
1283 Quaternion operator()(float progress, const Quaternion& property)
1286 if( mPath->SampleTangent(progress, tangent) )
1288 return Quaternion( mForward, tangent );
1300 } // namespace Internal
1304 #endif // __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__