X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fmanager%2Ftransform-manager.h;h=97294e27a6bee3bdf20b43ef32a9a66ec0d90897;hb=538d808523cf7cdb8dc37e10d60aa4fce636fb24;hp=445b1034f6e43326ab59c1e8c705861108024d46;hpb=2f99fe6e68e7b8f01e40a505501c3529f0511a3b;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/manager/transform-manager.h b/dali/internal/update/manager/transform-manager.h index 445b103..97294e2 100644 --- a/dali/internal/update/manager/transform-manager.h +++ b/dali/internal/update/manager/transform-manager.h @@ -1,9 +1,8 @@ - -#ifndef TRANSFORM_MANAGER_H_ -#define TRANSFORM_MANAGER_H_ +#ifndef DALI_INTERNAL_TRANSFORM_MANAGER_H +#define DALI_INTERNAL_TRANSFORM_MANAGER_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,35 +19,34 @@ */ // INTERNAL INCLUDES +#include +#include #include #include #include #include -#include namespace Dali { - namespace Internal { - namespace SceneGraph { - /** * Struct to store the animatable part of a component (Scale, orientation and position) */ struct TransformComponentAnimatable { TransformComponentAnimatable() - :mScale(1.0f,1.0f,1.0f), - mOrientation(1.0f,0.0f,0.0f,0.0f), - mPosition(0.0f,0.0f,0.0f) - {} + : mScale(Vector3::ONE), + mOrientation(Quaternion::IDENTITY), + mPosition(Vector3::ZERO) + { + } - Vector3 mScale; + Vector3 mScale; Quaternion mOrientation; - Vector3 mPosition; + Vector3 mPosition; }; /** @@ -57,21 +55,24 @@ struct TransformComponentAnimatable struct TransformComponentStatic { TransformComponentStatic() - :mAnchorPoint(0.5f,0.5f,0.5f), - mParentOrigin(0.0f,0.0f,0.5f) - {} + : mAnchorPoint(AnchorPoint::DEFAULT), + mParentOrigin(ParentOrigin::DEFAULT), + mPositionUsesAnchorPoint(true) + { + } Vector3 mAnchorPoint; Vector3 mParentOrigin; + bool mPositionUsesAnchorPoint; }; enum InheritanceMode { - DONT_INHERIT_TRANSFORM = 0, - INHERIT_POSITION = 1, - INHERIT_SCALE = 2, - INHERIT_ORIENTATION = 4, - INHERIT_ALL = INHERIT_POSITION | INHERIT_SCALE | INHERIT_ORIENTATION, + DONT_INHERIT_TRANSFORM = 0, + INHERIT_POSITION = 1, + INHERIT_SCALE = 2, + INHERIT_ORIENTATION = 4, + INHERIT_ALL = INHERIT_POSITION | INHERIT_SCALE | INHERIT_ORIENTATION, }; enum TransformManagerProperty @@ -88,21 +89,44 @@ enum TransformManagerProperty TRANSFORM_PROPERTY_COUNT, }; -typedef unsigned int TransformId; +using TransformId = uint32_t; // 4,294,967,295 transforms supported static const TransformId INVALID_TRANSFORM_ID = -1; -} //SceneGraph -} //Internal +class TransformManager; + +struct TransformManagerData +{ + TransformManager* Manager() const + { + return mManager; + } + + TransformId Id() const + { + return mId; + } + + TransformManager* mManager{nullptr}; + TransformId mId{INVALID_TRANSFORM_ID}; +}; + +} // namespace SceneGraph +} // namespace Internal // Allow TransformComponentAnimatable to be treated as a POD type -template <> struct TypeTraits< Dali::Internal::SceneGraph::TransformComponentAnimatable >: public Dali::BasicTypes< Dali::Internal::SceneGraph::TransformComponentAnimatable > { enum { IS_TRIVIAL_TYPE = true }; }; +template<> +struct TypeTraits : public Dali::BasicTypes +{ + enum + { + IS_TRIVIAL_TYPE = true + }; +}; namespace Internal { - namespace SceneGraph { - /** * Transform manager computes the local to world transformations * of all the nodes in the scene. All the transformation data is stored contiguously @@ -111,7 +135,6 @@ namespace SceneGraph class TransformManager { public: - /** * Default constructor */ @@ -139,28 +162,28 @@ public: * @param[in] id Id of the transform * @param[in] parentId Id of the new parent */ - void SetParent( TransformId id, TransformId parentId ); + void SetParent(TransformId id, TransformId parentId); /** * Gets the world transform matrix of an exisiting transform component * @param[in] id Id of the transform component * @return The local to world transformation matrix of the component */ - const Matrix& GetWorldMatrix( TransformId id ) const; + const Matrix& GetWorldMatrix(TransformId id) const; /** * Gets the world transform matrix of an exisiting transform component * @param[in] id Id of the transform component * @return The local to world transformation matrix of the component */ - Matrix& GetWorldMatrix( TransformId id ); + Matrix& GetWorldMatrix(TransformId id); /** * Checks if the local transform was updated in the last Update * @param[in] id Id of the transform * @return true if local matrix changed in the last update, false otherwise */ - bool IsLocalMatrixDirty( TransformId id ) const + bool IsLocalMatrixDirty(TransformId id) const { return mLocalMatrixDirty[mIds[id]]; } @@ -170,26 +193,27 @@ public: * @param[in] id Id of the transform * @param[in] inherit True if position is inherited from parent, false otherwise */ - void SetInheritPosition( TransformId id, bool inherit ); + void SetInheritPosition(TransformId id, bool inherit); /** * Sets scale inheritance mode. * @param[in] id Id of the transform * @param[in] inherit True if scale is inherited from parent, false otherwise */ - void SetInheritScale( TransformId id, bool inherit ); + void SetInheritScale(TransformId id, bool inherit); /** * Sets orientation inheritance mode. * @param[in] id Id of the transform * @param[in] inherit True if orientation is inherited from parent, false otherwise */ - void SetInheritOrientation( TransformId id, bool inherit ); + void SetInheritOrientation(TransformId id, bool inherit); /** * Recomputes all world transform matrices + * @return true if any component has been changed in this frame, false otherwise */ - void Update(); + bool Update(); /** * Resets all the animatable properties to its base value @@ -201,14 +225,14 @@ public: * @param[in] id Id of the transform component * @param[in] property The property */ - Vector3& GetVector3PropertyValue( TransformId id, TransformManagerProperty property ); + Vector3& GetVector3PropertyValue(TransformId id, TransformManagerProperty property); /** * Get the value of a Vector3 property * @param[in] id Id of the transform component * @param[in] property The property */ - const Vector3& GetVector3PropertyValue( TransformId id, TransformManagerProperty property ) const; + const Vector3& GetVector3PropertyValue(TransformId id, TransformManagerProperty property) const; /** * Get the value of a component of Vector3 property @@ -216,7 +240,7 @@ public: * @param[in] property The property * param[in] component The component (0,1,2) */ - const float& GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, unsigned int component ) const; + const float& GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, uint32_t component) const; /** * Set the value of a Vector3 property @@ -224,7 +248,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void SetVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value ); + void SetVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value); /** * Set the value of a component of a Vector3 property @@ -233,7 +257,7 @@ public: * @param[in] value The new value * param[in] component The component (0,1,2) */ - void SetVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component ); + void SetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, float value, uint32_t component); /** * Bakes the value of a Vector3 property @@ -241,7 +265,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value ); + void BakeVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value); /** * Bakes the value of a Vector3 property relative to the current value @@ -249,7 +273,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeRelativeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value ); + void BakeRelativeVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value); /** * Bakes the value of a Vector3 property by multiplying the current value and the new value @@ -257,7 +281,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeMultiplyVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value ); + void BakeMultiplyVector3PropertyValue(TransformId id, TransformManagerProperty property, const Vector3& value); /** * Bakes the value of a component of Vector3 property @@ -265,7 +289,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component ); + void BakeVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, float value, uint32_t component); /** * Bakes the value of the x component of Vector3 property @@ -273,7 +297,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeXVector3PropertyValue( TransformId id, TransformManagerProperty property, float value ); + void BakeXVector3PropertyValue(TransformId id, TransformManagerProperty property, float value); /** * Bakes the value of the y component of Vector3 property @@ -281,7 +305,7 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeYVector3PropertyValue( TransformId id, TransformManagerProperty property, float value ); + void BakeYVector3PropertyValue(TransformId id, TransformManagerProperty property, float value); /** * Bakes the value of the z component of Vector3 property @@ -289,50 +313,82 @@ public: * @param[in] property The property * @param[in] value The new value */ - void BakeZVector3PropertyValue( TransformId id, TransformManagerProperty property, float value ); + void BakeZVector3PropertyValue(TransformId id, TransformManagerProperty property, float value); /** * Get the value of a quaternion property * @param[in] id Id of the transform component */ - Quaternion& GetQuaternionPropertyValue( TransformId id ); + Quaternion& GetQuaternionPropertyValue(TransformId id); /** * Get the value of a quaternion property * @param[in] id Id of the transform component */ - const Quaternion& GetQuaternionPropertyValue( TransformId id ) const; + const Quaternion& GetQuaternionPropertyValue(TransformId id) const; /** * Set the value of a quaternion property * @param[in] id Id of the transform component * @param[in] q The new value */ - void SetQuaternionPropertyValue( TransformId id, const Quaternion& q ); + void SetQuaternionPropertyValue(TransformId id, const Quaternion& q); /** * Bake the value of a quaternion property * @param[in] id Id of the transform component * @param[in] q The new value */ - void BakeQuaternionPropertyValue( TransformId id, const Quaternion& q ); + void BakeQuaternionPropertyValue(TransformId id, const Quaternion& q); /** * Bake the value of a quaternion property relative to its current value * @param[in] id Id of the transform component * @param[in] q The new value */ - void BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q ); + void BakeRelativeQuaternionPropertyValue(TransformId id, const Quaternion& q); -private: + /** + * Get the bounding sphere, in world coordinates, of a given component + * @param[in] id Id of the transform component + * @return The world space bounding sphere of the component + */ + const Vector4& GetBoundingSphere(TransformId id) const; + /** + * Get the world matrix and size of a given component + * @param[in] id Id of the transform component + * @param[out] The world matrix of the component + * @param[out] size size of the component + */ + void GetWorldMatrixAndSize(TransformId id, Matrix& worldMatrix, Vector3& size) const; + + /** + * @brief Sets the boolean which states whether the position should use the anchor-point on the given transform component. + * @param[in] id Id of the transform component + * @param[in] value True if the position should use the anchor-point + */ + void SetPositionUsesAnchorPoint(TransformId id, bool value); + +private: //Helper struct to order components struct SOrderItem { - bool operator<(const SOrderItem& item) const {return level < item.level;} - - TransformId id; - unsigned int level; + bool operator<(const SOrderItem& item) const + { + if(sceneId != item.sceneId) + { + return sceneId < item.sceneId; + } + else + { + return level < item.level; + } + } + + TransformId id; + uint16_t sceneId; + uint16_t level; }; /** @@ -340,39 +396,38 @@ private: * @param[in] i Index of a component * @param[in] j Index of a component */ - void SwapComponents( unsigned int i, unsigned int j ); + void SwapComponents(uint32_t i, uint32_t j); /** * Reorders components in hierarchical order so update can iterate sequentially - * updating the world transforms + * updating the world transforms. The components are sorted in the breadth first + * order for each scene and grouped per scene. */ void ReorderComponents(); - unsigned int mComponentCount; ///< Total number of components - FreeList mIds; ///< FreeList of Ids - Vector mTxComponentAnimatable; ///< Animatable part of the components - Vector mTxComponentStatic; ///< Static part of the components - Vector mInheritanceMode; ///< Inheritance mode of the components - Vector mComponentId; ///< Ids of the components - Vector mSize; ///< Size of the components - Vector mParent; ///< Parent of the components - Vector mWorld; ///< Local to world transform of the components - Vector mLocal; ///< Local to parent space transform of the components - Vector mTxComponentAnimatableBaseValue; ///< Base values for the animatable part of the components - Vector mSizeBase; ///< Base value for the size of the components - Vector mComponentDirty; ///< 1u if some of the parts of the component has changed in this frame, 0 otherwise - Vector mLocalMatrixDirty; ///< 1u if the local matrix has been updated in this frame, 0 otherwise - Vector mOrderedComponents; ///< Used to reorder components when hierarchy changes - bool mReorder; ///< Flag to determine if the components have to reordered in the next Update - + uint32_t mComponentCount; ///< Total number of components + FreeList mIds; ///< FreeList of Ids + Vector mTxComponentAnimatable; ///< Animatable part of the components + Vector mTxComponentStatic; ///< Static part of the components + Vector mInheritanceMode; ///< Inheritance mode of the components + Vector mComponentId; ///< Ids of the components + Vector mSize; ///< Size of the components + Vector mParent; ///< Parent of the components + Vector mWorld; ///< Local to world transform of the components + Vector mLocal; ///< Local to parent space transform of the components + Vector mBoundingSpheres; ///< Bounding spheres. xyz is the center and w is the radius + Vector mTxComponentAnimatableBaseValue; ///< Base values for the animatable part of the components + Vector mSizeBase; ///< Base value for the size of the components + Vector mComponentDirty; ///< 1u if some of the parts of the component has changed in this frame, 0 otherwise + Vector mLocalMatrixDirty; ///< 1u if the local matrix has been updated in this frame, 0 otherwise + Vector mOrderedComponents; ///< Used to reorder components when hierarchy changes + bool mReorder; ///< Flag to determine if the components have to reordered in the next Update }; } //namespace SceneGraph } //namespace Internal - } //namespace Dali - -#endif /* TRANSFORM_MANAGER_H_ */ +#endif // DALI_INTERNAL_TRANSFORM_MANAGER_H