1 #ifndef __DALI_INTERNAL_PROGRESS_VALUE_H__
2 #define __DALI_INTERNAL_PROGRESS_VALUE_H__
5 * Copyright (c) 2014 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.
22 #include <dali/public-api/math/quaternion.h>
23 #include <dali/public-api/math/vector3.h>
24 #include <dali/public-api/math/radian.h>
25 #include <dali/public-api/math/degree.h>
34 * Progress / value pair for animating channels (properties) with keyframes
40 ProgressValue (float progress, T value)
41 : mProgress(progress),
50 float GetProgress () const
55 const T& GetValue () const
61 float mProgress; ///< Progress this value applies to animation channel
62 T mValue; ///< value this animation channel should take
65 typedef ProgressValue<Quaternion> ProgressQuaternion;
66 typedef std::vector<ProgressQuaternion> ProgressQuaternionContainer;
68 typedef ProgressValue<AngleAxis> ProgressAngleAxis;
69 typedef std::vector<AngleAxis> ProgressAngleAxisContainer;
71 typedef ProgressValue<bool> ProgressBoolean;
72 typedef std::vector<ProgressBoolean> ProgressBooleanContainer;
74 typedef ProgressValue<float> ProgressNumber;
75 typedef std::vector<ProgressNumber> ProgressNumberContainer;
77 typedef ProgressValue<int> ProgressInteger;
78 typedef std::vector<ProgressInteger> ProgressIntegerContainer;
80 typedef ProgressValue<Vector2> ProgressVector2;
81 typedef std::vector<ProgressVector2> ProgressVector2Container;
83 typedef ProgressValue<Vector3> ProgressVector3;
84 typedef std::vector<ProgressVector3> ProgressVector3Container;
86 typedef ProgressValue<Vector4> ProgressVector4;
87 typedef std::vector<ProgressVector4> ProgressVector4Container;
89 inline Quaternion Interpolate (ProgressQuaternion& a, ProgressQuaternion& b, float progress)
91 return Quaternion::Slerp(a.GetValue(), b.GetValue(), progress);
94 inline AngleAxis Interpolate (ProgressAngleAxis& a, ProgressAngleAxis& b, float progress)
96 AngleAxis av(a.GetValue());
97 AngleAxis bv(b.GetValue());
98 Quaternion q1(Radian(av.angle), av.axis);
99 Quaternion q2(Radian(bv.angle), bv.axis);
101 Quaternion iq = Quaternion::Slerp(q1, q2, progress);
103 iq.ToAxisAngle(result.axis, result.angle);
108 inline bool Interpolate (ProgressBoolean& a, ProgressBoolean& b, float progress)
110 return progress < 0.5f ? a.GetValue() : b.GetValue();
113 inline float Interpolate (ProgressNumber& a, ProgressNumber& b, float progress)
115 return (a.GetValue() + (b.GetValue() - a.GetValue()) * progress);
118 inline int Interpolate (ProgressInteger& a, ProgressInteger& b, float progress)
120 return static_cast<int>(a.GetValue() + (b.GetValue() - a.GetValue()) * progress + 0.5f);
123 inline Vector2 Interpolate (ProgressVector2& a, ProgressVector2& b, float progress)
125 return (a.GetValue() + (b.GetValue() - a.GetValue()) * progress);
128 inline Vector3 Interpolate (ProgressVector3& a, ProgressVector3& b, float progress)
130 return (a.GetValue() + (b.GetValue() - a.GetValue()) * progress);
133 inline Vector4 Interpolate (ProgressVector4& a, ProgressVector4& b, float progress)
135 return (a.GetValue() + (b.GetValue() - a.GetValue()) * progress);
138 } // namespace Internal
142 #endif //__DALI_PROGRESS_VALUE_H__