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::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.
618 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
620 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
622 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
624 // need to cast the return value in case property is integer
625 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
629 mPropertyAccessor.Bake( bufferIndex, result );
633 mPropertyAccessor.Set( bufferIndex, result );
640 * Private constructor; see also Animator::New().
642 Animator( PropertyOwner* propertyOwner,
643 PropertyBase* property,
644 AnimatorFunctionBase* animatorFunction,
645 AlphaFunction alphaFunction,
646 const TimePeriod& timePeriod )
647 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
648 mPropertyAccessor( property )
650 // WARNING - this object is created in the event-thread
651 // The scene-graph mPropertyOwner object cannot be observed here
655 Animator( const Animator& );
658 Animator& operator=( const Animator& );
662 PropertyAccessorType mPropertyAccessor;
669 * An animator for a specific property type PropertyType.
671 template <typename PropertyType, typename PropertyAccessorType>
672 class AnimatorTransformProperty : public AnimatorBase
677 * Construct a new property animator.
678 * @param[in] property The animatable property; only valid while the Animator is attached.
679 * @param[in] animatorFunction The function used to animate the property.
680 * @param[in] alphaFunction The alpha function to apply.
681 * @param[in] timePeriod The time period of this animation.
682 * @return A newly allocated animator.
684 static AnimatorBase* New( const PropertyOwner& propertyOwner,
685 const PropertyBase& property,
686 AnimatorFunctionBase* animatorFunction,
687 AlphaFunction alphaFunction,
688 const TimePeriod& timePeriod )
691 // The property was const in the actor-thread, but animators are used in the scene-graph thread.
692 return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
693 const_cast<PropertyBase*>( &property ),
700 * Virtual destructor.
702 ~AnimatorTransformProperty() override
707 * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
709 void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) final
711 const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
713 // need to cast the return value in case property is integer
714 const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
718 mPropertyAccessor.Bake( bufferIndex, result );
722 mPropertyAccessor.Set( bufferIndex, result );
729 * Private constructor; see also Animator::New().
731 AnimatorTransformProperty( PropertyOwner* propertyOwner,
732 PropertyBase* property,
733 AnimatorFunctionBase* animatorFunction,
734 AlphaFunction alphaFunction,
735 const TimePeriod& timePeriod )
736 : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
737 mPropertyAccessor( property )
739 // WARNING - this object is created in the event-thread
740 // The scene-graph mPropertyOwner object cannot be observed here
744 AnimatorTransformProperty() = delete;
745 AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
746 AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
750 PropertyAccessorType mPropertyAccessor;
754 } // namespace SceneGraph
758 struct AnimateByInteger : public AnimatorFunctionBase
760 AnimateByInteger(const int& relativeValue)
761 : mRelative(relativeValue)
765 using AnimatorFunctionBase::operator();
766 float operator()(float alpha, const int32_t& property) override
768 // integers need to be correctly rounded
769 return roundf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha );
775 struct AnimateToInteger : public AnimatorFunctionBase
777 AnimateToInteger(const int& targetValue)
778 : mTarget(targetValue)
782 using AnimatorFunctionBase::operator();
783 float operator()(float alpha, const int32_t& property) override
785 // integers need to be correctly rounded
786 return roundf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) );
792 struct AnimateByFloat : public AnimatorFunctionBase
794 AnimateByFloat(const float& relativeValue)
795 : mRelative(relativeValue)
799 using AnimatorFunctionBase::operator();
800 float operator()(float alpha, const float& property) override
802 return float(property + mRelative * alpha);
808 struct AnimateToFloat : public AnimatorFunctionBase
810 AnimateToFloat(const float& targetValue)
811 : mTarget(targetValue)
815 using AnimatorFunctionBase::operator();
816 float operator()(float alpha, const float& property) override
818 return float(property + ((mTarget - property) * alpha));
824 struct AnimateByVector2 : public AnimatorFunctionBase
826 AnimateByVector2(const Vector2& relativeValue)
827 : mRelative(relativeValue)
831 using AnimatorFunctionBase::operator();
832 Vector2 operator()(float alpha, const Vector2& property) override
834 return Vector2(property + mRelative * alpha);
840 struct AnimateToVector2 : public AnimatorFunctionBase
842 AnimateToVector2(const Vector2& targetValue)
843 : mTarget(targetValue)
847 using AnimatorFunctionBase::operator();
848 Vector2 operator()(float alpha, const Vector2& property) override
850 return Vector2(property + ((mTarget - property) * alpha));
856 struct AnimateByVector3 : public AnimatorFunctionBase
858 AnimateByVector3(const Vector3& relativeValue)
859 : mRelative(relativeValue)
863 using AnimatorFunctionBase::operator();
864 Vector3 operator()(float alpha, const Vector3& property) override
866 return Vector3(property + mRelative * alpha);
872 struct AnimateToVector3 : public AnimatorFunctionBase
874 AnimateToVector3(const Vector3& targetValue)
875 : mTarget(targetValue)
879 using AnimatorFunctionBase::operator();
880 Vector3 operator()(float alpha, const Vector3& property) override
882 return Vector3(property + ((mTarget - property) * alpha));
888 struct AnimateByVector4 : public AnimatorFunctionBase
890 AnimateByVector4(const Vector4& relativeValue)
891 : mRelative(relativeValue)
895 using AnimatorFunctionBase::operator();
896 Vector4 operator()(float alpha, const Vector4& property) override
898 return Vector4(property + mRelative * alpha);
904 struct AnimateToVector4 : public AnimatorFunctionBase
906 AnimateToVector4(const Vector4& targetValue)
907 : mTarget(targetValue)
911 using AnimatorFunctionBase::operator();
912 Vector4 operator()(float alpha, const Vector4& property) override
914 return Vector4(property + ((mTarget - property) * alpha));
920 struct AnimateByOpacity : public AnimatorFunctionBase
922 AnimateByOpacity(const float& relativeValue)
923 : mRelative(relativeValue)
927 using AnimatorFunctionBase::operator();
928 Vector4 operator()(float alpha, const Vector4& property) override
930 Vector4 result(property);
931 result.a += mRelative * alpha;
939 struct AnimateToOpacity : public AnimatorFunctionBase
941 AnimateToOpacity(const float& targetValue)
942 : mTarget(targetValue)
946 using AnimatorFunctionBase::operator();
947 Vector4 operator()(float alpha, const Vector4& property) override
949 Vector4 result(property);
950 result.a = property.a + ((mTarget - property.a) * alpha);
958 struct AnimateByBoolean : public AnimatorFunctionBase
960 AnimateByBoolean(bool relativeValue)
961 : mRelative(relativeValue)
965 using AnimatorFunctionBase::operator();
966 bool operator()(float alpha, const bool& property) override
968 // Alpha is not useful here, just keeping to the same template as other update functors
969 return bool(alpha >= 1.0f ? (property || mRelative) : property);
975 struct AnimateToBoolean : public AnimatorFunctionBase
977 AnimateToBoolean(bool targetValue)
978 : mTarget(targetValue)
982 using AnimatorFunctionBase::operator();
983 bool operator()(float alpha, const bool& property) override
985 // Alpha is not useful here, just keeping to the same template as other update functors
986 return bool(alpha >= 1.0f ? mTarget : property);
992 struct RotateByAngleAxis : public AnimatorFunctionBase
994 RotateByAngleAxis(const Radian& angleRadians, const Vector3& axis)
995 : mAngleRadians( angleRadians ),
996 mAxis(axis.x, axis.y, axis.z)
1000 using AnimatorFunctionBase::operator();
1001 Quaternion operator()(float alpha, const Quaternion& rotation) override
1005 return rotation * Quaternion(mAngleRadians * alpha, mAxis);
1011 Radian mAngleRadians;
1015 struct RotateToQuaternion : public AnimatorFunctionBase
1017 RotateToQuaternion(const Quaternion& targetValue)
1018 : mTarget(targetValue)
1022 using AnimatorFunctionBase::operator();
1023 Quaternion operator()(float alpha, const Quaternion& rotation) override
1025 return Quaternion::Slerp(rotation, mTarget, alpha);
1032 struct KeyFrameBooleanFunctor : public AnimatorFunctionBase
1034 KeyFrameBooleanFunctor(KeyFrameBooleanPtr keyFrames)
1035 : mKeyFrames(keyFrames)
1039 using AnimatorFunctionBase::operator();
1040 bool operator()(float progress, const bool& property) override
1042 if(mKeyFrames->IsActive(progress))
1044 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1049 KeyFrameBooleanPtr mKeyFrames;
1052 struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
1054 KeyFrameIntegerFunctor(KeyFrameIntegerPtr keyFrames, Interpolation interpolation)
1055 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1059 using AnimatorFunctionBase::operator();
1060 float operator()(float progress, const int32_t& property) override
1062 if(mKeyFrames->IsActive(progress))
1064 return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
1066 return static_cast<float>( property );
1069 KeyFrameIntegerPtr mKeyFrames;
1070 Interpolation mInterpolation;
1073 struct KeyFrameNumberFunctor : public AnimatorFunctionBase
1075 KeyFrameNumberFunctor(KeyFrameNumberPtr keyFrames, Interpolation interpolation)
1076 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1080 using AnimatorFunctionBase::operator();
1081 float operator()(float progress, const float& property) override
1083 if(mKeyFrames->IsActive(progress))
1085 return mKeyFrames->GetValue(progress, mInterpolation);
1090 KeyFrameNumberPtr mKeyFrames;
1091 Interpolation mInterpolation;
1094 struct KeyFrameVector2Functor : public AnimatorFunctionBase
1096 KeyFrameVector2Functor(KeyFrameVector2Ptr keyFrames, Interpolation interpolation)
1097 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1101 using AnimatorFunctionBase::operator();
1102 Vector2 operator()(float progress, const Vector2& property) override
1104 if(mKeyFrames->IsActive(progress))
1106 return mKeyFrames->GetValue(progress, mInterpolation);
1111 KeyFrameVector2Ptr mKeyFrames;
1112 Interpolation mInterpolation;
1116 struct KeyFrameVector3Functor : public AnimatorFunctionBase
1118 KeyFrameVector3Functor(KeyFrameVector3Ptr keyFrames, Interpolation interpolation)
1119 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1123 using AnimatorFunctionBase::operator();
1124 Vector3 operator()(float progress, const Vector3& property) override
1126 if(mKeyFrames->IsActive(progress))
1128 return mKeyFrames->GetValue(progress, mInterpolation);
1133 KeyFrameVector3Ptr mKeyFrames;
1134 Interpolation mInterpolation;
1137 struct KeyFrameVector4Functor : public AnimatorFunctionBase
1139 KeyFrameVector4Functor(KeyFrameVector4Ptr keyFrames, Interpolation interpolation)
1140 : mKeyFrames(keyFrames),mInterpolation(interpolation)
1144 using AnimatorFunctionBase::operator();
1145 Vector4 operator()(float progress, const Vector4& property) override
1147 if(mKeyFrames->IsActive(progress))
1149 return mKeyFrames->GetValue(progress, mInterpolation);
1154 KeyFrameVector4Ptr mKeyFrames;
1155 Interpolation mInterpolation;
1158 struct KeyFrameQuaternionFunctor : public AnimatorFunctionBase
1160 KeyFrameQuaternionFunctor(KeyFrameQuaternionPtr keyFrames)
1161 : mKeyFrames(keyFrames)
1165 using AnimatorFunctionBase::operator();
1166 Quaternion operator()(float progress, const Quaternion& property) override
1168 if(mKeyFrames->IsActive(progress))
1170 return mKeyFrames->GetValue(progress, Dali::Animation::LINEAR);
1175 KeyFrameQuaternionPtr mKeyFrames;
1178 struct PathPositionFunctor : public AnimatorFunctionBase
1180 PathPositionFunctor( PathPtr path )
1185 using AnimatorFunctionBase::operator();
1186 Vector3 operator()(float progress, const Vector3& property) override
1188 Vector3 position(property);
1189 static_cast<void>( mPath->SamplePosition(progress, position) );
1196 struct PathRotationFunctor : public AnimatorFunctionBase
1198 PathRotationFunctor( PathPtr path, const Vector3& forward )
1202 mForward.Normalize();
1205 using AnimatorFunctionBase::operator();
1206 Quaternion operator()(float progress, const Quaternion& property) override
1209 if( mPath->SampleTangent(progress, tangent) )
1211 return Quaternion( mForward, tangent );
1223 } // namespace Internal
1227 #endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H