#define __DALI_CONSTRAINTS_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// INTERNAL INCLUDES
+#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/math/vector3.h>
#include <dali/public-api/math/vector4.h>
#include <dali/public-api/math/quaternion.h>
namespace Dali
{
-
/**
- * @brief Scale To Fit constraint.
- *
- * Scales an Actor, such that it fits within it's Parent's Size.
- * f(current, size, parentSize) = parentSize / size
+ * @addtogroup dali_core_animation
+ * @{
*/
-struct ScaleToFitConstraint
-{
- /**
- * @brief Constructor.
- */
- ScaleToFitConstraint()
- { }
-
- /**
- * @brief Functor operator
- *
- * @param[in] current The actor's current scale
- * @param[in] sizeProperty The actor's current size
- * @param[in] parentSizeProperty The parent's current size.
- * @return The actor's new scale
- */
- Vector3 operator()(const Vector3& current,
- const PropertyInput& sizeProperty,
- const PropertyInput& parentSizeProperty)
- {
- const Vector3 size = sizeProperty.GetVector3();
- const Vector3 parentSize = parentSizeProperty.GetVector3();
-
- return Vector3( fabsf(size.x) > Math::MACHINE_EPSILON_1 ? (parentSize.x / size.x) : 0.0f,
- fabsf(size.y) > Math::MACHINE_EPSILON_1 ? (parentSize.y / size.y) : 0.0f,
- fabsf(size.z) > Math::MACHINE_EPSILON_1 ? (parentSize.z / size.z) : 0.0f );
- }
-};
/**
- * @brief Scale To Fit Keep Aspect Ratio constraint.
+ * @brief The constraint function that updates the target property with the value of the first source.
*
- * Scales an Actor, such that it fits within its Parent's Size Keeping the aspect ratio.
- * f(current, size, parentSize) = Vector3( min( parentSizeX / sizeX, min( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
+ * @e current = <em>input[0]</em>. @e current and <em>input[0]</em> indicate the target property
+ * and the first constraint source (the one added by the first Constraint::AddSource call), respectively.
+ * @SINCE_1_0.0
*/
-struct ScaleToFitKeepAspectRatioConstraint
+struct EqualToConstraint
{
/**
* @brief Constructor.
+ * @SINCE_1_0.0
*/
- ScaleToFitKeepAspectRatioConstraint()
+ EqualToConstraint()
{ }
/**
- * @brief Functor operator
+ * @brief Overrides functor for float properties.
*
- * @param[in] current The actor's current scale
- * @param[in] sizeProperty The actor's current size
- * @param[in] parentSizeProperty The parent's current size.
- * @return The actor's new scale
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- Vector3 operator()(const Vector3& current,
- const PropertyInput& sizeProperty,
- const PropertyInput& parentSizeProperty)
+ void operator()( float& current, const PropertyInputContainer& inputs )
{
- return FitKeepAspectRatio( parentSizeProperty.GetVector3(), sizeProperty.GetVector3() );
+ current = inputs[0]->GetFloat();
}
-};
-
-/**
- * @brief Scale To Fill XY Keep Aspect Ratio constraint.
- *
- * Scales an Actor, such that it fill its Parent's Size in the X and Y coordinates Keeping the aspect ratio.
- * f(current, size, parentSize) = Vector3( max( parentSizeX / sizeX, max( parentSizeY / sizeY, parentSizeZ / sizeZ ) )
- */
-struct ScaleToFillXYKeepAspectRatioConstraint
-{
- /**
- * @brief Constructor.
- */
- ScaleToFillXYKeepAspectRatioConstraint()
- { }
/**
- * @param[in] current The actor's current scale
- * @param[in] sizeProperty The actor's current size
- * @param[in] parentSizeProperty The parent's current size.
- * @return The actor's new scale
- */
- Vector3 operator()(const Vector3& current,
- const PropertyInput& sizeProperty,
- const PropertyInput& parentSizeProperty)
- {
- return FillXYKeepAspectRatio( parentSizeProperty.GetVector3(), sizeProperty.GetVector3() );
- }
-};
-
-/**
- * @brief EqualToConstraint
- *
- * f(current, property) = property
- */
-struct EqualToConstraint
-{
- /**
- * @brief Constructor.
- */
- EqualToConstraint()
- { }
-
- /**
- * @brief override functor for float properties
+ * @brief Overrides functor for Vector2 properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- float operator()(const float current, const PropertyInput& property)
+ void operator()( Vector2& current, const PropertyInputContainer& inputs )
{
- return property.GetFloat();
+ current = inputs[0]->GetVector2();
}
/**
- * @brief override functor for float properties
+ * @brief Overrides functor for Vector3 properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- Vector3 operator()(const Vector3& current, const PropertyInput& property)
+ void operator()( Vector3& current, const PropertyInputContainer& inputs )
{
- return property.GetVector3();
+ current = inputs[0]->GetVector3();
}
/**
- * @brief override functor for float properties
+ * @brief Overrides functor for Vector4 properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- Vector4 operator()(const Vector4& current, const PropertyInput& property)
+ void operator()( Vector4& current, const PropertyInputContainer& inputs )
{
- return property.GetVector4();
+ current = inputs[0]->GetVector4();
}
/**
- * @brief override functor for float properties
+ * @brief Overrides functor for Quaternion properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- Quaternion operator()(const Quaternion& current, const PropertyInput& property)
+ void operator()( Quaternion& current, const PropertyInputContainer& inputs )
{
- return property.GetQuaternion();
+ current = inputs[0]->GetQuaternion();
}
/**
- * @brief override functor for float properties
+ * @brief Overrides functor for Matrix3 properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value
+ * @param[in] inputs Contains the property to copy
*/
- Matrix3 operator()(const Matrix3& current, const PropertyInput& property)
+ void operator()( Matrix3& current, const PropertyInputContainer& inputs )
{
- return property.GetMatrix3();
+ current = inputs[0]->GetMatrix3();
}
/**
- * @brief override functor for float properties
+ * @brief Overrides functor for Matrix properties.
*
- * @param[in] current The current property value
- * @param[in] property The property to copy
- * @return The copy of the input property
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value, the constrained value is set
+ * @param[in] inputs Contains the property to copy
*/
- Matrix operator()(const Matrix& current, const PropertyInput& property)
+ void operator()( Matrix& current, const PropertyInputContainer& inputs )
{
- return property.GetMatrix();
+ current = inputs[0]->GetMatrix();
}
};
/**
- * @brief RelativeToConstraint for Vector3 properties
+ * @brief The constraint function that updates the target property with the value of the first source
+ * multiplied by scale parameter (for Vector3 properties).
*
- * f(current, property, scale) = property * scale
+ * @e current = <em>input[0]</em> * @e scale. @e current, <em>input[0]</em>, and @e scale
+ * indicates the target property, the first constraint source, and the scale parameter, respectively.
+ * * implies element-wise multiplication.
+ * @SINCE_1_0.0
*/
struct RelativeToConstraint
{
/**
* @brief Constructor.
+ * @SINCE_1_0.0
+ * @param[in] scale Scale factor
*/
RelativeToConstraint( float scale )
: mScale( scale, scale, scale ) { }
/**
* @brief Constructor.
+ * @SINCE_1_0.0
+ * @param[in] scale Scale factor
*/
RelativeToConstraint( const Vector3& scale )
: mScale( scale ) { }
/**
* @brief Functor.
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value (vector3 property * scale factor)
+ * @param[in] inputs Property container for current property calculation
*/
- Vector3 operator()(const Vector3& current, const PropertyInput& property)
+ void operator()( Vector3& current, const PropertyInputContainer& inputs )
{
- return property.GetVector3() * mScale;
+ current = inputs[0]->GetVector3() * mScale;
}
Vector3 mScale; ///< Component-wise scale factor
};
/**
- * @brief RelativeToConstraint for float properties
+ * @brief The constraint function that updates the target property with the value of the first source
+ * multiplied by scale parameter (for float properties).
+ *
+ * @e current = <em>input[0]</em> * @e scale. @e current, <em>input[0]</em>, and @e scale
+ * indicates the target property, the first constraint source, and the scale parameter, respectively.
+ * @SINCE_1_0.0
*/
struct RelativeToConstraintFloat
{
/**
* @brief Constructor.
+ * @SINCE_1_0.0
+ * @param[in] scale Scale factor
*/
RelativeToConstraintFloat( float scale )
: mScale( scale ) { }
/**
* @brief Functor.
+ * @SINCE_1_0.0
+ * @param[in,out] current The current property value (float property * scale factor)
+ * @param[in] inputs Property container for current property calculation
*/
- float operator()(const float current, const PropertyInput& property)
+ void operator()( float& current, const PropertyInputContainer& inputs )
{
- return property.GetFloat() * mScale;
+ current = inputs[0]->GetFloat() * mScale;
}
float mScale; ///< Scale factor
};
/**
- * @brief Constraint which sets width to be another actor's width,
- * and the height to a fixed height.
- */
-struct SourceWidthFixedHeight
-{
- /**
- * @brief Constructor.
- */
- SourceWidthFixedHeight( float height )
- : mFixedHeight( height ) { }
-
- /**
- * @brief Functor.
- */
- Vector3 operator()(const Vector3& current,
- const PropertyInput& sourceSize)
- {
- return Vector3( sourceSize.GetVector3().width, mFixedHeight, current.depth );
- }
-
- float mFixedHeight; ///< the fixed height
-};
-
-/**
* @brief Constraint function to aim a camera at a target.
*
* Constraint which sets camera's orientation given camera world position
- * and a target world position. Uses target's up vector to orient the
+ * and a target world position. Uses target's up vector to orient the
* constrained actor along the vector between camera position and
* target position.
*
- * @param[in] current The current orientation property value
- * @param[in] targetPosition World position of target
- * @param[in] cameraPosition World position of camera
- * @param[in] targetOrientation World orientation of the target
- * @return The orientation of the camera
+ * @SINCE_1_0.0
+ * @param[in,out] current The current orientation property value, the constrained value is set
+ * @param[in] inputs Contains the world position of the target, the world position of the camera, and the world orientation of the target
*/
-inline Quaternion LookAt( const Quaternion& current,
- const PropertyInput& targetPosition,
- const PropertyInput& cameraPosition,
- const PropertyInput& targetOrientation )
+inline void LookAt( Dali::Quaternion& current, const Dali::PropertyInputContainer& inputs )
{
+ const PropertyInput& targetPosition( *inputs[0] );
+ const PropertyInput& cameraPosition( *inputs[1] );
+ const PropertyInput& targetOrientation( *inputs[2] );
+
Vector3 vForward = targetPosition.GetVector3() - cameraPosition.GetVector3();
vForward.Normalize();
Vector3 vY = vForward.Cross(vX);
vY.Normalize();
- return Quaternion( vX, vY, vForward );
+ current = Quaternion( vX, vY, vForward );
}
+/**
+ * @}
+ */
} // namespace Dali
#endif // __DALI_CONSTRAINTS_H__