1646acbade53a89e7fcd8c3a67759887ab709e17
[platform/core/uifw/dali-core.git] / dali / public-api / animation / path.h
1 #ifndef __DALI_PATH_H__
2 #define __DALI_PATH_H__
3
4 /*
5  * Copyright (c) 2015 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
22 #include <dali/public-api/object/handle.h>
23 #include <dali/public-api/object/property-index-ranges.h>
24
25 namespace Dali
26 {
27 /**
28  * @addtogroup dali_core_animation
29  * @{
30  */
31
32 namespace Internal DALI_INTERNAL
33 {
34 class Path;
35 }
36
37 /**
38  * @brief A 3D parametric curve
39  *
40  * Paths can be used to animate position and orientation of actors using Dali::Animate()
41  *
42  * @SINCE_1_0.0
43  */
44 class DALI_IMPORT_API Path : public Handle
45 {
46 public:
47
48   /**
49    * @brief An enumeration of properties belonging to the Path class.
50    * @SINCE_1_0.0
51    */
52   struct Property
53   {
54     enum
55     {
56       POINTS         = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "points",         type Vector3 @SINCE_1_0.0
57       CONTROL_POINTS,                                       ///< name "controlPoints",  type Vector3 @SINCE_1_0.0
58     };
59   };
60
61   /**
62    * @brief Create an initialized Path handle.
63    *
64    * @SINCE_1_0.0
65    * @return A handle to a newly allocated Dali resource.
66    */
67   static Path New();
68
69   /**
70    * @brief Downcast a handle to Path handle.
71    *
72    * If handle points to a Path object the downcast produces
73    * valid handle. If not the returned handle is left uninitialized.
74    * @SINCE_1_0.0
75    * @param[in] handle Handle to an object
76    * @return Handle to a Path object or an uninitialized handle
77    */
78   static Path DownCast( BaseHandle handle );
79
80   /**
81    * @brief Create an uninitialized Path handle.
82    *
83    * This can be initialized with Path::New().
84    * Calling member functions with an uninitialized Path handle is not allowed.
85    * @SINCE_1_0.0
86    */
87   Path();
88
89   /**
90    * @brief Destructor
91    *
92    * This is non-virtual since derived Handle types must not contain data or virtual methods.
93    * @SINCE_1_0.0
94    */
95   ~Path();
96
97   /**
98    * @brief This copy constructor is required for (smart) pointer semantics.
99    *
100    * @SINCE_1_0.0
101    * @param [in] handle A reference to the copied handle
102    */
103   Path(const Path& handle);
104
105   /**
106    * @brief This assignment operator is required for (smart) pointer semantics.
107    *
108    * @SINCE_1_0.0
109    * @param [in] rhs  A reference to the copied handle
110    * @return A reference to this
111    */
112   Path& operator=(const Path& rhs);
113
114   /**
115    * @brief Add an interpolation point.
116    *
117    * @SINCE_1_0.0
118    * @param[in] point The new interpolation point to be added
119    */
120   void AddPoint(const Vector3& point );
121
122   /**
123    * @brief Add a control point.
124    *
125    * @SINCE_1_0.0
126    * @param[in] point The new control point to be added
127    */
128   void AddControlPoint(const Vector3& point );
129
130   /**
131    * @brief Automatic generation of control points. Generated control points which result in a smooth join between the splines of each segment.
132    *
133    * The generating algorithm is as follows:
134    * For a given knot point K[N], find the vector that bisects K[N-1],[N] and [N],[N+1].
135    * Calculate the tangent vector by taking the normal of this bisector.
136    * The in control point is the length of the preceding segment back along this bisector multiplied by the curvature.
137    * The out control point is the length of the succeeding segment forward along this bisector multiplied by the curvature.
138    *
139    * @SINCE_1_0.0
140    * @param[in] curvature The curvature of the spline. 0 gives straight lines between the knots,
141    *                      negative values means the spline contains loops, positive values up to
142    *                      0.5 result in a smooth curve, positive values between 0.5 and 1 result
143    *                      in looped curves where the loops are not distinct (i.e. the curve appears
144    *                      to be non-continuous), positive values higher than 1 result in looped curves.
145    * @pre There are at least two points in the path ( one segment ).
146    *
147    */
148   void GenerateControlPoints( float curvature );
149
150   /**
151    * @brief Sample path at a given progress. Calculates position and tangent at that point of the curve
152    *
153    * @SINCE_1_0.0
154    * @param[in]  progress  A floating point value between 0.0 and 1.0.
155    * @param[out] position The interpolated position at that progress.
156    * @param[out] tangent The interpolated tangent at that progress.
157    */
158   void Sample( float progress, Vector3& position, Vector3& tangent ) const;
159
160   /**
161    * @brief Accessor for the interpolation points.
162    *
163    * @SINCE_1_0.0
164    * @param[in] index The index of the interpolation point.
165    * @return A reference to the interpolation point.
166    */
167   Vector3& GetPoint( size_t index );
168
169   /**
170    * @brief Accessor for the control points.
171    *
172    * @SINCE_1_0.0
173    * @param[in] index The index of the control point.
174    * @return A reference to the control point.
175    */
176   Vector3& GetControlPoint( size_t index );
177
178   /**
179    * @brief Get the number of interpolation points in the path
180    *
181    * @SINCE_1_0.0
182    * @return The number of interpolation points in the path
183    */
184   size_t GetPointCount() const;
185
186 public: // Not intended for application developers
187   /**
188    * @brief This constructor is used by Path::New() methods.
189    *
190    * @SINCE_1_0.0
191    * @param[in] path A pointer to an internal path resource
192    */
193   explicit DALI_INTERNAL Path(Internal::Path* path);
194 };
195
196 /**
197  * @}
198  */
199 } // namespace Dali
200
201 #endif // __DALI_KEY_FRAMES_H__