[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / integration-api / physics-world.h
1 #pragma once
2
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include <dali-toolkit/public-api/dali-toolkit-common.h>
19 #include <dali/public-api/math/vector3.h>
20 #include <dali/public-api/object/any.h>
21
22 namespace Dali::Toolkit::Physics::Internal
23 {
24 class PhysicsWorld;
25 }
26
27 namespace Dali::Toolkit::Physics::Integration
28 {
29 /** Proxy to the physics world impl.
30  *
31  * Does NOT own physics world.
32  * Copyable. Doesn't track lock.
33  */
34 class DALI_TOOLKIT_API PhysicsWorld
35 {
36 public:
37   /**
38    * Constructor
39    * @param[in] impl The physics world implementation class.
40    */
41   PhysicsWorld(Dali::Toolkit::Physics::Internal::PhysicsWorld* impl);
42
43   /**
44    * Destructor.
45    * Does not destroy the physic world.
46    */
47   ~PhysicsWorld();
48
49   /**
50    * Copy Constructor
51    */
52   PhysicsWorld(const PhysicsWorld& rhs) = default;
53
54   /**
55    * Assignment operator
56    */
57   PhysicsWorld& operator=(const PhysicsWorld& rhs) = default;
58
59   /**
60    * Lock the physics world. The caller MUST unlock it afterwards, otherwise
61    * the physics integration step will block, and DALi update thread will be locked.
62    */
63   void Lock();
64
65   /**
66    * Unlock the physics world.
67    */
68   void Unlock();
69
70   /**
71    * Get a handle to the native physics world / space
72    *
73    * This API should be wrapped with Lock/Unlock in any interop implementation
74    * @return a pointer to the native world.
75    */
76   Dali::Any GetNative();
77
78   /**
79    * Hit test the physics world.
80    *
81    * This API should be wrapped with Lock/Unlock in any interop implementation
82    * @param[in] rayFromWorld The origin in physics world space
83    * @param[in] rayToWorld A point along the direction on the far side of the physics world
84    * @param[in] nativeFilter a native body / shape filter
85    * @param[out] localPivot The hit point local to the body
86    * @param[out] distanceFromCamera The distance of the pick point from the camera
87    * @return Either a pointer to the native body, or an empty value.
88    */
89   Dali::Any HitTest(Dali::Vector3 rayFromWorld, Dali::Vector3 rayToWorld, Dali::Any nativeFilter, Dali::Vector3& localPivot, float& distanceFromCamera);
90
91   /**
92    * Get the implementation pointer.
93    *
94    * @return the implementation pointer.
95    */
96   Dali::Toolkit::Physics::Internal::PhysicsWorld* GetImpl();
97
98 private:
99   Dali::Toolkit::Physics::Internal::PhysicsWorld* impl;
100 };
101
102 } // namespace Dali::Toolkit::Physics::Integration