[3.0] Update doxygen comments
[platform/core/uifw/dali-core.git] / dali / public-api / animation / constraints.h
1 #ifndef __DALI_CONSTRAINTS_H__
2 #define __DALI_CONSTRAINTS_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/animation/constraint.h>
23 #include <dali/public-api/math/vector3.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/matrix.h>
27 #include <dali/public-api/math/matrix3.h>
28 #include <dali/public-api/object/property-input.h>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_animation
34  * @{
35  */
36
37 /**
38  * @brief The constraint function that updates the target property with the value of the first source.
39  *
40  * @e current = <em>input[0]</em>. @e current and <em>input[0]</em> indicate the target property
41  * and the first constraint source (the one added by the first Constraint::AddSource call), respectively.
42  * @SINCE_1_0.0
43  */
44 struct EqualToConstraint
45 {
46   /**
47    * @brief Constructor.
48    * @SINCE_1_0.0
49    */
50   EqualToConstraint()
51   { }
52
53   /**
54    * @brief Overrides functor for float properties.
55    *
56    * @SINCE_1_0.0
57    * @param[in,out] current The current property value, the constrained value is set
58    * @param[in] inputs Contains the property to copy
59    */
60   void operator()( float& current, const PropertyInputContainer& inputs )
61   {
62     current = inputs[0]->GetFloat();
63   }
64
65   /**
66    * @brief Overrides functor for Vector2 properties.
67    *
68    * @SINCE_1_0.0
69    * @param[in,out] current The current property value, the constrained value is set
70    * @param[in] inputs Contains the property to copy
71    */
72   void operator()( Vector2& current, const PropertyInputContainer& inputs )
73   {
74     current = inputs[0]->GetVector2();
75   }
76
77   /**
78    * @brief Overrides functor for Vector3 properties.
79    *
80    * @SINCE_1_0.0
81    * @param[in,out] current The current property value, the constrained value is set
82    * @param[in] inputs Contains the property to copy
83    */
84   void operator()( Vector3& current, const PropertyInputContainer& inputs )
85   {
86     current = inputs[0]->GetVector3();
87   }
88
89   /**
90    * @brief Overrides functor for Vector4 properties.
91    *
92    * @SINCE_1_0.0
93    * @param[in,out] current The current property value, the constrained value is set
94    * @param[in] inputs Contains the property to copy
95    */
96   void operator()( Vector4& current, const PropertyInputContainer& inputs )
97   {
98     current = inputs[0]->GetVector4();
99   }
100
101   /**
102    * @brief Overrides functor for Quaternion properties.
103    *
104    * @SINCE_1_0.0
105    * @param[in,out] current The current property value, the constrained value is set
106    * @param[in] inputs Contains the property to copy
107    */
108   void operator()( Quaternion& current, const PropertyInputContainer& inputs )
109   {
110     current = inputs[0]->GetQuaternion();
111   }
112
113   /**
114    * @brief Overrides functor for Matrix3 properties.
115    *
116    * @SINCE_1_0.0
117    * @param[in,out] current The current property value
118    * @param[in] inputs Contains the property to copy
119    */
120   void operator()( Matrix3& current, const PropertyInputContainer& inputs )
121   {
122     current = inputs[0]->GetMatrix3();
123   }
124
125   /**
126    * @brief Overrides functor for Matrix properties.
127    *
128    * @SINCE_1_0.0
129    * @param[in,out] current The current property value, the constrained value is set
130    * @param[in] inputs Contains the property to copy
131    */
132   void operator()( Matrix& current, const PropertyInputContainer& inputs )
133   {
134     current = inputs[0]->GetMatrix();
135   }
136
137 };
138
139 /**
140  * @brief The constraint function that updates the target property with the value of the first source
141  * multiplied by scale parameter (for Vector3 properties).
142  *
143  * @e current = <em>input[0]</em> * @e scale. @e current, <em>input[0]</em>, and @e scale
144  * indicates the target property, the first constraint source, and the scale parameter, respectively.
145  * * implies element-wise multiplication.
146  * @SINCE_1_0.0
147  */
148 struct RelativeToConstraint
149 {
150   /**
151    * @brief Constructor.
152    * @SINCE_1_0.0
153    * @param[in] scale Scale factor
154    */
155   RelativeToConstraint( float scale )
156   : mScale( scale, scale, scale ) { }
157
158   /**
159    * @brief Constructor.
160    * @SINCE_1_0.0
161    * @param[in] scale Scale factor
162    */
163   RelativeToConstraint( const Vector3& scale )
164   : mScale( scale ) { }
165
166   /**
167    * @brief Functor.
168    * @SINCE_1_0.0
169    * @param[in,out] current The current property value (vector3 property * scale factor)
170    * @param[in] inputs Property container for current property calculation
171    */
172   void operator()( Vector3& current, const PropertyInputContainer& inputs )
173   {
174     current = inputs[0]->GetVector3() * mScale;
175   }
176
177   Vector3 mScale; ///< Component-wise scale factor
178 };
179
180 /**
181  * @brief The constraint function that updates the target property with the value of the first source
182  * multiplied by scale parameter (for float properties).
183  *
184  * @e current = <em>input[0]</em> * @e scale. @e current, <em>input[0]</em>, and @e scale
185  * indicates the target property, the first constraint source, and the scale parameter, respectively.
186  * @SINCE_1_0.0
187  */
188 struct RelativeToConstraintFloat
189 {
190   /**
191    * @brief Constructor.
192    * @SINCE_1_0.0
193    * @param[in] scale Scale factor
194    */
195   RelativeToConstraintFloat( float scale )
196   : mScale( scale ) { }
197
198   /**
199    * @brief Functor.
200    * @SINCE_1_0.0
201    * @param[in,out] current The current property value (float property * scale factor)
202    * @param[in] inputs Property container for current property calculation
203    */
204   void operator()( float& current, const PropertyInputContainer& inputs )
205   {
206     current = inputs[0]->GetFloat() * mScale;
207   }
208
209   float mScale; ///< Scale factor
210 };
211
212 /**
213  * @brief Constraint function to aim a camera at a target.
214  *
215  * Constraint which sets camera's orientation given camera world position
216  * and a target world position. Uses target's up vector to orient the
217  * constrained actor along the vector between camera position and
218  * target position.
219  *
220  * @SINCE_1_0.0
221  * @param[in,out] current The current orientation property value, the constrained value is set
222  * @param[in] inputs Contains the world position of the target, the world position of the camera, and the world orientation of the target
223  */
224 inline void LookAt( Dali::Quaternion& current, const Dali::PropertyInputContainer& inputs )
225 {
226   const PropertyInput& targetPosition( *inputs[0] );
227   const PropertyInput& cameraPosition( *inputs[1] );
228   const PropertyInput& targetOrientation( *inputs[2] );
229
230   Vector3 vForward = targetPosition.GetVector3() - cameraPosition.GetVector3();
231   vForward.Normalize();
232
233   const Quaternion& targetOrientationQ = targetOrientation.GetQuaternion();
234
235   Vector3 targetY(targetOrientationQ.Rotate(Vector3::YAXIS));
236   targetY.Normalize();
237
238   // Camera Right vector is perpendicular to forward & target up
239   Vector3 vX = targetY.Cross(vForward);
240   vX.Normalize();
241
242   // Camera Up vector is perpendicular to forward and right
243   Vector3 vY = vForward.Cross(vX);
244   vY.Normalize();
245
246   current = Quaternion( vX, vY, vForward );
247 }
248
249 /**
250  * @}
251  */
252 } // namespace Dali
253
254 #endif // __DALI_CONSTRAINTS_H__