1 #ifndef __DALI_INTERNAL_PATH_CONSTRAINT_H__
2 #define __DALI_INTERNAL_PATH_CONSTRAINT_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/path-impl.h>
23 #include <dali/internal/event/common/object-impl.h>
24 #include <dali/public-api/animation/path-constraint.h>
32 typedef IntrusivePtr<PathConstraint> PathConstraintPtr;
33 typedef Dali::Vector<Object*> ObjectContainer;
34 typedef ObjectContainer::Iterator ObjectIter;
37 * @brief Constraint functor to constraint properties to paths.
39 * Vector3 properties will be constrained to the position of the path and
40 * Rotation properties will be constrained to follow the tangent of the path
41 * given a forward vector in object's local space.
43 struct PathConstraintFunctor
48 * @param[in] path The path used in the constraint
49 * @param[in] range The range of values in the input property which will be mapped to 0..1
52 PathConstraintFunctor(PathPtr path, const Vector2& range ):mPath(path),mRange(range){}
57 * @param[in] path The path used in the constraint
58 * @param[in] range The range of values in the input property which will be mapped to 0..1
59 * @param[in] forward Vector in object space which will be aligned with the tangent of the path
61 PathConstraintFunctor(PathPtr path, const Vector2& range,const Vector3& forward ):mPath(path),mForward(forward),mRange(range){}
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 t = ( inputs[0]->GetFloat() - mRange.x ) / ( mRange.y-mRange.x );
76 mPath->Sample( t, position, tangent );
80 * @brief Functor operator for Quaternion properties
82 * @param[in,out] current Current value of the property
83 * @param[in] inputs Contains the input property used as the parameter for the path
85 * @return The rotation which will align the forward vector and the tangent of the path at the given parameter.
87 void operator()( Quaternion& current,
88 const PropertyInputContainer& inputs)
90 float t = ( inputs[0]->GetFloat() - mRange.x ) / (mRange.y-mRange.x);
91 Vector3 position, tangent;
92 mPath->Sample( t, position, tangent );
93 current = Quaternion( mForward, tangent );
96 PathPtr mPath; ///< The path used
97 Vector3 mForward; ///< Vector in object space which will be aligned with the tangent of the path
98 Vector2 mRange; ///< The range of values in the input property which will be mapped to 0..1
102 * @brief A PathConstraint used to constraint properties to a path
104 class PathConstraint : public Object, public Object::Observer
109 * Create a new PathConstraint
110 * @param[in] path The path used in the constraint
111 * @param[in] range The range of values in the input property which will be mapped to 0..1
112 * @return A smart-pointer to the newly allocated PathConstraint.
114 static PathConstraint* New( Path& path, const Vector2& range );
122 virtual ~PathConstraint();
126 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
128 virtual void SceneObjectAdded(Object& object){}
131 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
133 virtual void SceneObjectRemoved(Object& object){}
136 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
138 virtual void ObjectDestroyed(Object& object);
141 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
143 virtual unsigned int GetDefaultPropertyCount() const;
146 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
148 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
151 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
153 virtual const char* GetDefaultPropertyName(Property::Index index) const;
156 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
158 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
161 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
163 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
166 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
168 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
171 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
173 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
176 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
178 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
181 * @copydoc Dali::Internal::Object::SetDefaultProperty()
183 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
186 * @copydoc Dali::Internal::Object::GetDefaultProperty()
188 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
191 * @copydoc Dali::Internal::Object::GetSceneObject()
193 virtual const SceneGraph::PropertyOwner* GetSceneObject() const{ return NULL; }
196 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
198 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{ return NULL; }
201 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
203 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{ return NULL; }
208 * @copydoc Dali::PathConstraint::Apply
210 void Apply( Property source, Property target, const Vector3& forward );
213 * @copydoc Dali::PathConstraint::Remove
215 void Remove( Dali::Handle& target );
221 * @param[in] path The path used in the constraint
222 * @param[in] range The range of values in the input property which will be mapped to 0..1
224 PathConstraint( Path& path, const Vector2& range );
230 PathConstraint(const PathConstraint&);
233 PathConstraint& operator=(const PathConstraint& rhs);
235 PathPtr mPath; ///< The path used to constrain objects
236 ObjectContainer mObservedObjects; ///< The list of object which have been constrained by the PathConstraint
237 Vector2 mRange; ///< The range of values in the input property which will be mapped to 0..1
242 // Get impl of handle
243 inline Internal::PathConstraint& GetImplementation(Dali::PathConstraint& pathConstraint)
245 DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
246 Dali::RefObject& object = pathConstraint.GetBaseObject();
247 return static_cast<Internal::PathConstraint&>(object);
250 inline const Internal::PathConstraint& GetImplementation(const Dali::PathConstraint& pathConstraint)
252 DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
253 const Dali::RefObject& object = pathConstraint.GetBaseObject();
254 return static_cast<const Internal::PathConstraint&>(object);
259 #endif //__DALI_INTERNAL_KEY_FRAMES_H__