1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_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.
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 Dali::Property::Type GetType() const override = 0;
48 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
50 virtual T& Get( BufferIndex bufferIndex ) = 0;
53 * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
55 virtual const T& Get( BufferIndex bufferIndex ) const = 0;
58 * @copydoc Dali::PropertyInput::GetVector3()
60 const Vector3& GetVector3( BufferIndex bufferIndex ) const override{ return Vector3::ZERO; }
63 * Retrieve a component of property
64 * @param[in] component The component of the property
66 virtual const float& GetFloatComponent(uint32_t 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, uint32_t 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, uint32_t 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 void ResetToBaseValue(BufferIndex updateBufferIndex) override{}
126 * @copydoc Dali::AnimatableProperty::IsClean()
128 bool IsClean() const override{ 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 bool IsTransformManagerProperty() const override
149 TransformManager* mTxManager;
153 struct TransformManagerPropertyVector3 : public TransformManagerPropertyHandler<Vector3>
156 TransformManagerPropertyVector3(TransformManagerProperty property)
157 :TransformManagerPropertyHandler(),
158 mProperty( property )
161 Dali::Property::Type GetType() const override
163 return Dali::PropertyTypes::Get<Vector3>();
166 Vector3& Get( BufferIndex bufferIndex ) override
168 return mTxManager->GetVector3PropertyValue( mId, mProperty );
171 const Vector3& Get( BufferIndex bufferIndex ) const override
173 return mTxManager->GetVector3PropertyValue( mId, mProperty );
176 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
178 return Get(bufferIndex);
181 const float& GetFloatComponent( uint32_t component ) override
183 return mTxManager->GetVector3PropertyComponentValue( mId, mProperty, component );
186 void Set(BufferIndex bufferIndex, const Vector3& value) override
188 mTxManager->SetVector3PropertyValue( mId, mProperty, value );
191 void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
193 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
196 void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
198 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
201 void Bake(BufferIndex bufferIndex, const Vector3& value) override
203 mTxManager->BakeVector3PropertyValue(mId, mProperty, value );
206 void BakeX(BufferIndex bufferIndex, float value) override
208 mTxManager->BakeXVector3PropertyValue(mId, mProperty, value );
211 void BakeY(BufferIndex bufferIndex, float value) override
213 mTxManager->BakeYVector3PropertyValue(mId, mProperty, value );
216 void BakeZ(BufferIndex bufferIndex, float value) override
218 mTxManager->BakeZVector3PropertyValue(mId, mProperty, value );
221 void SetFloatComponent( float value, uint32_t component) override
223 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
226 void BakeFloatComponent( float value, uint32_t component ) override
228 mTxManager->BakeVector3PropertyComponentValue( mId, mProperty, value, component);
231 void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
233 mTxManager->BakeRelativeVector3PropertyValue(mId, mProperty, value );
236 void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
238 mTxManager->BakeMultiplyVector3PropertyValue(mId, mProperty, value );
241 TransformManagerProperty mProperty;
244 class TransformManagerPropertyQuaternion : public TransformManagerPropertyHandler<Quaternion>
248 TransformManagerPropertyQuaternion()
249 :TransformManagerPropertyHandler()
252 Dali::Property::Type GetType() const override
254 return Dali::PropertyTypes::Get<Quaternion>();
257 Quaternion& Get( BufferIndex bufferIndex ) override
259 return mTxManager->GetQuaternionPropertyValue( mId );
262 const Quaternion& Get( BufferIndex bufferIndex ) const override
264 return mTxManager->GetQuaternionPropertyValue( mId );
267 const float& GetFloatComponent( uint32_t component) override
269 return mTxManager->GetQuaternionPropertyValue( mId ).mVector[component];
272 void Set(BufferIndex bufferIndex, const Quaternion& value) override
274 return mTxManager->SetQuaternionPropertyValue( mId, value );
277 void Bake(BufferIndex bufferIndex, const Quaternion& value) override
279 return mTxManager->BakeQuaternionPropertyValue( mId, value );
282 void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
284 return mTxManager->BakeRelativeQuaternionPropertyValue( mId, value );
287 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
289 return Get(bufferIndex);
295 * A Vector3 property used as input.
297 class TransformManagerVector3Input : public PropertyInputImpl
302 * Create an TransformManagerVector3Input
304 TransformManagerVector3Input( TransformManagerProperty property, const Vector3& initialValue )
305 :mTxManager(nullptr),
306 mId(INVALID_TRANSFORM_ID),
312 * Virtual destructor.
314 ~TransformManagerVector3Input() override
319 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
321 Dali::Property::Type GetType() const override
323 return Dali::PropertyTypes::Get<Vector3>();
327 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
329 virtual bool IsClean() const
335 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
337 bool InputInitialized() const override
343 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
344 * @note A constraint can only receive the inherited property from the previous frame.
346 bool InputChanged() const override
352 * Helper function to get the transform components out of the world matrix.
353 * It stores the value in the mValue member variable
355 void ComputeTransformComponent() const
359 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
361 if( mProperty == TRANSFORM_PROPERTY_WORLD_POSITION )
363 mValue = worldMatrix.GetTranslation3();
365 else if( mProperty == TRANSFORM_PROPERTY_WORLD_SCALE )
368 Quaternion orientation;
369 worldMatrix.GetTransformComponents(position, orientation, mValue);
375 * @copydoc Dali::PropertyInput::GetVector3()
377 const Vector3& GetVector3( BufferIndex bufferIndex ) const override
379 ComputeTransformComponent();
384 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
386 const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const override
388 ComputeTransformComponent();
393 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
395 Vector3& Get( BufferIndex bufferIndex )
397 ComputeTransformComponent();
402 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
404 const Vector3& Get( BufferIndex bufferIndex ) const
406 ComputeTransformComponent();
411 * Retrieve the property value.
412 * @param[in] bufferIndex The buffer to read.
413 * @return The property value.
415 const Vector3& operator[]( BufferIndex bufferIndex ) const
417 ComputeTransformComponent();
422 * Initializes the property
423 * @param[in] transformManager Pointer to the transform manager
424 * @param[in] Id of the transformation the property is associated with
426 void Initialize( TransformManager* transformManager, TransformId id )
428 mTxManager = transformManager;
433 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
435 bool IsTransformManagerProperty() const override
443 TransformManagerVector3Input(const TransformManagerVector3Input& property);
446 TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
450 TransformManager* mTxManager;
452 TransformManagerProperty mProperty;
453 mutable Vector3 mValue;
457 * A Quaternion property used as input.
459 class TransformManagerQuaternionInput : public PropertyInputImpl
466 TransformManagerQuaternionInput()
467 :mTxManager(nullptr),
468 mId(INVALID_TRANSFORM_ID),
469 mValue(1.0f,0.0f,0.0f,0.0f)
474 * Virtual destructor.
476 ~TransformManagerQuaternionInput() override
481 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
483 Dali::Property::Type GetType() const override
485 return Dali::PropertyTypes::Get<Quaternion>();
489 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
491 virtual bool IsClean() const
497 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
499 bool InputInitialized() const override
505 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
506 * @note A constraint can only receive the inherited property from the previous frame.
508 bool InputChanged() const override
514 * Helper function to get the orientation out of the world matrix.
515 * It stores the result in the mValue member variable
517 void ComputeTransformComponent() const
521 const Matrix& worldMatrix = mTxManager->GetWorldMatrix(mId);
522 Vector3 position, scale;
523 worldMatrix.GetTransformComponents(position, mValue, scale);
528 * @copydoc Dali::PropertyInput::GetQuaternion()
530 const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const override
532 ComputeTransformComponent();
537 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
539 const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const override
541 ComputeTransformComponent();
546 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
548 Quaternion& Get( BufferIndex bufferIndex )
550 ComputeTransformComponent();
555 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
557 const Quaternion& Get( BufferIndex bufferIndex ) const
559 ComputeTransformComponent();
564 * Retrieve the property value.
565 * @param[in] bufferIndex The buffer to read.
566 * @return The property value.
568 const Quaternion& operator[]( BufferIndex bufferIndex) const
570 ComputeTransformComponent();
575 * Initializes the property
576 * @param[in] transformManager Pointer to the transform manager
577 * @param[in] Id of the transformation the property is associated with
579 void Initialize( TransformManager* transformManager, TransformId id )
581 mTxManager = transformManager;
586 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
588 bool IsTransformManagerProperty() const override
596 TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
599 TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
603 TransformManager* mTxManager;
605 mutable Quaternion mValue;
609 * A Matrix property used as input.
611 class TransformManagerMatrixInput : public PropertyInputImpl
618 TransformManagerMatrixInput()
619 :mTxManager(nullptr),
620 mId(INVALID_TRANSFORM_ID)
625 * Virtual destructor.
627 ~TransformManagerMatrixInput() override
632 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
634 Dali::Property::Type GetType() const override
636 return Dali::PropertyTypes::Get<Matrix>();
640 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
642 virtual bool IsClean() const
648 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
650 bool InputInitialized() const override
656 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
657 * @note A constraint can only receive the inherited property from the previous frame.
659 bool InputChanged() const override
665 * @copydoc Dali::PropertyInput::GetMatrix()
667 const Matrix& GetMatrix( BufferIndex bufferIndex ) const override
671 return mTxManager->GetWorldMatrix(mId);
674 return Matrix::IDENTITY;
678 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
680 const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const override
684 return mTxManager->GetWorldMatrix(mId);
687 return Matrix::IDENTITY;
691 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
693 Matrix& Get( BufferIndex bufferIndex )
695 DALI_ASSERT_ALWAYS( mTxManager != nullptr );
696 return mTxManager->GetWorldMatrix(mId);
700 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
702 const Matrix& Get( BufferIndex bufferIndex ) const
704 return GetMatrix( bufferIndex );
708 * Retrieve the property value.
709 * @param[in] bufferIndex The buffer to read.
710 * @return The property value.
712 const Matrix& operator[]( BufferIndex bufferIndex ) const
714 return GetMatrix( bufferIndex );
717 void Initialize( TransformManager* transformManager, TransformId id )
719 mTxManager = transformManager;
724 * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
726 bool IsTransformManagerProperty() const override
734 TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
737 TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
741 TransformManager* mTxManager;
746 } //namespace SceneGraph
747 } //namespace Internal
750 #endif // TRANSFORM_MANAGER_PROPERTY_H_