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 virtual Dali::Property::Type GetType() const = 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 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(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 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( BufferIndex bufferIndex )
168 return mTxManager->GetVector3PropertyValue( mId, mProperty );
171 const Vector3& Get( BufferIndex bufferIndex ) const
173 return mTxManager->GetVector3PropertyValue( mId, mProperty );
176 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
178 return Get(bufferIndex);
181 const float& GetFloatComponent( uint32_t 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, 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)
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, uint32_t component)
223 mTxManager->SetVector3PropertyComponentValue( mId, mProperty, value, component);
226 void BakeFloatComponent( float value, uint32_t 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( BufferIndex bufferIndex )
259 return mTxManager->GetQuaternionPropertyValue( mId );
262 const Quaternion& Get( BufferIndex bufferIndex ) const
264 return mTxManager->GetQuaternionPropertyValue( mId );
267 const float& GetFloatComponent( uint32_t 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 );
287 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
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 )
306 mId(INVALID_TRANSFORM_ID),
312 * Virtual destructor.
314 virtual ~TransformManagerVector3Input()
319 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
321 virtual Dali::Property::Type GetType() const
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 virtual bool InputInitialized() const
343 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
344 * @note A constraint can only receive the inherited property from the previous frame.
346 virtual bool InputChanged() const
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 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
379 ComputeTransformComponent();
384 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
386 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
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 virtual bool IsTransformManagerProperty() const
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()
468 mId(INVALID_TRANSFORM_ID),
469 mValue(1.0f,0.0f,0.0f,0.0f)
474 * Virtual destructor.
476 virtual ~TransformManagerQuaternionInput()
481 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
483 virtual Dali::Property::Type GetType() const
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 virtual bool InputInitialized() const
505 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
506 * @note A constraint can only receive the inherited property from the previous frame.
508 virtual bool InputChanged() const
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 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
532 ComputeTransformComponent();
537 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
539 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
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 virtual bool IsTransformManagerProperty() const
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()
620 mId(INVALID_TRANSFORM_ID)
625 * Virtual destructor.
627 virtual ~TransformManagerMatrixInput()
632 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
634 virtual Dali::Property::Type GetType() const
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 virtual bool InputInitialized() const
656 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
657 * @note A constraint can only receive the inherited property from the previous frame.
659 virtual bool InputChanged() const
665 * @copydoc Dali::PropertyInput::GetMatrix()
667 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
671 return mTxManager->GetWorldMatrix(mId);
674 return Matrix::IDENTITY;
678 * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
680 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
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 != 0 );
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 virtual bool IsTransformManagerProperty() const
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_