1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_H_
5 * Copyright (c) 2016 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.
21 #include <dali/internal/update/manager/transform-manager.h>
22 #include <dali/internal/update/common/animatable-property.h>
32 struct TransformManagerPropertyHandler : public AnimatablePropertyBase
37 TransformManagerPropertyHandler()
39 mId( INVALID_TRANSFORM_ID )
43 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
45 virtual Dali::Property::Type GetType() const = 0;
48 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
50 virtual T& Get(size_t bufferIndex) = 0;
53 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
55 virtual const T& Get(size_t bufferIndex) const = 0;
58 * @copydoc Dali::PropertyInput::GetVector3()
60 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const{ return Vector3::ZERO; }
63 * Retrieve a component of property
64 * @param[in] component The component of the property
66 virtual const float& GetFloatComponent(unsigned int component)=0;
69 * Set the property value. This will only persist for the current frame; the property
70 * will be reset with the base value, at the beginning of the next frame.
71 * @param[in] bufferIndex Not used
72 * @param[in] value The new property value.
74 virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
77 * Change a component of property
78 * @param[in] value The new value of the component
79 * @param[in] component The component of the property
81 virtual void SetFloatComponent( float value, unsigned int component){}
84 * @copydoc Dali::AnimatableProperty::Bake()
86 virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
89 * Bake a component of a property
90 * @param[in] value The new value of the component
91 * @param[in] component The component of the property
93 virtual void BakeFloatComponent( float value, unsigned int component){}
96 * @copydoc Dali::AnimatableProperty::BakeX()
98 virtual void BakeX(BufferIndex bufferIndex, float value){}
101 * @copydoc Dali::AnimatableProperty::BakeY()
103 virtual void BakeY(BufferIndex bufferIndex, float value){}
106 * @copydoc Dali::AnimatableProperty::BakeZ()
108 virtual void BakeZ(BufferIndex bufferIndex, float value){}
111 * @copydoc Dali::AnimatableProperty::BakeRelative()
113 virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
116 * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
118 virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
121 * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
123 virtual void ResetToBaseValue(BufferIndex updateBufferIndex){}
126 * @copydoc Dali::AnimatableProperty::IsClean()
128 virtual bool IsClean() const{ return false; }
131 * Initializes the property
132 * @param[in] transformManager Pointer to the transform manager
133 * @param[in] Id of the transformation the property is associated with
135 void Initialize( TransformManager* transformManager, TransformId id )
137 mTxManager = transformManager;
142 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
144 virtual bool IsTransformManagerProperty() const
149 TransformManager* mTxManager;
153 struct TransformManagerPropertyVector3 : public TransformManagerPropertyHandler<Vector3>
156 TransformManagerPropertyVector3(TransformManagerProperty property)
157 :TransformManagerPropertyHandler(),
158 mProperty( property )
161 Dali::Property::Type GetType() const
163 return Dali::PropertyTypes::Get<Vector3>();
166 Vector3& Get(size_t bufferIndex)
168 return mTxManager->GetVector3PropertyValue( mId, mProperty );
171 const Vector3& Get(size_t bufferIndex) const
173 return mTxManager->GetVector3PropertyValue( mId, mProperty );
176 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
178 return Get(bufferIndex);
181 const float& GetFloatComponent( unsigned int component )
183 return mTxManager->GetVector3PropertyComponentValue( mId, mProperty, component );
186 void Set(BufferIndex bufferIndex, const Vector3& value)
188 mTxManager->SetVector3PropertyValue( mId, mProperty, value );
191 void SetComponent(BufferIndex bufferIndex, float value, unsigned int component)
193 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
196 void BakeComponent(BufferIndex bufferIndex, float value, unsigned int component)
198 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
201 void Bake(BufferIndex bufferIndex, const Vector3& value)
203 mTxManager->BakeVector3PropertyValue(mId, mProperty, value );
206 void BakeX(BufferIndex bufferIndex, float value)
208 mTxManager->BakeXVector3PropertyValue(mId, mProperty, value );
211 void BakeY(BufferIndex bufferIndex, float value)
213 mTxManager->BakeYVector3PropertyValue(mId, mProperty, value );
216 void BakeZ(BufferIndex bufferIndex, float value)
218 mTxManager->BakeZVector3PropertyValue(mId, mProperty, value );
221 void SetFloatComponent( float value, unsigned int component)
223 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
226 void BakeFloatComponent( float value, unsigned int component )
228 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
231 void BakeRelative(BufferIndex bufferIndex, const Vector3& value)
233 mTxManager->BakeRelativeVector3PropertyValue(mId, mProperty, value );
236 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value)
238 mTxManager->BakeMultiplyVector3PropertyValue(mId, mProperty, value );
241 TransformManagerProperty mProperty;
244 class TransformManagerPropertyQuaternion : public TransformManagerPropertyHandler<Quaternion>
248 TransformManagerPropertyQuaternion()
249 :TransformManagerPropertyHandler()
252 virtual Dali::Property::Type GetType() const
254 return Dali::PropertyTypes::Get<Quaternion>();
257 Quaternion& Get(size_t bufferIndex)
259 return mTxManager->GetQuaternionPropertyValue( mId );
262 const Quaternion& Get(size_t bufferIndex) const
264 return mTxManager->GetQuaternionPropertyValue( mId );
267 const float& GetFloatComponent( unsigned int component)
269 return mTxManager->GetQuaternionPropertyValue( mId ).mVector[component];
272 void Set(BufferIndex bufferIndex, const Quaternion& value)
274 return mTxManager->SetQuaternionPropertyValue( mId, value );
277 void Bake(BufferIndex bufferIndex, const Quaternion& value)
279 return mTxManager->BakeQuaternionPropertyValue( mId, value );
282 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value)
284 return mTxManager->BakeRelativeQuaternionPropertyValue( mId, value );
289 * A Vector3 property used as input.
291 class TransformManagerVector3Input : public PropertyInputImpl
296 * Create an TransformManagerVector3Input
298 TransformManagerVector3Input( TransformManagerProperty property, const Vector3& initialValue )
300 mId(INVALID_TRANSFORM_ID),
306 * Virtual destructor.
308 virtual ~TransformManagerVector3Input()
313 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
315 virtual Dali::Property::Type GetType() const
317 return Dali::PropertyTypes::Get<Vector3>();
321 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
323 virtual bool IsClean() const
329 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
331 virtual bool InputInitialized() const
337 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
338 * @note A constraint can only receive the inherited property from the previous frame.
340 virtual bool InputChanged() const
346 * Helper function to get the transform components out of the world matrix.
347 * It stores the value in the mValue member variable
349 void ComputeTransformComponent() const
353 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
355 if( mProperty == TRANSFORM_PROPERTY_WORLD_POSITION )
357 mValue = worldMatrix.GetTranslation3();
359 else if( mProperty == TRANSFORM_PROPERTY_WORLD_SCALE )
362 Quaternion orientation;
363 worldMatrix.GetTransformComponents(position, orientation, mValue);
369 * @copydoc Dali::PropertyInput::GetVector3()
371 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
373 ComputeTransformComponent();
378 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
380 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
382 ComputeTransformComponent();
387 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
389 Vector3& Get(size_t bufferIndex)
391 ComputeTransformComponent();
396 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
398 const Vector3& Get(size_t bufferIndex) const
400 ComputeTransformComponent();
405 * Retrieve the property value.
406 * @param[in] bufferIndex The buffer to read.
407 * @return The property value.
409 const Vector3& operator[](size_t bufferIndex) const
411 ComputeTransformComponent();
416 * Initializes the property
417 * @param[in] transformManager Pointer to the transform manager
418 * @param[in] Id of the transformation the property is associated with
420 void Initialize( TransformManager* transformManager, TransformId id )
422 mTxManager = transformManager;
427 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
429 virtual bool IsTransformManagerProperty() const
437 TransformManagerVector3Input(const TransformManagerVector3Input& property);
440 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
444 TransformManager* mTxManager;
446 TransformManagerProperty mProperty;
447 mutable Vector3 mValue;
451 * A Quaternion property used as input.
453 class TransformManagerQuaternionInput : public PropertyInputImpl
460 TransformManagerQuaternionInput()
462 mId(INVALID_TRANSFORM_ID),
463 mValue(1.0f,0.0f,0.0f,0.0f)
468 * Virtual destructor.
470 virtual ~TransformManagerQuaternionInput()
475 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
477 virtual Dali::Property::Type GetType() const
479 return Dali::PropertyTypes::Get<Quaternion>();
483 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
485 virtual bool IsClean() const
491 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
493 virtual bool InputInitialized() const
499 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
500 * @note A constraint can only receive the inherited property from the previous frame.
502 virtual bool InputChanged() const
508 * Helper function to get the orientation out of the world matrix.
509 * It stores the result in the mValue member variable
511 void ComputeTransformComponent() const
515 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
516 Vector3 position, scale;
517 worldMatrix.GetTransformComponents(position, mValue, scale);
522 * @copydoc Dali::PropertyInput::GetQuaternion()
524 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
526 ComputeTransformComponent();
531 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
533 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
535 ComputeTransformComponent();
540 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
542 Quaternion& Get(size_t bufferIndex)
544 ComputeTransformComponent();
549 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
551 const Quaternion& Get(size_t bufferIndex) const
553 ComputeTransformComponent();
558 * Retrieve the property value.
559 * @param[in] bufferIndex The buffer to read.
560 * @return The property value.
562 const Quaternion& operator[](size_t bufferIndex) const
564 ComputeTransformComponent();
569 * Initializes the property
570 * @param[in] transformManager Pointer to the transform manager
571 * @param[in] Id of the transformation the property is associated with
573 void Initialize( TransformManager* transformManager, TransformId id )
575 mTxManager = transformManager;
580 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
582 virtual bool IsTransformManagerProperty() const
590 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
593 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
597 TransformManager* mTxManager;
599 mutable Quaternion mValue;
603 * A Matrix property used as input.
605 class TransformManagerMatrixInput : public PropertyInputImpl
612 TransformManagerMatrixInput()
614 mId(INVALID_TRANSFORM_ID)
619 * Virtual destructor.
621 virtual ~TransformManagerMatrixInput()
626 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
628 virtual Dali::Property::Type GetType() const
630 return Dali::PropertyTypes::Get<Matrix>();
634 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
636 virtual bool IsClean() const
642 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
644 virtual bool InputInitialized() const
650 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
651 * @note A constraint can only receive the inherited property from the previous frame.
653 virtual bool InputChanged() const
659 * @copydoc Dali::PropertyInput::GetMatrix()
661 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
665 return mTxManager->GetWorldMatrix(mId);
668 return Matrix::IDENTITY;
672 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
674 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
678 return mTxManager->GetWorldMatrix(mId);
681 return Matrix::IDENTITY;
685 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
687 Matrix& Get(size_t bufferIndex)
689 DALI_ASSERT_ALWAYS( mTxManager != 0 );
690 return mTxManager->GetWorldMatrix(mId);
694 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
696 const Matrix& Get(size_t bufferIndex) const
698 return GetMatrix(bufferIndex);
702 * Retrieve the property value.
703 * @param[in] bufferIndex The buffer to read.
704 * @return The property value.
706 const Matrix& operator[](size_t bufferIndex) const
708 return GetMatrix(bufferIndex);
711 void Initialize( TransformManager* transformManager, TransformId id )
713 mTxManager = transformManager;
718 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
720 virtual bool IsTransformManagerProperty() const
728 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
731 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
735 TransformManager* mTxManager;
740 } //namespace SceneGraph
741 } //namespace Internal
744 #endif // TRANSFORM_MANAGER_PROPERTY_H_