1 #ifndef __DALI_INTERNAL_PATH_CONSTRAINER_H__
2 #define __DALI_INTERNAL_PATH_CONSTRAINER_H__
5 * Copyright (c) 2015 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::GetDefaultPropertyCount()
141 virtual unsigned int GetDefaultPropertyCount() const;
144 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
146 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
149 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
151 virtual const char* GetDefaultPropertyName(Property::Index index) const;
154 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
156 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
159 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
161 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
164 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
166 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
169 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
171 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
174 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
176 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
179 * @copydoc Dali::Internal::Object::SetDefaultProperty()
181 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
184 * @copydoc Dali::Internal::Object::GetDefaultProperty()
186 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
191 * @copydoc Dali::PathConstrainer::Apply
193 void Apply( Property target, Property source, const Vector2& range, const Vector2& wrap );
201 PathConstrainer(const PathConstrainer&);
204 PathConstrainer& operator=(const PathConstrainer& rhs);
206 PathPtr mPath; ///< The path used in the constraints
207 Vector3 mForward; ///< Vector in object space which will be aligned with the tangent of the path
212 // Get impl of handle
213 inline Internal::PathConstrainer& GetImplementation(Dali::PathConstrainer& pathConstrainer)
215 DALI_ASSERT_ALWAYS( pathConstrainer && "PathConstrainer handle is empty" );
216 Dali::RefObject& object = pathConstrainer.GetBaseObject();
217 return static_cast<Internal::PathConstrainer&>(object);
220 inline const Internal::PathConstrainer& GetImplementation(const Dali::PathConstrainer& pathConstrainer)
222 DALI_ASSERT_ALWAYS( pathConstrainer && "PathConstrainer handle is empty" );
223 const Dali::RefObject& object = pathConstrainer.GetBaseObject();
224 return static_cast<const Internal::PathConstrainer&>(object);
229 #endif //__DALI_INTERNAL_PATH_CONSTRAINER_H__