License conversion from Flora to Apache 2.0
[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 Vector2 LerpVector2( const Vector2& current, const Vector2& target, float progress )
44 {
45   return current + ((target - current) * progress);
46 }
47
48 Vector3 LerpVector3( const Vector3& current, const Vector3& target, float progress )
49 {
50   return current + ((target - current) * progress);
51 }
52
53 Vector4 LerpVector4( const Vector4& current, const Vector4& target, float progress )
54 {
55   return current + ((target - current) * progress);
56 }
57
58 Quaternion SlerpQuaternion( const Quaternion& current, const Quaternion& target, float progress )
59 {
60   return Quaternion::Slerp(current, target, progress);
61 }
62
63 Matrix LerpMatrix( const Matrix& current, const Matrix& target, float progress )
64 {
65   if (progress > 0.5f)
66   {
67     return target;
68   }
69
70   return current;
71 }
72
73 Matrix3 LerpMatrix3( const Matrix3& current, const Matrix3& target, float progress )
74 {
75   if (progress > 0.5f)
76   {
77     return target;
78   }
79
80   return current;
81 }
82
83 AnyInterpolator GetDefaultInterpolator( Property::Type type )
84 {
85   AnyInterpolator function;
86
87   switch ( type )
88   {
89     case Property::BOOLEAN:
90     {
91       function = boost::function<bool (const bool&, const bool&, float)>( &LerpBoolean );
92       break;
93     }
94
95     case Property::FLOAT:
96     {
97       function = boost::function<float (const float&, const float&, float)>( &LerpFloat );
98       break;
99     }
100
101     case Property::VECTOR2:
102     {
103       function = boost::function<Vector2 (const Vector2&, const Vector2&, float)>( &LerpVector2 );
104       break;
105     }
106
107     case Property::VECTOR3:
108     {
109       function = boost::function<Vector3 (const Vector3&, const Vector3&, float)>( &LerpVector3 );
110       break;
111     }
112
113     case Property::VECTOR4:
114     {
115       function = boost::function<Vector4 (const Vector4&, const Vector4&, float)>( &LerpVector4 );
116       break;
117     }
118
119     case Property::ROTATION:
120     {
121       function = boost::function<Quaternion (const Quaternion&, const Quaternion&, float)>( &SlerpQuaternion );
122       break;
123     }
124
125     case Property::MATRIX3:
126     {
127       function = boost::function<Matrix3 (const Matrix3&, const Matrix3&, float)>(&LerpMatrix3);
128       break;
129     }
130
131     case Property::MATRIX:
132     {
133       function = boost::function<Matrix (const Matrix&, const Matrix&, float)>(&LerpMatrix);
134       break;
135     }
136
137     default:
138       break;
139   }
140
141   return function;
142 }
143
144
145 } // namespace Dali