UTC public API updates: stage.h
[platform/core/uifw/dali-core.git] / dali / devel-api / dynamics / dynamics-world.h
1 #ifndef __DALI_DYNAMICS_WORLD_H__
2 #define __DALI_DYNAMICS_WORLD_H__
3
4 /*
5  * Copyright (c) 2015 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
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // BASE CLASS INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/dynamics/dynamics-world-config.h>
29 #include <dali/public-api/signals/dali-signal.h>
30
31 namespace Dali
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class DynamicsWorld;
37 } // namespace Internal
38
39 class Actor;
40 class DynamicsBody;
41 class DynamicsCollision;
42 class DynamicsJoint;
43 class DynamicsShape;
44
45 /**
46  * @brief DynamicsWorld gives the application developer an alternative method of moving and rotating.
47  * actors in the DALi scene.
48  *
49  * Actors are represented by DynamicsBody objects in the dynamics simulation and are moved by
50  * forces (eg gravity). Dynamics also allows collisions between objects to be
51  * detected and responded to in signal handlers.
52  *
53  * DALi will update the physics simulation after animations and constraints, thus dynamics forces
54  * will override positions and orientations applied by animations and constrints.
55  *
56  * Here is an example illustrating the basic steps to initialise the simulation and
57  * add a rigid body.
58  *
59  * @code
60  * // Initialize and get a handle to the Dali::DynamicsWorld
61  * Dali::DynamicsWorldConfig worldConfig( Dali::DynamicsWorldConfig::New() );
62  * Dali::DynamicsWorld dynamicsWorld( Dali::Stage::GetCurrent().InitializeDynamics( worldConfig ) );
63  *
64  * // Create an actor to represent the world and act as a parent to DynamicsBody instances
65  * Dali::Actor dynamicsRootActor( Dali::Actor::New() );
66  * dynamicsRootActor.SetParentOrigin( Dali::ParentOrigin::CENTER );
67  * dynamicsWorld.SetRootActor( dynamicsRootActor );
68  * Dali::Stage::GetCurrent().Add( dynamicsRootActor );
69  *
70  * // create an actor to represent a rigid body
71  * Dali::Actor actor( Dali::Actor::New() );
72  * actor.SetParentOrigin( Dali::ParentOrigin::CENTER );
73  *
74  * // Enable dynamics for the actor, creating a rigid body with default configuration
75  * actor.EnableDynamics( Dali::DynamicsBodyConfig::New() );
76  *
77  * // Add the actor to the scene
78  * dynamicsRootActor.Add( actor );
79  * @endcode
80  *
81  * Signals
82  * | %Signal Name              | Method                     |
83  * |---------------------------|----------------------------|
84  * | collision                 | @ref CollisionSignal()     |
85  */
86 class DALI_IMPORT_API DynamicsWorld : public BaseHandle
87 {
88 public:
89
90   // signals
91   typedef Signal< void ( DynamicsWorld, const DynamicsCollision ) > CollisionSignalType; ///< Type of collision signal
92
93 public:
94   /**
95    * @brief Debug modes
96    */
97   enum  DEBUG_MODES
98   {
99     DEBUG_MODE_NONE               = 0,
100     DEBUG_MODE_WIREFRAME          = (1<<0),
101     DEBUG_MODE_FAST_WIREFRAME     = (1<<1),
102     DEBUG_MODE_AABB               = (1<<2),
103     DEBUG_MODE_CONTACT_POINTS     = (1<<3),
104     DEBUG_MODE_NO_DEACTIVATION    = (1<<4),
105     DEBUG_MODE_CONSTRAINTS        = (1<<5),
106     DEBUG_MODE_CONSTRAINTS_LIMITS = (1<<6),
107     DEBUG_MODES_NORMALS           = (1<<7),
108   };
109
110 public:
111   /**
112    * @brief Create an uninitialized DynamicsWorld handle.
113    */
114   DynamicsWorld();
115
116   /**
117    * @brief Destructor
118    *
119    * This is non-virtual since derived Handle types must not contain data or virtual methods.
120    */
121   ~DynamicsWorld();
122
123   /**
124    * @brief This copy constructor is required for (smart) pointer semantics.
125    *
126    * @param [in] handle A reference to the copied handle
127    */
128   DynamicsWorld(const DynamicsWorld& handle);
129
130   /**
131    * @brief This assignment operator is required for (smart) pointer semantics.
132    *
133    * @param [in] rhs  A reference to the copied handle
134    * @return A reference to this
135    */
136   DynamicsWorld& operator=(const DynamicsWorld& rhs);
137
138   /**
139    * @brief Static / singleton creator and getter.
140    * Initialise the Dynamics simulation and create a DynamicsWorld object.
141    *
142    * Only one instance of DynamicsWorld will be created, so calling this method multiple times
143    * will return the same DynamicsWorld object.
144    *
145    * If an instance already exists, it is returned regardless of configuration being passed in.
146    *
147    * @param[in] configuration A DynamicsWorldConfig object describing the required capabilities of the dynamics world.
148    * @return A handle to the world object of the dynamics simulation, or an empty handle if Dynamics is not capable
149    *         of supporting a requirement in the configuration as it is not available on the platform.
150    */
151   static DynamicsWorld GetInstance( DynamicsWorldConfig configuration );
152
153   /**
154    * @brief Static / singleton getter.
155    * Get a handle to the world object of the dynamics simulation.
156    *
157    * Does not create an instance, use only if the instance is known to exist.
158    *
159    * @return A pointer to the dynamics world if it is installed.
160    */
161   static DynamicsWorld Get();
162
163   /**
164    * @brief Static instance cleanup.
165    * Terminate the dynamics simulation.
166    *
167    * Calls Actor::DisableDynamics on all dynamics enabled actors,
168    * all handles to any DynamicsBody or DynamicsJoint objects held by applications
169    * will become detached from their actors and the simulation therefore should be discarded.
170    */
171   static void DestroyInstance();
172
173 // Methods that modify the simulation
174 public:
175
176   /**
177    * @brief Set the gravity for the world.
178    *
179    * @param[in] gravity a Vector3 specifying the applicable gravity for the world.
180    */
181   void SetGravity( const Vector3& gravity );
182
183   /**
184    * @brief Get the gravity for the world.
185    *
186    * @return A Vector3 specifying the gravity that will be applied in the world.
187    */
188   const Vector3& GetGravity() const;
189
190   /**
191    * @brief Get the current debug drawmode.
192    *
193    * @return A combination of the flags in DEBUG_MODES or 0 if debug drawing is currently disabled.
194    */
195   int GetDebugDrawMode() const;
196
197   /**
198    * @brief Set the debug drawmode for the simulation.
199    *
200    * @param[in] mode A combination of the flags in DEBUG_MODES or 0 to disable debug drawing
201    */
202   void SetDebugDrawMode(int mode);
203
204   /**
205    * @brief Set the actor which will represent the dynamics world.
206    *
207    * All actors that will participate in the dynamics simulation must be direct children of this actor
208    * @param[in] actor The root actor for the dynamics simulation
209    */
210   void SetRootActor(Actor actor);
211
212   /**
213    * @brief Get the root actor for the simulation.
214    *
215    * @return The root actor for the dynamics simulation
216    */
217   Actor GetRootActor() const;
218
219 public: // Signals
220
221   /**
222    * @brief This signal is emitted when a collision is detected between two DynamicsBodies.
223    *
224    * A callback of the following type may be connected:
225    * @code
226    *   void YourCollisionHandler(Dali::DynamicsWorld world, const Dali::DynamicsCollision collisionData);
227    * @endcode
228    *
229    * @return The signal to connect to.
230    */
231   CollisionSignalType& CollisionSignal();
232
233 public: // Not intended for application developers
234
235   /**
236    * @brief This constructor is used internally by Dali.
237    *
238    * @param [in] internal A pointer to a newly allocated Dali resource
239    */
240   explicit DALI_INTERNAL DynamicsWorld( Internal::DynamicsWorld* internal );
241 };
242
243 } // namespace Dali
244
245 #endif // __DALI_DYNAMICS_WORLD_H__