Updated non-capi public API documentation to new style.
[platform/core/uifw/dali-core.git] / dali / public-api / dynamics / dynamics-world.h
1 #ifndef __DALI_DYNAMICS_WORLD_H__
2 #define __DALI_DYNAMICS_WORLD_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 <string>
22
23 // BASE CLASS INCLUDES
24 #include <dali/public-api/object/base-handle.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/signals/dali-signal-v2.h>
28
29 namespace Dali DALI_IMPORT_API
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34 class DynamicsWorld;
35 } // namespace Internal
36
37 class Actor;
38 class DynamicsBody;
39 class DynamicsCollision;
40 class DynamicsJoint;
41 class DynamicsShape;
42
43 /**
44  * @brief DynamicsWorld gives the application developer an alternative method of moving and rotating.
45  * actors in the DALi scene.
46  *
47  * Actors are represented by DynamicsBody objects in the dynamics simulation and are moved by
48  * forces (eg gravity). Dynamics also allows collisions between objects to be
49  * detected and responded to in signal handlers.
50  *
51  * DALi will update the physics simulation after animations and constraints, thus dynamics forces
52  * will override positions and rotations applied by animations and constrints.
53  *
54  * Here is an example illustrating the basic steps to initialise the simulation and
55  * add a rigid body.
56  *
57  * @code
58  * // Initialize and get a handle to the Dali::DynamicsWorld
59  * Dali::DynamicsWorldConfig worldConfig( Dali::DynamicsWorldConfig::New() );
60  * Dali::DynamicsWorld dynamicsWorld( Dali::Stage::GetCurrent().InitializeDynamics( worldConfig ) );
61  *
62  * // Create an actor to represent the world and act as a parent to DynamicsBody instances
63  * Dali::Actor dynamicsRootActor( Dali::Actor::New() );
64  * dynamicsRootActor.SetParentOrigin( Dali::ParentOrigin::CENTER );
65  * dynamicsWorld.SetRootActor( dynamicsRootActor );
66  * Dali::Stage::GetCurrent().Add( dynamicsRootActor );
67  *
68  * // create an actor to represent a rigid body
69  * Dali::Actor actor( Dali::Actor::New() );
70  * actor.SetParentOrigin( Dali::ParentOrigin::CENTER );
71  *
72  * // Enable dynamics for the actor, creating a rigid body with default configuration
73  * actor.EnableDynamics( Dali::DynamicsBodyConfig::New() );
74  *
75  * // Add the actor to the scene
76  * dynamicsRootActor.Add( actor );
77  * @endcode
78  */
79 class DynamicsWorld : public BaseHandle
80 {
81 public:
82
83   // Signal Names
84   static const char* const SIGNAL_COLLISION; ///< name "collision"
85
86   // signals
87   typedef SignalV2< void (DynamicsWorld, const DynamicsCollision) > CollisionSignalV2; ///< Type of collision signal
88
89 public:
90   /**
91    * @brief Debug modes
92    */
93   enum  DEBUG_MODES
94   {
95     DEBUG_MODE_NONE               = 0,
96     DEBUG_MODE_WIREFRAME          = (1<<0),
97     DEBUG_MODE_FAST_WIREFRAME     = (1<<1),
98     DEBUG_MODE_AABB               = (1<<2),
99     DEBUG_MODE_CONTACT_POINTS     = (1<<3),
100     DEBUG_MODE_NO_DEACTIVATION    = (1<<4),
101     DEBUG_MODE_CONSTRAINTS        = (1<<5),
102     DEBUG_MODE_CONSTRAINTS_LIMITS = (1<<6),
103     DEBUG_MODES_NORMALS           = (1<<7),
104   };
105
106 public:
107   /**
108    * @brief Create an uninitialized DynamicsWorld handle.
109    */
110   DynamicsWorld();
111
112   /**
113    * @brief Virtual destructor.
114    */
115   virtual ~DynamicsWorld();
116
117   /**
118    * @copydoc Dali::BaseHandle::operator=
119    */
120   using BaseHandle::operator=;
121
122 // Methods that modify the simulation
123 public:
124
125   /**
126    * @brief Set the gravity for the world.
127    *
128    * @param[in] gravity a Vector3 specifying the applicable gravity for the world.
129    */
130   void SetGravity( const Vector3& gravity );
131
132   /**
133    * @brief Get the gravity for the world.
134    *
135    * @return A Vector3 specifying the gravity that will be applied in the world.
136    */
137   const Vector3& GetGravity() const;
138
139   /**
140    * @brief Get the current debug drawmode.
141    *
142    * @return A combination of the flags in DEBUG_MODES or 0 if debug drawing is currently disabled.
143    */
144   int GetDebugDrawMode() const;
145
146   /**
147    * @brief Set the debug drawmode for the simulation.
148    *
149    * @param[in] mode A combination of the flags in DEBUG_MODES or 0 to disable debug drawing
150    */
151   void SetDebugDrawMode(const int mode);
152
153   /**
154    * @brief Set the actor which will represent the dynamics world.
155    *
156    * All actors that will participate in the dynamics simulation must be direct children of this actor
157    * @param[in] actor The root actor for the dynamics simulation
158    */
159   void SetRootActor(Actor actor);
160
161   /**
162    * @brief Get the root actor for the simulation.
163    *
164    * @return The root actor for the dynamics simulation
165    */
166   Actor GetRootActor() const;
167
168 public: // Signals
169
170   /**
171    * @brief This signal is emitted when a collision is detected between two DynamicsBodies.
172    *
173    * A callback of the following type may be connected:
174    * @code
175    *   void YourCollisionHandler(Dali::DynamicsWorld world, const Dali::DynamicsCollision collisionData);
176    * @endcode
177    *
178    * @return The signal to connect to.
179    */
180   CollisionSignalV2& CollisionSignal();
181
182 public: // Not intended for application developers
183
184   /**
185    * @brief This constructor is used internally by Dali.
186    *
187    * @param [in] internal A pointer to a newly allocated Dali resource
188    */
189   explicit DALI_INTERNAL DynamicsWorld( Internal::DynamicsWorld* internal );
190 };
191
192 } // namespace Dali
193
194 #endif // __DALI_DYNAMICS_WORLD_H__