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