2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <boost/function.hpp>
22 #include <dali/public-api/animation/interpolator-functions.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/vector3.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/math/quaternion.h>
27 #include <dali/public-api/math/matrix.h>
28 #include <dali/public-api/math/matrix3.h>
33 bool LerpBoolean( const bool& current, const bool& target, float progress )
35 // Not particularly useful for boolean values
44 float LerpFloat( const float& current, const float& target, float progress )
46 return current + ((target - current) * progress);
49 int LerpInteger( const int& current, const int& target, float progress )
51 return static_cast<int>( current + ( (target - current) * progress ) + 0.5f );
54 Dali::Vector2 LerpVector2( const Dali::Vector2& current, const Dali::Vector2& target, float progress )
56 return current + ((target - current) * progress);
59 Dali::Vector3 LerpVector3( const Dali::Vector3& current, const Dali::Vector3& target, float progress )
61 return current + ((target - current) * progress);
64 Dali::Vector4 LerpVector4( const Dali::Vector4& current, const Dali::Vector4& target, float progress )
66 return current + ((target - current) * progress);
69 Dali::Quaternion SlerpQuaternion( const Dali::Quaternion& current, const Dali::Quaternion& target, float progress )
71 return Dali::Quaternion::Slerp(current, target, progress);
74 Dali::Matrix LerpMatrix( const Dali::Matrix& current, const Dali::Matrix& target, float progress )
84 Dali::Matrix3 LerpMatrix3( const Dali::Matrix3& current, const Dali::Matrix3& target, float progress )
94 } // unnamed namespace
99 AnyInterpolator GetDefaultInterpolator( Property::Type type )
101 AnyInterpolator function;
105 case Property::BOOLEAN:
107 function = boost::function<bool (const bool&, const bool&, float)>( &LerpBoolean );
111 case Property::FLOAT:
113 function = boost::function<float (const float&, const float&, float)>( &LerpFloat );
117 case Property::INTEGER:
119 function = boost::function<int (const int&, const int&, float)>( &LerpInteger );
123 case Property::VECTOR2:
125 function = boost::function<Vector2 (const Vector2&, const Vector2&, float)>( &LerpVector2 );
129 case Property::VECTOR3:
131 function = boost::function<Vector3 (const Vector3&, const Vector3&, float)>( &LerpVector3 );
135 case Property::VECTOR4:
137 function = boost::function<Vector4 (const Vector4&, const Vector4&, float)>( &LerpVector4 );
141 case Property::ROTATION:
143 function = boost::function<Quaternion (const Quaternion&, const Quaternion&, float)>( &SlerpQuaternion );
147 case Property::MATRIX3:
149 function = boost::function<Matrix3 (const Matrix3&, const Matrix3&, float)>(&LerpMatrix3);
153 case Property::MATRIX:
155 function = boost::function<Matrix (const Matrix&, const Matrix&, float)>(&LerpMatrix);