[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / internal / physics-actor-impl.h
1 #ifndef DALI_TOOLKIT_PHYSICS_INTERNAL_ACTOR_H
2 #define DALI_TOOLKIT_PHYSICS_INTERNAL_ACTOR_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/object/any.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-physics/public-api/physics-actor.h>
27 #include <dali-toolkit/public-api/dali-toolkit-common.h>
28
29 namespace Dali::Toolkit::Physics
30 {
31 namespace Internal
32 {
33 class PhysicsActor;
34 class PhysicsAdaptor;
35
36 using PhysicsActorPtr = Dali::IntrusivePtr<PhysicsActor>;
37
38 class PhysicsActor : public Dali::BaseObject
39 {
40 public:
41   PhysicsActor(Dali::Actor actor, Dali::Any body, PhysicsAdaptor& adaptor);
42   ~PhysicsActor() override;
43   PhysicsActor(const PhysicsActor& handle) = delete;
44   PhysicsActor& operator=(const PhysicsActor& handle) = delete;
45
46   /**
47    * @copydoc Dali::Toolkit::Physics::PhysicsActor::New()
48    */
49   static PhysicsActorPtr New(Dali::Actor actor, Dali::Any body, PhysicsAdaptor& adaptor);
50
51   void Initialize(void);
52
53   /**
54    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetId
55    */
56   uint32_t GetId() const
57   {
58     return mActorId;
59   }
60
61   /**
62    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetBody
63    */
64   Dali::Any GetBody() const
65   {
66     return mBody;
67   }
68
69   /**
70    * @copydoc Dali::Toolkit::Physics::PhysicsActor::AsyncSetPhysicsPosition
71    */
72   void AsyncSetPhysicsPosition(Dali::Vector3 actorPosition);
73
74   /**
75    * @copydoc Dali::Toolkit::Physics::PhysicsActor::AsyncSetPhysicsRotation
76    */
77   void AsyncSetPhysicsRotation(Dali::Quaternion actorRotation);
78
79   /**
80    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetPhysicsPosition
81    */
82   Dali::Vector3 GetPhysicsPosition() const;
83
84   /**
85    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetPhysicsRotation
86    */
87   Dali::Quaternion GetPhysicsRotation() const;
88
89   /**
90    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetActorPosition
91    */
92   Dali::Vector3 GetActorPosition() const;
93
94   /**
95    * @copydoc Dali::Toolkit::Physics::PhysicsActor::GetActorRotation
96    */
97   Dali::Quaternion GetActorRotation() const;
98
99 private:
100   PhysicsAdaptor& mAdaptor;
101   uint32_t        mActorId{0};
102   Dali::Any       mBody;
103 };
104
105 } // namespace Internal
106
107 inline Internal::PhysicsActor& GetImplementation(Physics::PhysicsActor& physics)
108 {
109   DALI_ASSERT_ALWAYS(physics && "Physics actor handle is empty");
110   BaseObject& handle = physics.GetBaseObject();
111   return static_cast<Internal::PhysicsActor&>(handle);
112 }
113
114 inline const Internal::PhysicsActor& GetImplementation(const Physics::PhysicsActor& physics)
115 {
116   DALI_ASSERT_ALWAYS(physics && "Physics actor handle is empty");
117   const BaseObject& handle = physics.GetBaseObject();
118   return static_cast<const Internal::PhysicsActor&>(handle);
119 }
120
121 } // namespace Dali::Toolkit::Physics
122
123 #endif //DALI_TOOLKIT_PHYSICS_INTERNAL_ACTOR_H