1d92f8879fac37cdeabd6cd49cda14065fc5f192
[platform/core/uifw/dali-core.git] / dali / public-api / animation / animator-functions.h
1 #ifndef __DALI_ANIMATOR_FUNCTIONS_H__
2 #define __DALI_ANIMATOR_FUNCTIONS_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/math/quaternion.h>
24
25
26 namespace Dali DALI_IMPORT_API
27 {
28
29 namespace AnimatorFunctions
30 {
31
32 /**
33  * @brief Function object that interpolates using a bounce shape.
34  */
35 struct BounceFunc
36 {
37   /**
38    * @brief Constructor.
39    */
40   BounceFunc(float x, float y, float z);
41
42   /**
43    * @brief functor
44    */
45   Vector3 operator()(float alpha, const Vector3& current);
46
47   Vector3 mDistance; ///< Distance to bounce
48 };
49
50 /**
51  * @brief Function object that rotates about a random axis twice.
52  */
53 struct TumbleFunc
54 {
55   /**
56    * @brief Factory method to create a functor with a random axis.
57    */
58   static TumbleFunc GetRandom();
59
60   /**
61    * @brief Class method to return a random float in the given range
62    */
63   static float Randomize(float f0, float f1);
64
65   /**
66    * @brief Constructor.
67    *
68    * @param[in] x The x component of the axis
69    * @param[in] y The y component of the axis
70    * @param[in] z The z component of the axis
71    */
72   TumbleFunc(float x, float y, float z);
73
74   /**
75    * @brief Functor to get the current rotation.
76    * @param[in] alpha The alpha value (the output of an alpha function)
77    * @param[in] current The current property value
78    * @return The output rotation
79    */
80   Quaternion operator()(float alpha, const Quaternion& current);
81
82   Vector4 tumbleAxis; ///< The axis about which to rotate
83 };
84
85 /**
86  * @brief Animator functor that allows provide a timer as input to an animation.
87  *
88  * The functor returns: scale * ( numberOfLoops + progress )
89  */
90 struct Timer
91 {
92   /**
93    * @brief Constructor
94    *
95    * @param[in] scale Factor by which to multiply progress.
96    */
97   Timer(float scale);
98
99   /**
100    * @brief Functor to return the time.
101    * @param[in] progress The animation progress (0-1)
102    * @param[in] current The current property value.
103    * @return Time since start of animation
104    */
105   float operator()(float progress, const float& current);
106
107 private:
108   unsigned int mLoopCounter; ///< Number of times this functor has seen looping progress
109   float mPrevious;           ///< The last progress value
110   float mScale;              ///< factor by which to multiply progress.
111 };
112
113 } // namespace AnimatorFunctions
114
115 } // namespace Dali
116
117
118 #endif // __DALI_ANIMATOR_FUNCTIONS_H__