Dali 3D User Interface Engine
progress-value.h
Go to the documentation of this file.
1 #ifndef __DALI_INTERNAL_PROGRESS_VALUE_H__
2 #define __DALI_INTERNAL_PROGRESS_VALUE_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
26 
27 namespace Dali
28 {
29 
30 namespace Internal
31 {
32 
36 template <typename T>
38 {
39 public:
40  ProgressValue (float progress, T value)
41  : mProgress(progress),
42  mValue (value)
43  {
44  }
45 
47  {
48  }
49 
50  float GetProgress () const
51  {
52  return mProgress;
53  }
54 
55  const T& GetValue () const
56  {
57  return mValue;
58  }
59 
60 public:
61  float mProgress;
62  T mValue;
63 };
64 
66 typedef std::vector<ProgressQuaternion> ProgressQuaternionContainer;
67 
69 typedef std::vector<AngleAxis> ProgressAngleAxisContainer;
70 
72 typedef std::vector<ProgressBoolean> ProgressBooleanContainer;
73 
75 typedef std::vector<ProgressInteger> ProgressIntegerContainer;
76 
78 typedef std::vector<ProgressNumber> ProgressNumberContainer;
79 
81 typedef std::vector<ProgressVector2> ProgressVector2Container;
82 
84 typedef std::vector<ProgressVector3> ProgressVector3Container;
85 
87 typedef std::vector<ProgressVector4> ProgressVector4Container;
88 
89 inline void Interpolate (Quaternion& result, const Quaternion& a, const Quaternion& b, float progress)
90 {
91  result = Quaternion::Slerp(a, b, progress);
92 }
93 
94 inline void Interpolate (AngleAxis& result, const AngleAxis& a, const AngleAxis& b, float progress)
95 {
96  Quaternion q1(a.angle, a.axis);
97  Quaternion q2(b.angle, b.axis);
98 
99  Quaternion iq = Quaternion::Slerp(q1, q2, progress);
100  iq.ToAxisAngle(result.axis, result.angle);
101 }
102 
103 
104 inline void Interpolate (bool& result, bool a, bool b, float progress)
105 {
106  result = progress < 0.5f ? a : b;
107 }
108 
109 inline void Interpolate (int& result, int a, int b, float progress)
110 {
111  result = static_cast<int>(a + (b - a) * progress + 0.5f);
112 }
113 
114 inline void Interpolate (unsigned int& result, unsigned int a, unsigned int b, float progress)
115 {
116  result = static_cast<unsigned int>(a + (b - a) * progress + 0.5f);
117 }
118 
119 inline void Interpolate (float& result, float a, float b, float progress)
120 {
121  result = a + (b-a) * progress;
122 }
123 
124 inline void Interpolate (Vector2& result, const Vector2& a, const Vector2& b, float progress)
125 {
126  result = a + (b-a) * progress;
127 }
128 
129 inline void Interpolate (Vector3& result, const Vector3& a, const Vector3& b, float progress)
130 {
131  result = a + (b-a) * progress;
132 }
133 
134 inline void Interpolate (Vector4& result, const Vector4& a, const Vector4& b, float progress)
135 {
136  result = a + (b-a) * progress;
137 }
138 
139 /* Cubic Interpolation (Catmull-Rom spline) between values p1 and p2. p0 and p3 are prev and next values
140  * and are used as control points to calculate tangent of the curve at interpolation points.
141  *
142  * f(t) = a3*t^3 + a2*t^2 + a1*t + a0
143  * Restrictions: f(0)=p1 f(1)=p2 f'(0)=(p2-p0)*0.5 f'(1)=(p3-p1)*0.5
144  */
145 
146 inline void CubicInterpolate( int& result, int p0, int p1, int p2, int p3, float progress )
147 {
148  float a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
149  float a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
150  float a1 = (p2-p0)*0.5f;
151 
152  result = static_cast<int>( a3*progress*progress*progress + a2*progress*progress + a1*progress + p1 + 0.5f );
153 }
154 
155 inline void CubicInterpolate( unsigned int& result, unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3, float progress )
156 {
157  float a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
158  float a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
159  float a1 = (p2-p0)*0.5f;
160 
161  result = static_cast<unsigned int>( a3*progress*progress*progress + a2*progress*progress + a1*progress + p1 + 0.5f );
162 }
163 
164 inline void CubicInterpolate( float& result, float p0, float p1, float p2, float p3, float progress )
165 {
166  float a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
167  float a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
168  float a1 = (p2-p0)*0.5f;
169 
170  result = a3*progress*progress*progress + a2*progress*progress + a1*progress + p1;
171 }
172 
173 inline void CubicInterpolate( Vector2& result, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, float progress )
174 {
175  Vector2 a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
176  Vector2 a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
177  Vector2 a1 = (p2-p0)*0.5f;
178 
179  result = a3*progress*progress*progress + a2*progress*progress + a1*progress + p1;
180 }
181 
182 inline void CubicInterpolate( Vector3& result, const Vector3& p0, const Vector3& p1, const Vector3& p2, const Vector3& p3, float progress )
183 {
184  Vector3 a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
185  Vector3 a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
186  Vector3 a1 = (p2-p0)*0.5f;
187 
188  result = a3*progress*progress*progress + a2*progress*progress + a1*progress + p1;
189 }
190 
191 inline void CubicInterpolate( Vector4& result, const Vector4& p0, const Vector4& p1, const Vector4& p2, const Vector4& p3, float progress )
192 {
193  Vector4 a3 = p3*0.5f - p2*1.5f + p1*1.5f - p0*0.5f;
194  Vector4 a2 = p0 - p1*2.5f + p2*2.0f - p3*0.5f;
195  Vector4 a1 = (p2-p0)*0.5f;
196 
197  result = a3*progress*progress*progress + a2*progress*progress + a1*progress + p1;
198 }
199 
200 inline void CubicInterpolate( bool& result, bool p0, bool p1, bool p2, bool p3, float progress )
201 {
202  Interpolate( result, p1, p2, progress);
203 }
204 
205 inline void CubicInterpolate( Quaternion& result, const Quaternion& p0, const Quaternion& p1, const Quaternion& p2, const Quaternion& p3, float progress )
206 {
207  Interpolate( result, p1, p2, progress);
208 }
209 
210 inline void CubicInterpolate( AngleAxis& result, const AngleAxis& p0, const AngleAxis& p1, const AngleAxis& p2, const AngleAxis& p3, float progress )
211 {
212  Interpolate( result, p1, p2, progress);
213 }
214 
215 } // namespace Internal
216 
217 } // namespace Dali
218 
219 #endif //__DALI_PROGRESS_VALUE_H__
Dali Docs Home
Read more about Dali