1 #ifndef __DALI_DYNAMICS_WORLD_H__
2 #define __DALI_DYNAMICS_WORLD_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
23 // BASE CLASS INCLUDES
24 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/signals/dali-signal-v2.h>
29 namespace Dali DALI_IMPORT_API
32 namespace Internal DALI_INTERNAL
35 } // namespace Internal
39 class DynamicsCollision;
44 * @brief DynamicsWorld gives the application developer an alternative method of moving and rotating.
45 * actors in the DALi scene.
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.
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.
54 * Here is an example illustrating the basic steps to initialise the simulation and
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 ) );
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 );
68 * // create an actor to represent a rigid body
69 * Dali::Actor actor( Dali::Actor::New() );
70 * actor.SetParentOrigin( Dali::ParentOrigin::CENTER );
72 * // Enable dynamics for the actor, creating a rigid body with default configuration
73 * actor.EnableDynamics( Dali::DynamicsBodyConfig::New() );
75 * // Add the actor to the scene
76 * dynamicsRootActor.Add( actor );
79 class DynamicsWorld : public BaseHandle
84 static const char* const SIGNAL_COLLISION; ///< name "collision"
87 typedef SignalV2< void (DynamicsWorld, const DynamicsCollision) > CollisionSignalV2; ///< Type of collision signal
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),
108 * @brief Create an uninitialized DynamicsWorld handle.
113 * @brief Virtual destructor.
115 virtual ~DynamicsWorld();
118 * @copydoc Dali::BaseHandle::operator=
120 using BaseHandle::operator=;
122 // Methods that modify the simulation
126 * @brief Set the gravity for the world.
128 * @param[in] gravity a Vector3 specifying the applicable gravity for the world.
130 void SetGravity( const Vector3& gravity );
133 * @brief Get the gravity for the world.
135 * @return A Vector3 specifying the gravity that will be applied in the world.
137 const Vector3& GetGravity() const;
140 * @brief Get the current debug drawmode.
142 * @return A combination of the flags in DEBUG_MODES or 0 if debug drawing is currently disabled.
144 int GetDebugDrawMode() const;
147 * @brief Set the debug drawmode for the simulation.
149 * @param[in] mode A combination of the flags in DEBUG_MODES or 0 to disable debug drawing
151 void SetDebugDrawMode(const int mode);
154 * @brief Set the actor which will represent the dynamics world.
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
159 void SetRootActor(Actor actor);
162 * @brief Get the root actor for the simulation.
164 * @return The root actor for the dynamics simulation
166 Actor GetRootActor() const;
171 * @brief This signal is emitted when a collision is detected between two DynamicsBodies.
173 * A callback of the following type may be connected:
175 * void YourCollisionHandler(Dali::DynamicsWorld world, const Dali::DynamicsCollision collisionData);
178 * @return The signal to connect to.
180 CollisionSignalV2& CollisionSignal();
182 public: // Not intended for application developers
185 * @brief This constructor is used internally by Dali.
187 * @param [in] internal A pointer to a newly allocated Dali resource
189 explicit DALI_INTERNAL DynamicsWorld( Internal::DynamicsWorld* internal );
194 #endif // __DALI_DYNAMICS_WORLD_H__