[dali_2.3.31] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / path-impl.h
1 #ifndef DALI_INTERNAL_PATH_H
2 #define DALI_INTERNAL_PATH_H
3
4 /*
5  * Copyright (c) 2021 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/internal/event/common/object-impl.h>
23 #include <dali/public-api/animation/path.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/math/matrix.h>
26 #include <dali/public-api/object/base-object.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 using PathPtr = IntrusivePtr<Path>;
33
34 /**
35  * A 3D path
36  */
37 class Path : public Object
38 {
39 public:
40   /**
41    * Construct a new path
42    */
43   static Path* New();
44
45   /**
46    * Constructor
47    */
48   Path();
49
50 protected:
51   /**
52    * virtual destructor
53    */
54   ~Path() override;
55
56 private:
57   /**
58    * @copydoc Dali::Internal::Object::SetDefaultProperty()
59    */
60   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
61
62   /**
63    * @copydoc Dali::Internal::Object::GetDefaultProperty()
64    */
65   Property::Value GetDefaultProperty(Property::Index index) const override;
66
67 public:
68   /**
69    * Returns a clone to the given path
70    */
71   static Path* Clone(const Path& path);
72
73   /**
74    * @copydoc Dali::Path::AddPoint
75    */
76   void AddPoint(const Vector3& point);
77
78   /**
79    * @copydoc Dali::Path::AddControlPoint
80    */
81   void AddControlPoint(const Vector3& point);
82
83   /**
84    * @copydoc Dali::Path::GenerateControlPoints
85    */
86   void GenerateControlPoints(float curvature);
87
88   /**
89    * @copydoc Dali::Path::Sample
90    */
91   void Sample(float t, Vector3& position, Vector3& tangent) const;
92
93   /**
94    * @brief Sample path at a given progress. Calculates position and tangent at that point of the curve
95    *
96    * @param[in]  progress  A floating point value between 0.0 and 1.0.
97    * @param[out] position The interpolated position at that progress.
98    * @param[out] tangent The interpolated tangent at that progress.
99    * @return true if Sample could be calculated
100    */
101   bool SampleAt(float t, Vector3& position, Vector3& tangent) const;
102
103   /**
104    * Sample position at point t.
105    *
106    * @param[in] progress  A floating point value between 0.0 and 1.0.
107    * @param[out] position The interpolated position at that progress.
108    * @return true if sample could be calculated
109    */
110   bool SamplePosition(float t, Vector3& position) const;
111
112   /**
113    * @brief Sample tangent at point t.
114    *
115    * @param[in] progress  A floating point value between 0.0 and 1.0.
116    * @param[out] tangent The interpolated tangent at that progress.
117    * @return true if sample could be calculated
118    */
119   bool SampleTangent(float t, Vector3& tangent) const;
120
121   /**
122    * @copydoc Dali::Path::GetPoint
123    */
124   Vector3& GetPoint(uint32_t index);
125
126   /**
127    * @copydoc Dali::Path::GetControlPoint
128    */
129   Vector3& GetControlPoint(uint32_t index);
130
131   /**
132    * @copydoc Dali::Path::GetPointCount
133    */
134   uint32_t GetPointCount() const;
135
136   /**
137    * Clears the points of the path
138    */
139   void ClearPoints();
140
141   /**
142    * Clears the control points of the path
143    */
144   void ClearControlPoints();
145
146   /**
147    * @brief Get mPoint property
148    *
149    * @return A const reference to mPoint vector
150    */
151   const Dali::Vector<Vector3>& GetPoints() const
152   {
153     return mPoint;
154   }
155
156   /*
157    * @brief Set mPoint
158    *
159    * @param[in] p New value for mPoint property
160    */
161   void SetPoints(const Dali::Vector<Vector3>& p)
162   {
163     mPoint = p;
164   }
165
166   /**
167    * @brief Get mCotrolPoint property
168    *
169    * @return A const reference to mControlPoint vector
170    */
171   const Dali::Vector<Vector3>& GetControlPoints() const
172   {
173     return mControlPoint;
174   }
175
176   /*
177    * @brief Set mControlPoint property
178    *
179    * @param[in] p New value for mControlPoint property
180    */
181   void SetControlPoints(const Dali::Vector<Vector3>& p)
182   {
183     mControlPoint = p;
184   }
185
186 private:
187   /**
188    * Undefined
189    */
190   Path(const Path& p);
191
192   /**
193    * Undefined
194    */
195   Path& operator=(const Path& rhs);
196
197   /**
198    * Helper function to calculate the segment and local progress in that segment
199    * given a progress
200    *
201    * @param[in] t Progress
202    * @param[out] segment Segment for t
203    * @param[out] tLocal Local progress in the segment
204    *
205    */
206   void FindSegmentAndProgress(float t, uint32_t& segment, float& tLocal) const;
207
208   /**
209    * Helper function to calculate to number of segments in the path
210    */
211   uint32_t GetNumberOfSegments() const;
212
213   Dali::Vector<Vector3> mPoint;        ///< Interpolation points
214   Dali::Vector<Vector3> mControlPoint; ///< Control points
215 };
216
217 } // namespace Internal
218
219 // Get impl of handle
220 inline Internal::Path& GetImplementation(Dali::Path& path)
221 {
222   DALI_ASSERT_ALWAYS(path && "Path handle is empty");
223   Dali::RefObject& object = path.GetBaseObject();
224   return static_cast<Internal::Path&>(object);
225 }
226
227 inline const Internal::Path& GetImplementation(const Dali::Path& path)
228 {
229   DALI_ASSERT_ALWAYS(path && "Path handle is empty");
230   const Dali::RefObject& object = path.GetBaseObject();
231   return static_cast<const Internal::Path&>(object);
232 }
233
234 } // namespace Dali
235
236 #endif // DALI_INTERNAL_PATH_H