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 #include <dali/public-api/math/vector3.h>
23 #include <dali/public-api/math/quaternion.h>
25 namespace Dali DALI_IMPORT_API
34 * @brief Scale To Fit constraint.
36 * Scales an Actor, such that it fits within it's Parent's Size.
37 * f(current, size, parentSize) = parentSize / size
39 struct DALI_IMPORT_API ScaleToFitConstraint
44 ScaleToFitConstraint();
47 * @brief Functor operator
49 * @param[in] current The actor's current scale
50 * @param[in] sizeProperty The actor's current size
51 * @param[in] parentSizeProperty The parent's current size.
52 * @return The actor's new scale
54 Vector3 operator()(const Vector3& current,
55 const PropertyInput& sizeProperty,
56 const PropertyInput& parentSizeProperty);
61 * @brief Scale To Fit Keep Aspect Ratio constraint.
63 * Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio.
64 * f(current, size, parentSize) = Vector3( min( parentSizeX / sizeX, min( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
66 struct DALI_IMPORT_API ScaleToFitKeepAspectRatioConstraint
71 ScaleToFitKeepAspectRatioConstraint();
74 * @brief Functor operator
76 * @param[in] current The actor's current scale
77 * @param[in] sizeProperty The actor's current size
78 * @param[in] parentSizeProperty The parent's current size.
79 * @return The actor's new scale
81 Vector3 operator()(const Vector3& current,
82 const PropertyInput& sizeProperty,
83 const PropertyInput& parentSizeProperty);
87 * @brief Scale To Fill Keep Aspect Ratio constraint.
89 * Scales an Actor, such that it fill its Parent's Size Keeping the aspect ratio.
90 * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
92 struct DALI_IMPORT_API ScaleToFillKeepAspectRatioConstraint
97 ScaleToFillKeepAspectRatioConstraint();
100 * @param[in] current The actor's current scale
101 * @param[in] sizeProperty The actor's current size
102 * @param[in] parentSizeProperty The parent's current size.
103 * @return The actor's new scale
105 Vector3 operator()(const Vector3& current,
106 const PropertyInput& sizeProperty,
107 const PropertyInput& parentSizeProperty);
111 * @brief Scale To Fill XY Keep Aspect Ratio constraint.
113 * Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio.
114 * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
116 struct DALI_IMPORT_API ScaleToFillXYKeepAspectRatioConstraint
119 * @brief Constructor.
121 ScaleToFillXYKeepAspectRatioConstraint();
124 * @param[in] current The actor's current scale
125 * @param[in] sizeProperty The actor's current size
126 * @param[in] parentSizeProperty The parent's current size.
127 * @return The actor's new scale
129 Vector3 operator()(const Vector3& current,
130 const PropertyInput& sizeProperty,
131 const PropertyInput& parentSizeProperty);
135 * @brief Shrinks source size inside the target size maintaining aspect ratio of source.
136 * If source is smaller than target it returns source
138 struct ShrinkInsideKeepAspectRatioConstraint
141 * @brief Constructor.
143 ShrinkInsideKeepAspectRatioConstraint();
146 * @param[in] current The actor's current scale
147 * @param[in] sizeProperty The actor's current size
148 * @param[in] parentSizeProperty The parent's current size.
149 * @return The actor's new scale
151 Vector3 operator()(const Vector3& current,
152 const PropertyInput& sizeProperty,
153 const PropertyInput& parentSizeProperty);
157 * @brief MultiplyConstraint
159 * f(current, property) = current * property
161 struct DALI_IMPORT_API MultiplyConstraint
164 * @brief Constructor.
166 MultiplyConstraint();
169 * @param[in] current The object's current property value
170 * @param[in] property The property to multiply by.
171 * @return The object's new property value
173 Vector3 operator()(const Vector3& current,
174 const PropertyInput& property);
178 * @brief DivideConstraint
180 * f(current, property) = current / property
182 struct DALI_IMPORT_API DivideConstraint
185 * @brief Constructor.
190 * @param[in] current The object's current property value
191 * @param[in] property The property to divide by.
192 * @return The object's new property value
194 Vector3 operator()(const Vector3& current,
195 const PropertyInput& property);
199 * @brief EqualToConstraint
201 * f(current, property) = property
203 struct DALI_IMPORT_API EqualToConstraint
206 * @brief Constructor.
211 * @brief override functor for float properties
213 * @param[in] current The current property value
214 * @param[in] property The property to copy
215 * @return The copy of the input property
217 float operator()(const float current, const PropertyInput& property);
220 * @brief override functor for float properties
222 * @param[in] current The current property value
223 * @param[in] property The property to copy
224 * @return The copy of the input property
226 Vector3 operator()(const Vector3& current, const PropertyInput& property);
229 * @brief override functor for float properties
231 * @param[in] current The current property value
232 * @param[in] property The property to copy
233 * @return The copy of the input property
235 Vector4 operator()(const Vector4& current, const PropertyInput& property);
238 * @brief override functor for float properties
240 * @param[in] current The current property value
241 * @param[in] property The property to copy
242 * @return The copy of the input property
244 Quaternion operator()(const Quaternion& current, const PropertyInput& property);
247 * @brief override functor for float properties
249 * @param[in] current The current property value
250 * @param[in] property The property to copy
251 * @return The copy of the input property
253 Matrix3 operator()(const Matrix3& current, const PropertyInput& property);
256 * @brief override functor for float properties
258 * @param[in] current The current property value
259 * @param[in] property The property to copy
260 * @return The copy of the input property
262 Matrix operator()(const Matrix& current, const PropertyInput& property);
266 * @brief RelativeToConstraint for Vector3 properties
268 * f(current, property, scale) = property * scale
270 struct DALI_IMPORT_API RelativeToConstraint
273 * @brief Constructor.
275 RelativeToConstraint( float scale );
278 * @brief Constructor.
280 RelativeToConstraint( const Vector3& scale );
285 Vector3 operator()(const Vector3& current, const PropertyInput& property);
287 Vector3 mScale; ///< Component-wise scale factor
291 * @brief RelativeToConstraint for float properties
293 struct DALI_IMPORT_API RelativeToConstraintFloat
296 * @brief Constructor.
298 RelativeToConstraintFloat( float scale );
303 float operator()(const float current, const PropertyInput& property);
305 float mScale; ///< Scale factor
309 * @brief InverseOfConstraint
311 * f(current, property) = 1 / property
313 struct DALI_IMPORT_API InverseOfConstraint
316 * @brief Constructor.
318 InverseOfConstraint();
323 Vector3 operator()(const Vector3& current,
324 const PropertyInput& property);
328 * @brief Constraint which sets width to be another actor's width,
329 * and the height to a fixed height.
331 struct DALI_IMPORT_API SourceWidthFixedHeight
334 * @brief Constructor.
336 SourceWidthFixedHeight( float height );
341 Vector3 operator()(const Vector3& current,
342 const PropertyInput& sourceSize);
344 float mFixedHeight; ///< the fixed height
348 * @brief Constraint which sets height to be another actor's height,
349 * and the width to a fixed width.
351 struct DALI_IMPORT_API SourceHeightFixedWidth
356 SourceHeightFixedWidth( float width );
361 Vector3 operator()(const Vector3& current,
362 const PropertyInput& sourceSize);
364 float mFixedWidth; ///< the fixed width
368 * @brief Constraint function to aim a camera at a target.
370 * Constraint which sets camera's rotation given camera world position
371 * and a target world position. Uses target's up vector to orient the
372 * constrained actor along the vector between camera position and
375 * @param[in] current The current rotation property value
376 * @param[in] targetPosition World position of target
377 * @param[in] cameraPosition World position of camera
378 * @param[in] targetRotation World rotation of the target
379 * @return The orientation of the camera
381 DALI_IMPORT_API Dali::Quaternion LookAt( const Dali::Quaternion& current,
382 const PropertyInput& targetPosition,
383 const PropertyInput& cameraPosition,
384 const PropertyInput& targetRotation );
388 * @brief Constraint functor to aim a camera at a target.
390 * Constraint which sets rotation given camera world position,
391 * target world position (usually the looked at actor's world position)
392 * and the angle parameter (how much the camera is offset with respect
393 * to the target's up vector).
395 struct DALI_IMPORT_API OrientedLookAt
398 * @brief Functor constructor.
400 * @param[in] angle The angle of the camera's up vector with regards
401 * to the target's up vector in radians. Positive angles rotate the
402 * camera clockwise, negative angles rotate anti-clockwise.
404 OrientedLookAt( float angle );
409 * @param[in] current The current rotation property value
410 * @param[in] targetPosition World position of target
411 * @param[in] cameraPosition World position of camera
412 * @param[in] targetRotation World rotation of the target
413 * @return The orientation of the camera
415 Dali::Quaternion operator()(const Dali::Quaternion& current,
416 const PropertyInput& targetPosition,
417 const PropertyInput& cameraPosition,
418 const PropertyInput& targetRotation );
420 float mAngle; ///< camera angle offset
426 #endif // __DALI_CONSTRAINTS_H__