Merge "Change shader data pointer to IntrusivePtr" into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / animation / interpolator-functions.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // EXTERNAL INCLUDES
19 #include <boost/function.hpp>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/animation/interpolator-functions.h>
23
24 namespace Dali
25 {
26
27 bool LerpBoolean( const bool& current, const bool& target, float progress )
28 {
29   // Not particularly useful for boolean values
30   if (progress >= 1.0f)
31   {
32     return target;
33   }
34
35   return current;
36 }
37
38 float LerpFloat( const float& current, const float& target, float progress )
39 {
40   return current + ((target - current) * progress);
41 }
42
43 int LerpInteger( const int& current, const int& target, float progress )
44 {
45   return static_cast<int>( current + ( (target - current) * progress ) + 0.5f );
46 }
47
48 Vector2 LerpVector2( const Vector2& current, const Vector2& target, float progress )
49 {
50   return current + ((target - current) * progress);
51 }
52
53 Vector3 LerpVector3( const Vector3& current, const Vector3& target, float progress )
54 {
55   return current + ((target - current) * progress);
56 }
57
58 Vector4 LerpVector4( const Vector4& current, const Vector4& target, float progress )
59 {
60   return current + ((target - current) * progress);
61 }
62
63 Quaternion SlerpQuaternion( const Quaternion& current, const Quaternion& target, float progress )
64 {
65   return Quaternion::Slerp(current, target, progress);
66 }
67
68 Matrix LerpMatrix( const Matrix& current, const Matrix& target, float progress )
69 {
70   if (progress > 0.5f)
71   {
72     return target;
73   }
74
75   return current;
76 }
77
78 Matrix3 LerpMatrix3( const Matrix3& current, const Matrix3& target, float progress )
79 {
80   if (progress > 0.5f)
81   {
82     return target;
83   }
84
85   return current;
86 }
87
88 AnyInterpolator GetDefaultInterpolator( Property::Type type )
89 {
90   AnyInterpolator function;
91
92   switch ( type )
93   {
94     case Property::BOOLEAN:
95     {
96       function = boost::function<bool (const bool&, const bool&, float)>( &LerpBoolean );
97       break;
98     }
99
100     case Property::FLOAT:
101     {
102       function = boost::function<float (const float&, const float&, float)>( &LerpFloat );
103       break;
104     }
105
106     case Property::INTEGER:
107     {
108       function = boost::function<int (const int&, const int&, float)>( &LerpInteger );
109       break;
110     }
111
112     case Property::VECTOR2:
113     {
114       function = boost::function<Vector2 (const Vector2&, const Vector2&, float)>( &LerpVector2 );
115       break;
116     }
117
118     case Property::VECTOR3:
119     {
120       function = boost::function<Vector3 (const Vector3&, const Vector3&, float)>( &LerpVector3 );
121       break;
122     }
123
124     case Property::VECTOR4:
125     {
126       function = boost::function<Vector4 (const Vector4&, const Vector4&, float)>( &LerpVector4 );
127       break;
128     }
129
130     case Property::ROTATION:
131     {
132       function = boost::function<Quaternion (const Quaternion&, const Quaternion&, float)>( &SlerpQuaternion );
133       break;
134     }
135
136     case Property::MATRIX3:
137     {
138       function = boost::function<Matrix3 (const Matrix3&, const Matrix3&, float)>(&LerpMatrix3);
139       break;
140     }
141
142     case Property::MATRIX:
143     {
144       function = boost::function<Matrix (const Matrix&, const Matrix&, float)>(&LerpMatrix);
145       break;
146     }
147
148     default:
149       break;
150   }
151
152   return function;
153 }
154
155
156 } // namespace Dali