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] current Current value of the property
67 * @param[in] property The input property used as the parameter for the path
69 * @return The position of the path at the given parameter.
71 Vector3 operator()(const Vector3& current,
72 const PropertyInput& property)
74 float t = ( property.GetFloat() - mRange.x ) / (mRange.y-mRange.x);
75 Vector3 position, tangent;
76 mPath->Sample( t, position, tangent );
81 * @brief Functor operator for Quaternion properties
83 * @param[in] current Current value of the property
84 * @param[in] property The input property used as the parameter for the path
86 * @return The rotation which will align the forward vector and the tangent of the path at the given parameter.
88 Quaternion operator()( const Quaternion& current,
89 const PropertyInput& property)
91 float t = ( property.GetFloat() - mRange.x ) / (mRange.y-mRange.x);
92 Vector3 position, tangent;
93 mPath->Sample( t, position, tangent );
94 return Quaternion( mForward, tangent );
97 PathPtr mPath; ///< The path used
98 Vector3 mForward; ///< Vector in object space which will be aligned with the tangent of the path
99 Vector2 mRange; ///< The range of values in the input property which will be mapped to 0..1
103 * @brief A PathConstraint used to constraint properties to a path
105 class PathConstraint : public Object, public Object::Observer
110 * Create a new PathConstraint
111 * @param[in] path The path used in the constraint
112 * @param[in] range The range of values in the input property which will be mapped to 0..1
113 * @return A smart-pointer to the newly allocated PathConstraint.
115 static PathConstraint* New( Path& path, const Vector2& range );
123 virtual ~PathConstraint();
127 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
129 virtual void SceneObjectAdded(Object& object){}
132 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
134 virtual void SceneObjectRemoved(Object& object){}
137 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
139 virtual void ObjectDestroyed(Object& object);
142 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
144 virtual unsigned int GetDefaultPropertyCount() const;
147 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
149 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
152 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
154 virtual const char* GetDefaultPropertyName(Property::Index index) const;
157 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
159 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
162 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
164 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
167 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
169 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
172 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
174 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
177 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
179 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
182 * @copydoc Dali::Internal::Object::SetDefaultProperty()
184 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
187 * @copydoc Dali::Internal::Object::GetDefaultProperty()
189 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
192 * @copydoc Dali::Internal::Object::GetSceneObject()
194 virtual const SceneGraph::PropertyOwner* GetSceneObject() const{ return NULL; }
197 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
199 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const{ return NULL; }
202 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
204 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const{ return NULL; }
209 * @copydoc Dali::PathConstraint::Apply
211 void Apply( Property source, Property target, const Vector3& forward );
214 * @copydoc Dali::PathConstraint::Remove
216 void Remove( Dali::Handle& target );
222 * @param[in] path The path used in the constraint
223 * @param[in] range The range of values in the input property which will be mapped to 0..1
225 PathConstraint( Path& path, const Vector2& range );
231 PathConstraint(const PathConstraint&);
234 PathConstraint& operator=(const PathConstraint& rhs);
236 PathPtr mPath; ///< The path used to constrain objects
237 ObjectContainer mObservedObjects; ///< The list of object which have been constrained by the PathConstraint
238 Vector2 mRange; ///< The range of values in the input property which will be mapped to 0..1
243 // Get impl of handle
244 inline Internal::PathConstraint& GetImplementation(Dali::PathConstraint& pathConstraint)
246 DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
247 Dali::RefObject& object = pathConstraint.GetBaseObject();
248 return static_cast<Internal::PathConstraint&>(object);
251 inline const Internal::PathConstraint& GetImplementation(const Dali::PathConstraint& pathConstraint)
253 DALI_ASSERT_ALWAYS( pathConstraint && "PathConstraint handle is empty" );
254 const Dali::RefObject& object = pathConstraint.GetBaseObject();
255 return static_cast<const Internal::PathConstraint&>(object);
260 #endif //__DALI_INTERNAL_KEY_FRAMES_H__