1 #ifndef __DALI_CONSTRAINTS_H__
2 #define __DALI_CONSTRAINTS_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @addtogroup CAPI_DALI_ANIMATION_MODULE
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/quaternion.h>
30 namespace Dali DALI_IMPORT_API
39 * @brief Scale To Fit constraint.
41 * Scales an Actor, such that it fits within it's Parent's Size.
42 * f(current, size, parentSize) = parentSize / size
44 struct DALI_IMPORT_API ScaleToFitConstraint
49 ScaleToFitConstraint();
52 * @brief Functor operator
54 * @param[in] current The actor's current scale
55 * @param[in] sizeProperty The actor's current size
56 * @param[in] parentSizeProperty The parent's current size.
57 * @return The actor's new scale
59 Vector3 operator()(const Vector3& current,
60 const PropertyInput& sizeProperty,
61 const PropertyInput& parentSizeProperty);
66 * @brief Scale To Fit Keep Aspect Ratio constraint.
68 * Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio.
69 * f(current, size, parentSize) = Vector3( min( parentSizeX / sizeX, min( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
71 struct DALI_IMPORT_API ScaleToFitKeepAspectRatioConstraint
76 ScaleToFitKeepAspectRatioConstraint();
79 * @brief Functor operator
81 * @param[in] current The actor's current scale
82 * @param[in] sizeProperty The actor's current size
83 * @param[in] parentSizeProperty The parent's current size.
84 * @return The actor's new scale
86 Vector3 operator()(const Vector3& current,
87 const PropertyInput& sizeProperty,
88 const PropertyInput& parentSizeProperty);
92 * @brief Scale To Fill Keep Aspect Ratio constraint.
94 * Scales an Actor, such that it fill its Parent's Size Keeping the aspect ratio.
95 * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
97 struct DALI_IMPORT_API ScaleToFillKeepAspectRatioConstraint
100 * @brief Constructor.
102 ScaleToFillKeepAspectRatioConstraint();
105 * @param[in] current The actor's current scale
106 * @param[in] sizeProperty The actor's current size
107 * @param[in] parentSizeProperty The parent's current size.
108 * @return The actor's new scale
110 Vector3 operator()(const Vector3& current,
111 const PropertyInput& sizeProperty,
112 const PropertyInput& parentSizeProperty);
116 * @brief Scale To Fill XY Keep Aspect Ratio constraint.
118 * Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio.
119 * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
121 struct DALI_IMPORT_API ScaleToFillXYKeepAspectRatioConstraint
124 * @brief Constructor.
126 ScaleToFillXYKeepAspectRatioConstraint();
129 * @param[in] current The actor's current scale
130 * @param[in] sizeProperty The actor's current size
131 * @param[in] parentSizeProperty The parent's current size.
132 * @return The actor's new scale
134 Vector3 operator()(const Vector3& current,
135 const PropertyInput& sizeProperty,
136 const PropertyInput& parentSizeProperty);
140 * @brief Shrinks source size inside the target size maintaining aspect ratio of source.
141 * If source is smaller than target it returns source
143 struct ShrinkInsideKeepAspectRatioConstraint
146 * @brief Constructor.
148 ShrinkInsideKeepAspectRatioConstraint();
151 * @param[in] current The actor's current scale
152 * @param[in] sizeProperty The actor's current size
153 * @param[in] parentSizeProperty The parent's current size.
154 * @return The actor's new scale
156 Vector3 operator()(const Vector3& current,
157 const PropertyInput& sizeProperty,
158 const PropertyInput& parentSizeProperty);
162 * @brief MultiplyConstraint
164 * f(current, property) = current * property
166 struct DALI_IMPORT_API MultiplyConstraint
169 * @brief Constructor.
171 MultiplyConstraint();
174 * @param[in] current The object's current property value
175 * @param[in] property The property to multiply by.
176 * @return The object's new property value
178 Vector3 operator()(const Vector3& current,
179 const PropertyInput& property);
183 * @brief DivideConstraint
185 * f(current, property) = current / property
187 struct DALI_IMPORT_API DivideConstraint
190 * @brief Constructor.
195 * @param[in] current The object's current property value
196 * @param[in] property The property to divide by.
197 * @return The object's new property value
199 Vector3 operator()(const Vector3& current,
200 const PropertyInput& property);
204 * @brief EqualToConstraint
206 * f(current, property) = property
208 struct DALI_IMPORT_API EqualToConstraint
211 * @brief Constructor.
216 * @brief override functor for float properties
218 * @param[in] current The current property value
219 * @param[in] property The property to copy
220 * @return The copy of the input property
222 float operator()(const float current, const PropertyInput& property);
225 * @brief override functor for float properties
227 * @param[in] current The current property value
228 * @param[in] property The property to copy
229 * @return The copy of the input property
231 Vector3 operator()(const Vector3& current, const PropertyInput& property);
234 * @brief override functor for float properties
236 * @param[in] current The current property value
237 * @param[in] property The property to copy
238 * @return The copy of the input property
240 Vector4 operator()(const Vector4& current, const PropertyInput& property);
243 * @brief override functor for float properties
245 * @param[in] current The current property value
246 * @param[in] property The property to copy
247 * @return The copy of the input property
249 Quaternion operator()(const Quaternion& current, const PropertyInput& property);
252 * @brief override functor for float properties
254 * @param[in] current The current property value
255 * @param[in] property The property to copy
256 * @return The copy of the input property
258 Matrix3 operator()(const Matrix3& current, const PropertyInput& property);
261 * @brief override functor for float properties
263 * @param[in] current The current property value
264 * @param[in] property The property to copy
265 * @return The copy of the input property
267 Matrix operator()(const Matrix& current, const PropertyInput& property);
271 * @brief RelativeToConstraint for Vector3 properties
273 * f(current, property, scale) = property * scale
275 struct DALI_IMPORT_API RelativeToConstraint
278 * @brief Constructor.
280 RelativeToConstraint( float scale );
283 * @brief Constructor.
285 RelativeToConstraint( const Vector3& scale );
290 Vector3 operator()(const Vector3& current, const PropertyInput& property);
292 Vector3 mScale; ///< Component-wise scale factor
296 * @brief RelativeToConstraint for float properties
298 struct DALI_IMPORT_API RelativeToConstraintFloat
301 * @brief Constructor.
303 RelativeToConstraintFloat( float scale );
308 float operator()(const float current, const PropertyInput& property);
310 float mScale; ///< Scale factor
314 * @brief InverseOfConstraint
316 * f(current, property) = 1 / property
318 struct DALI_IMPORT_API InverseOfConstraint
321 * @brief Constructor.
323 InverseOfConstraint();
328 Vector3 operator()(const Vector3& current,
329 const PropertyInput& property);
333 * @brief Constraint which sets width to be another actor's width,
334 * and the height to a fixed height.
336 struct DALI_IMPORT_API SourceWidthFixedHeight
339 * @brief Constructor.
341 SourceWidthFixedHeight( float height );
346 Vector3 operator()(const Vector3& current,
347 const PropertyInput& sourceSize);
349 float mFixedHeight; ///< the fixed height
353 * @brief Constraint which sets height to be another actor's height,
354 * and the width to a fixed width.
356 struct DALI_IMPORT_API SourceHeightFixedWidth
361 SourceHeightFixedWidth( float width );
366 Vector3 operator()(const Vector3& current,
367 const PropertyInput& sourceSize);
369 float mFixedWidth; ///< the fixed width
373 * @brief Constraint function to aim a camera at a target.
375 * Constraint which sets camera's rotation given camera world position
376 * and a target world position. Uses target's up vector to orient the
377 * constrained actor along the vector between camera position and
380 * @param[in] current The current rotation property value
381 * @param[in] targetPosition World position of target
382 * @param[in] cameraPosition World position of camera
383 * @param[in] targetRotation World rotation of the target
384 * @return The orientation of the camera
386 DALI_IMPORT_API Dali::Quaternion LookAt( const Dali::Quaternion& current,
387 const PropertyInput& targetPosition,
388 const PropertyInput& cameraPosition,
389 const PropertyInput& targetRotation );
393 * @brief Constraint functor to aim a camera at a target.
395 * Constraint which sets rotation given camera world position,
396 * target world position (usually the looked at actor's world position)
397 * and the angle parameter (how much the camera is offset with respect
398 * to the target's up vector).
400 struct DALI_IMPORT_API OrientedLookAt
403 * @brief Functor constructor.
405 * @param[in] angle The angle of the camera's up vector with regards
406 * to the target's up vector in radians. Positive angles rotate the
407 * camera clockwise, negative angles rotate anti-clockwise.
409 OrientedLookAt( float angle );
414 * @param[in] current The current rotation property value
415 * @param[in] targetPosition World position of target
416 * @param[in] cameraPosition World position of camera
417 * @param[in] targetRotation World rotation of the target
418 * @return The orientation of the camera
420 Dali::Quaternion operator()(const Dali::Quaternion& current,
421 const PropertyInput& targetPosition,
422 const PropertyInput& cameraPosition,
423 const PropertyInput& targetRotation );
425 float mAngle; ///< camera angle offset
434 #endif // __DALI_CONSTRAINTS_H__