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