1 #ifndef __DALI_INTERNAL_PATH_CONSTRAINER_H__
2 #define __DALI_INTERNAL_PATH_CONSTRAINER_H__
5 * Copyright (c) 2018 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/internal/event/animation/constrainer.h>
23 #include <dali/devel-api/animation/path-constrainer.h>
24 #include <dali/public-api/math/math-utils.h>
25 #include <dali/internal/event/animation/path-impl.h>
33 typedef IntrusivePtr<PathConstrainer> PathConstrainerPtr;
36 * @brief Constraint functor to constraint properties to paths.
38 * Vector3 properties will be constrained to the position of the path and
39 * Rotation properties will be constrained to follow the tangent of the path
40 * given a forward vector in object's local space.
42 struct PathConstraintFunctor
47 * @param[in] path The path used in the constraint
48 * @param[in] range The range of values in the input property which will be mapped to [0,1]
49 * @param[in] wrap Wrapping domain. Input property value will be wrapped in the domain [wrap.x,wrap.y] before mapping to [0,1]
51 PathConstraintFunctor(PathPtr path, const Vector2& range, const Vector2& wrap ):mPath(path),mRange(range),mWrap(wrap){}
56 * @param[in] path The path used in the constraint
57 * @param[in] range The range of values in the input property which will be mapped to 0..1
58 * @param[in] forward Vector in object space which will be aligned with the tangent of the path
59 * @param[in] wrap Wrapping domain. Input property value will be wrapped in the domain [wrap.x,wrap.y] before mapping to [0,1]
61 PathConstraintFunctor(PathPtr path, const Vector2& range,const Vector3& forward, const Vector2& wrap ):mPath(path),mForward(forward),mRange(range),mWrap(wrap){}
64 * @brief Functor operator for Vector3 properties
66 * @param[in,out] position Current value of the property
67 * @param[in] inputs Contains the input property used as the parameter for the path
69 * @return The position of the path at the given parameter.
71 void operator()( Vector3& position,
72 const PropertyInputContainer& inputs)
74 float inputWrapped = inputs[0]->GetFloat();
75 if( inputWrapped < mWrap.x || inputWrapped > mWrap.y )
77 inputWrapped = WrapInDomain(inputWrapped, mWrap.x, mWrap.y);
80 float t = ( inputWrapped - mRange.x ) / ( mRange.y-mRange.x );
83 mPath->Sample( t, position, tangent );
87 * @brief Functor operator for Quaternion properties
89 * @param[in,out] current Current value of the property
90 * @param[in] inputs Contains the input property used as the parameter for the path
92 * @return The rotation which will align the forward vector and the tangent of the path at the given parameter.
94 void operator()( Quaternion& current,
95 const PropertyInputContainer& inputs)
97 float inputWrapped = inputs[0]->GetFloat();
98 if( inputWrapped < mWrap.x || inputWrapped > mWrap.y )
100 inputWrapped = WrapInDomain(inputWrapped, mWrap.x, mWrap.y);
103 float t = ( inputWrapped - mRange.x ) / ( mRange.y-mRange.x );
105 Vector3 position, tangent;
106 mPath->Sample( t, position, tangent );
107 current = Quaternion( mForward, tangent );
110 PathPtr mPath; ///< The path used
111 Vector3 mForward; ///< Vector in object space which will be aligned with the tangent of the path
112 Vector2 mRange; ///< The range of values in the input property which will be mapped to 0..1
113 Vector2 mWrap; ///< Wrapping domain. Input property will be wrapped in this domain before being mapped to [0,1]
117 * @brief A PathConstrainer used to constraint properties to a path
119 class PathConstrainer : public Constrainer
124 * Create a new PathConstrainer
125 * @return A smart-pointer to the newly allocated PathConstrainer.
127 static PathConstrainer* New();
134 virtual ~PathConstrainer();
139 * @copydoc Dali::Internal::Object::SetDefaultProperty()
141 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
144 * @copydoc Dali::Internal::Object::GetDefaultProperty()
146 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
149 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
151 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
156 * @copydoc Dali::PathConstrainer::Apply
158 void Apply( Property target, Property source, const Vector2& range, const Vector2& wrap );
166 PathConstrainer(const PathConstrainer&);
169 PathConstrainer& operator=(const PathConstrainer& rhs);
171 PathPtr mPath; ///< The path used in the constraints
172 Vector3 mForward; ///< Vector in object space which will be aligned with the tangent of the path
177 // Get impl of handle
178 inline Internal::PathConstrainer& GetImplementation(Dali::PathConstrainer& pathConstrainer)
180 DALI_ASSERT_ALWAYS( pathConstrainer && "PathConstrainer handle is empty" );
181 Dali::RefObject& object = pathConstrainer.GetBaseObject();
182 return static_cast<Internal::PathConstrainer&>(object);
185 inline const Internal::PathConstrainer& GetImplementation(const Dali::PathConstrainer& pathConstrainer)
187 DALI_ASSERT_ALWAYS( pathConstrainer && "PathConstrainer handle is empty" );
188 const Dali::RefObject& object = pathConstrainer.GetBaseObject();
189 return static_cast<const Internal::PathConstrainer&>(object);
194 #endif //__DALI_INTERNAL_PATH_CONSTRAINER_H__