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() = default;
61 * Virtual destructor (Intended as base class)
63 virtual ~AnimatorFunctionBase() = default;
65 ///Stub "()" operators.
66 virtual bool operator()(float progress, const bool& property)
71 virtual float operator()(float progress, const int32_t& property)
73 return static_cast<float>( property );
76 virtual float operator()(float progress, const float& property)
81 virtual Vector2 operator()(float progress, const Vector2& property)
86 virtual Vector3 operator()(float progress, const Vector3& property)
91 virtual Vector4 operator()(float progress, const Vector4& property)
96 virtual Quaternion operator()(float progress, const Quaternion& property)
106 * An abstract base class for Animators, which can be added to scene graph animations.
107 * Each animator changes a single property of an object in the scene graph.
109 class AnimatorBase : public PropertyOwner::Observer
113 using AlphaFunc = float (*)(float progress); ///< Definition of an alpha function
116 * Observer to determine when the animator is no longer present
118 class LifecycleObserver
122 * Called shortly before the animator is destroyed.
124 virtual void ObjectDestroyed() = 0;
128 * Virtual destructor, no deletion through this interface
130 virtual ~LifecycleObserver() = default;
137 AnimatorBase( PropertyOwner* propertyOwner,
138 AnimatorFunctionBase* animatorFunction,
139 AlphaFunction alphaFunction,
140 const TimePeriod& timePeriod )
141 : mLifecycleObserver( nullptr ),
142 mPropertyOwner( propertyOwner ),
143 mAnimatorFunction( animatorFunction ),
144 mDurationSeconds( timePeriod.durationSeconds ),
145 mIntervalDelaySeconds( timePeriod.delaySeconds ),
146 mSpeedFactor( 1.0f ),
147 mCurrentProgress( 0.f ),
149 mAlphaFunction( alphaFunction ),
150 mDisconnectAction( Dali::Animation::BAKE_FINAL ),
151 mAnimationPlaying( false ),
153 mConnectedToSceneGraph( false ),
154 mAutoReverseEnabled( false )
159 * Virtual destructor.
161 ~AnimatorBase() override
163 delete mAnimatorFunction;
164 if (mPropertyOwner && mConnectedToSceneGraph)
166 mPropertyOwner->RemoveObserver(*this);
168 if( mLifecycleObserver != nullptr )
170 mLifecycleObserver->ObjectDestroyed();
174 void AddLifecycleObserver( LifecycleObserver& observer )
176 mLifecycleObserver = &observer;
179 void RemoveLifecycleObserver( LifecycleObserver& observer )
181 mLifecycleObserver = nullptr;
184 private: // From PropertyOwner::Observer
187 * @copydoc PropertyOwner::Observer::PropertyOwnerConnected( PropertyOwner& owner )
189 void PropertyOwnerConnected( PropertyOwner& owner ) final
195 * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
197 void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) final
199 // If we are active, then bake the value if required
200 if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::DISCARD )
202 // Bake to target-value if BakeFinal, otherwise bake current value
203 Update( bufferIndex, ( mDisconnectAction == Dali::Animation::BAKE ? mCurrentProgress : 1.0f ), true );
210 * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed( PropertyOwner& owner )
212 void PropertyOwnerDestroyed( PropertyOwner& owner ) final
214 mPropertyOwner = nullptr;
219 * Called when Animator is added to the scene-graph in update-thread.
221 void ConnectToSceneGraph()
223 mConnectedToSceneGraph = true;
224 mPropertyOwner->AddObserver(*this);
226 // Enable if the target object is valid and connected to the scene graph.
227 mEnabled = mPropertyOwner->IsAnimationPossible();
231 * Set the duration of the animator.
232 * @pre durationSeconds must be zero or greater; zero is useful when animating boolean values.
233 * @param [in] seconds Duration in seconds.
235 void SetDuration(float seconds)
237 DALI_ASSERT_DEBUG(seconds >= 0.0f);
239 mDurationSeconds = seconds;
243 * Retrieve the duration of the animator.
244 * @return The duration in seconds.
246 float GetDuration() const
248 return mDurationSeconds;
251 void SetSpeedFactor( float factor )
253 mSpeedFactor = factor;
256 void SetLoopCount(int32_t loopCount)
258 mLoopCount = loopCount;
261 float SetProgress( float progress )
265 if( mAutoReverseEnabled )
267 if( mSpeedFactor > 0.0f )
269 value = 1.0f - 2.0f * std::abs( progress - 0.5f );
272 else if( mSpeedFactor < 0.0f )
274 value = 2.0f * std::abs( progress - 0.5f );
286 * Set the delay before the animator should take effect.
287 * The default is zero i.e. no delay.
288 * @param [in] seconds The delay in seconds.
290 void SetIntervalDelay(float seconds)
292 mIntervalDelaySeconds = seconds;
296 * Retrieve the delay before the animator should take effect.
297 * @return The delay in seconds.
299 float GetIntervalDelay() const
301 return mIntervalDelaySeconds;
305 * Set the alpha function for an animator.
306 * @param [in] alphaFunc The alpha function to apply to the animation progress.
308 void SetAlphaFunction(const AlphaFunction& alphaFunction)
310 mAlphaFunction = alphaFunction;
314 * Retrieve the alpha function of an animator.
315 * @return The function.
317 AlphaFunction GetAlphaFunction() const
319 return mAlphaFunction;
323 * Applies the alpha function to the specified progress
324 * @param[in] Current progress
325 * @return The progress after the alpha function has been aplied
327 float ApplyAlphaFunction( float progress ) const
329 float result = progress;
331 AlphaFunction::Mode alphaFunctionMode( mAlphaFunction.GetMode() );
332 if( alphaFunctionMode == AlphaFunction::BUILTIN_FUNCTION )
334 switch(mAlphaFunction.GetBuiltinFunction())
336 case AlphaFunction::DEFAULT:
337 case AlphaFunction::LINEAR:
341 case AlphaFunction::REVERSE:
343 result = 1.0f-progress;
346 case AlphaFunction::EASE_IN_SQUARE:
348 result = progress * progress;
351 case AlphaFunction::EASE_OUT_SQUARE:
353 result = 1.0f - (1.0f-progress) * (1.0f-progress);
356 case AlphaFunction::EASE_IN:
358 result = progress * progress * progress;
361 case AlphaFunction::EASE_OUT:
363 result = (progress-1.0f) * (progress-1.0f) * (progress-1.0f) + 1.0f;
366 case AlphaFunction::EASE_IN_OUT:
368 result = progress*progress*(3.0f-2.0f*progress);
371 case AlphaFunction::EASE_IN_SINE:
373 result = -1.0f * cosf(progress * Math::PI_2) + 1.0f;
376 case AlphaFunction::EASE_OUT_SINE:
378 result = sinf(progress * Math::PI_2);
381 case AlphaFunction::EASE_IN_OUT_SINE:
383 result = -0.5f * (cosf(Math::PI * progress) - 1.0f);
386 case AlphaFunction::BOUNCE:
388 result = sinf(progress * Math::PI);
391 case AlphaFunction::SIN:
393 result = 0.5f - cosf(progress * 2.0f * Math::PI) * 0.5f;
396 case AlphaFunction::EASE_OUT_BACK:
398 const float sqrt2 = 1.70158f;
400 result = 1.0f + progress * progress * ( ( sqrt2 + 1.0f ) * progress + sqrt2 );
403 case AlphaFunction::COUNT:
409 else if( alphaFunctionMode == AlphaFunction::CUSTOM_FUNCTION )
411 AlphaFunctionPrototype customFunction = mAlphaFunction.GetCustomFunction();
414 result = customFunction(progress);
419 //If progress is very close to 0 or very close to 1 we don't need to evaluate the curve as the result will
420 //be almost 0 or almost 1 respectively
421 if( ( progress > Math::MACHINE_EPSILON_1 ) && ((1.0f - progress) > Math::MACHINE_EPSILON_1) )
423 Dali::Vector4 controlPoints = mAlphaFunction.GetBezierControlPoints();
425 static const float tolerance = 0.001f; //10 iteration max
427 //Perform a binary search on the curve
428 float lowerBound(0.0f);
429 float upperBound(1.0f);
430 float currentT(0.5f);
431 float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
432 while( fabsf( progress - currentX ) > tolerance )
434 if( progress > currentX )
436 lowerBound = currentT;
440 upperBound = currentT;
442 currentT = (upperBound+lowerBound)*0.5f;
443 currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
445 result = EvaluateCubicBezier( controlPoints.y, controlPoints.w, currentT);
453 * Whether to bake the animation if attached property owner is disconnected.
454 * Property is only baked if the animator is active.
455 * @param [in] action The disconnect action.
457 void SetDisconnectAction( Dali::Animation::EndAction action )
459 mDisconnectAction = action;
463 * Retrieve the disconnect action of an animator.
464 * @return The disconnect action.
466 Dali::Animation::EndAction GetDisconnectAction() const
468 return mDisconnectAction;
472 * Whether the animator is active or not.
473 * @param [in] active The new active state.
474 * @post When the animator becomes active, it applies the disconnect-action if the property owner is then disconnected.
475 * @note When the property owner is disconnected, the active state is set to false.
477 void SetActive( bool active )
479 mAnimationPlaying = active;
483 * Whether the animator's target object is valid and on the stage.
484 * @return The enabled state.
486 bool IsEnabled() const
492 * @brief Sets the looping mode.
493 * @param[in] loopingMode True when the looping mode is AUTO_REVERSE
495 void SetLoopingMode( bool loopingMode )
497 mAutoReverseEnabled = loopingMode;
501 * Returns wheter the target object of the animator is still valid
502 * or has been destroyed.
503 * @return True if animator is orphan, false otherwise *
504 * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
508 return (mPropertyOwner == nullptr);
512 * Update the scene object attached to the animator.
513 * @param[in] bufferIndex The buffer to animate.
514 * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
515 * @param[in] bake Bake.
517 void Update( BufferIndex bufferIndex, float progress, bool bake )
519 if( mLoopCount >= 0 )
521 // Update the progress value
522 progress = SetProgress( progress );
527 mPropertyOwner->SetUpdated( true );
530 float alpha = ApplyAlphaFunction( progress );
532 // PropertyType specific part
533 DoUpdate( bufferIndex, bake, alpha );
535 mCurrentProgress = progress;
539 * Type specific part of the animator
540 * @param bufferIndex index to use
541 * @param bake whether to bake or not
542 * @param alpha value from alpha based on progress
544 virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0;
549 * Helper function to evaluate a cubic bezier curve assuming first point is at 0.0 and last point is at 1.0
550 * @param[in] p0 First control point of the bezier curve
551 * @param[in] p1 Second control point of the bezier curve
552 * @param[in] t A floating point value between 0.0 and 1.0
553 * @return Value of the curve at progress t
555 inline float EvaluateCubicBezier( float p0, float p1, float t ) const
558 return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
561 LifecycleObserver* mLifecycleObserver;
562 PropertyOwner* mPropertyOwner;
563 AnimatorFunctionBase* mAnimatorFunction;
564 float mDurationSeconds;
565 float mIntervalDelaySeconds;
567 float mCurrentProgress;
571 AlphaFunction mAlphaFunction;
573 Dali::Animation::EndAction mDisconnectAction; ///< EndAction to apply when target object gets disconnected from the stage.
574 bool mAnimationPlaying:1; ///< whether disconnect has been applied while it's running.
575 bool mEnabled:1; ///< Animator is "enabled" while its target object is valid and on the stage.
576 bool mConnectedToSceneGraph:1; ///< True if ConnectToSceneGraph() has been called in update-thread.
577 bool mAutoReverseEnabled:1;
581 * An animator for a specific property type PropertyType.
583 template < typename PropertyType, typename PropertyAccessorType >
584 class Animator : public AnimatorBase
589 * Construct a new property animator.
590 * @param[in] property The animatable property; only valid while the Animator is attached.
591 * @param[in] animatorFunction The function used to animate the property.
592 * @param[in] alphaFunction The alpha function to apply.
593 * @param[in] timePeriod The time period of this animation.
594 * @return A newly allocated animator.
596 static AnimatorBase* New( const PropertyOwner& propertyOwner,
597 const PropertyBase& property,
598 AnimatorFunctionBase* animatorFunction,
599 AlphaFunction alphaFunction,
600 const TimePeriod& timePeriod )
602 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
603 return new Animator( const_cast<PropertyOwner*>( &propertyOwner ),
604 const_cast<PropertyBase*>( &property ),
611 * Virtual destructor.
613 ~Animator() override = default;
616 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
618 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
620 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
622 // need to cast the return value in case property is integer
623 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
627 mPropertyAccessor.Bake( bufferIndex, result );
631 mPropertyAccessor.Set( bufferIndex, result );
638 * Private constructor; see also Animator::New().
640 Animator( PropertyOwner* propertyOwner,
641 PropertyBase* property,
642 AnimatorFunctionBase* animatorFunction,
643 AlphaFunction alphaFunction,
644 const TimePeriod& timePeriod )
645 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
646 mPropertyAccessor( property )
648 // WARNING - this object is created in the event-thread
649 // The scene-graph mPropertyOwner object cannot be observed here
653 Animator( const Animator& );
656 Animator& operator=( const Animator& );
660 PropertyAccessorType mPropertyAccessor;
667 * An animator for a specific property type PropertyType.
669 template <typename PropertyType, typename PropertyAccessorType>
670 class AnimatorTransformProperty : public AnimatorBase
675 * Construct a new property animator.
676 * @param[in] property The animatable property; only valid while the Animator is attached.
677 * @param[in] animatorFunction The function used to animate the property.
678 * @param[in] alphaFunction The alpha function to apply.
679 * @param[in] timePeriod The time period of this animation.
680 * @return A newly allocated animator.
682 static AnimatorBase* New( const PropertyOwner& propertyOwner,
683 const PropertyBase& property,
684 AnimatorFunctionBase* animatorFunction,
685 AlphaFunction alphaFunction,
686 const TimePeriod& timePeriod )
689 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
690 return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
691 const_cast<PropertyBase*>( &property ),
698 * Virtual destructor.
700 ~AnimatorTransformProperty() override = default;
703 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
705 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
707 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
709 // need to cast the return value in case property is integer
710 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
714 mPropertyAccessor.Bake( bufferIndex, result );
718 mPropertyAccessor.Set( bufferIndex, result );
725 * Private constructor; see also Animator::New().
727 AnimatorTransformProperty( PropertyOwner* propertyOwner,
728 PropertyBase* property,
729 AnimatorFunctionBase* animatorFunction,
730 AlphaFunction alphaFunction,
731 const TimePeriod& timePeriod )
732 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
733 mPropertyAccessor( property )
735 // WARNING - this object is created in the event-thread
736 // The scene-graph mPropertyOwner object cannot be observed here
740 AnimatorTransformProperty() = delete;
741 AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
742 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
746 PropertyAccessorType mPropertyAccessor;
750 } // namespace SceneGraph
754 struct AnimateByInteger : public AnimatorFunctionBase
756 AnimateByInteger(const int& relativeValue)
757 : mRelative(relativeValue)
761 using AnimatorFunctionBase::operator();
762 float operator()(float alpha, const int32_t& property) override
764 // integers need to be correctly rounded
765 return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
771 struct AnimateToInteger : public AnimatorFunctionBase
773 AnimateToInteger(const int& targetValue)
774 : mTarget(targetValue)
778 using AnimatorFunctionBase::operator();
779 float operator()(float alpha, const int32_t& property) override
781 // integers need to be correctly rounded
782 return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
788 struct AnimateByFloat : public AnimatorFunctionBase
790 AnimateByFloat(const float& relativeValue)
791 : mRelative(relativeValue)
795 using AnimatorFunctionBase::operator();
796 float operator()(float alpha, const float& property) override
798 return float(property + mRelative * alpha);
804 struct AnimateToFloat : public AnimatorFunctionBase
806 AnimateToFloat(const float& targetValue)
807 : mTarget(targetValue)
811 using AnimatorFunctionBase::operator();
812 float operator()(float alpha, const float& property) override
814 return float(property + ((mTarget - property) * alpha));
820 struct AnimateByVector2 : public AnimatorFunctionBase
822 AnimateByVector2(const Vector2& relativeValue)
823 : mRelative(relativeValue)
827 using AnimatorFunctionBase::operator();
828 Vector2 operator()(float alpha, const Vector2& property) override
830 return Vector2(property + mRelative * alpha);
836 struct AnimateToVector2 : public AnimatorFunctionBase
838 AnimateToVector2(const Vector2& targetValue)
839 : mTarget(targetValue)
843 using AnimatorFunctionBase::operator();
844 Vector2 operator()(float alpha, const Vector2& property) override
846 return Vector2(property + ((mTarget - property) * alpha));
852 struct AnimateByVector3 : public AnimatorFunctionBase
854 AnimateByVector3(const Vector3& relativeValue)
855 : mRelative(relativeValue)
859 using AnimatorFunctionBase::operator();
860 Vector3 operator()(float alpha, const Vector3& property) override
862 return Vector3(property + mRelative * alpha);
868 struct AnimateToVector3 : public AnimatorFunctionBase
870 AnimateToVector3(const Vector3& targetValue)
871 : mTarget(targetValue)
875 using AnimatorFunctionBase::operator();
876 Vector3 operator()(float alpha, const Vector3& property) override
878 return Vector3(property + ((mTarget - property) * alpha));
884 struct AnimateByVector4 : public AnimatorFunctionBase
886 AnimateByVector4(const Vector4& relativeValue)
887 : mRelative(relativeValue)
891 using AnimatorFunctionBase::operator();
892 Vector4 operator()(float alpha, const Vector4& property) override
894 return Vector4(property + mRelative * alpha);
900 struct AnimateToVector4 : public AnimatorFunctionBase
902 AnimateToVector4(const Vector4& targetValue)
903 : mTarget(targetValue)
907 using AnimatorFunctionBase::operator();
908 Vector4 operator()(float alpha, const Vector4& property) override
910 return Vector4(property + ((mTarget - property) * alpha));
916 struct AnimateByOpacity : public AnimatorFunctionBase
918 AnimateByOpacity(const float& relativeValue)
919 : mRelative(relativeValue)
923 using AnimatorFunctionBase::operator();
924 Vector4 operator()(float alpha, const Vector4& property) override
926 Vector4 result(property);
927 result.a += mRelative * alpha;
935 struct AnimateToOpacity : public AnimatorFunctionBase
937 AnimateToOpacity(const float& targetValue)
938 : mTarget(targetValue)
942 using AnimatorFunctionBase::operator();
943 Vector4 operator()(float alpha, const Vector4& property) override
945 Vector4 result(property);
946 result.a = property.a + ((mTarget - property.a) * alpha);
954 struct AnimateByBoolean : public AnimatorFunctionBase
956 AnimateByBoolean(bool relativeValue)
957 : mRelative(relativeValue)
961 using AnimatorFunctionBase::operator();
962 bool operator()(float alpha, const bool& property) override
964 // Alpha is not useful here, just keeping to the same template as other update functors
965 return bool(alpha >= 1.0f ? (property || mRelative) : property);
971 struct AnimateToBoolean : public AnimatorFunctionBase
973 AnimateToBoolean(bool targetValue)
974 : mTarget(targetValue)
978 using AnimatorFunctionBase::operator();
979 bool operator()(float alpha, const bool& property) override
981 // Alpha is not useful here, just keeping to the same template as other update functors
982 return bool(alpha >= 1.0f ? mTarget : property);
988 struct RotateByAngleAxis : public AnimatorFunctionBase
990 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
991 : mAngleRadians( angleRadians ),
992 mAxis(axis.x, axis.y, axis.z)
996 using AnimatorFunctionBase::operator();
997 Quaternion operator()(float alpha, const Quaternion& rotation) override
1001 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1007 Radian mAngleRadians;
1011 struct RotateToQuaternion : public AnimatorFunctionBase
1013 RotateToQuaternion(const Quaternion& targetValue)
1014 : mTarget(targetValue)
1018 using AnimatorFunctionBase::operator();
1019 Quaternion operator()(float alpha, const Quaternion& rotation) override
1021 return Quaternion::Slerp(rotation, mTarget, alpha);
1028 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1030 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1031 : mKeyFrames(keyFrames)
1035 using AnimatorFunctionBase::operator();
1036 bool operator()(float progress, const bool& property) override
1038 if(mKeyFrames->IsActive(progress))
1040 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1045 KeyFrameBooleanPtr mKeyFrames;
1048 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1050 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1051 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1055 using AnimatorFunctionBase::operator();
1056 float operator()(float progress, const int32_t& property) override
1058 if(mKeyFrames->IsActive(progress))
1060 return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
1062 return static_cast<float>( property );
1065 KeyFrameIntegerPtr mKeyFrames;
1066 Interpolation mInterpolation;
1069 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1071 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1072 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1076 using AnimatorFunctionBase::operator();
1077 float operator()(float progress, const float& property) override
1079 if(mKeyFrames->IsActive(progress))
1081 return mKeyFrames->GetValue(progress, mInterpolation);
1086 KeyFrameNumberPtr mKeyFrames;
1087 Interpolation mInterpolation;
1090 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1092 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1093 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1097 using AnimatorFunctionBase::operator();
1098 Vector2 operator()(float progress, const Vector2& property) override
1100 if(mKeyFrames->IsActive(progress))
1102 return mKeyFrames->GetValue(progress, mInterpolation);
1107 KeyFrameVector2Ptr mKeyFrames;
1108 Interpolation mInterpolation;
1112 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1114 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1115 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1119 using AnimatorFunctionBase::operator();
1120 Vector3 operator()(float progress, const Vector3& property) override
1122 if(mKeyFrames->IsActive(progress))
1124 return mKeyFrames->GetValue(progress, mInterpolation);
1129 KeyFrameVector3Ptr mKeyFrames;
1130 Interpolation mInterpolation;
1133 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1135 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1136 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1140 using AnimatorFunctionBase::operator();
1141 Vector4 operator()(float progress, const Vector4& property) override
1143 if(mKeyFrames->IsActive(progress))
1145 return mKeyFrames->GetValue(progress, mInterpolation);
1150 KeyFrameVector4Ptr mKeyFrames;
1151 Interpolation mInterpolation;
1154 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1156 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1157 : mKeyFrames(keyFrames)
1161 using AnimatorFunctionBase::operator();
1162 Quaternion operator()(float progress, const Quaternion& property) override
1164 if(mKeyFrames->IsActive(progress))
1166 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1171 KeyFrameQuaternionPtr mKeyFrames;
1174 struct PathPositionFunctor : public AnimatorFunctionBase
1176 PathPositionFunctor( PathPtr path )
1181 using AnimatorFunctionBase::operator();
1182 Vector3 operator()(float progress, const Vector3& property) override
1184 Vector3 position(property);
1185 static_cast<void>( mPath->SamplePosition(progress, position) );
1192 struct PathRotationFunctor : public AnimatorFunctionBase
1194 PathRotationFunctor( PathPtr path, const Vector3& forward )
1198 mForward.Normalize();
1201 using AnimatorFunctionBase::operator();
1202 Quaternion operator()(float progress, const Quaternion& property) override
1205 if( mPath->SampleTangent(progress, tangent) )
1207 return Quaternion( mForward, tangent );
1219 } // namespace Internal
1223 #endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H