2 * \page dynamics-collisions Collisions
3 * \section collision-detection Collision Detection
5 * Collision detection is automatic and occurs between all Dali::DynamicsBody objects in the simulation.@n
6 * To respond to a detected collisions, the application developer can connect to a signal provided by
7 * a Dali::DynamicsWorld object.
11 * // DynamicsWorld initialization code
15 * // Connect a signal handler to the signal
16 * Dali::DynamicsWorld theWorld( Stage::GetCurrent().GetDynamicsWorld() );
17 * theWorld.SignalCollision().Connect( this, &myClass::OnDynamicsCollision );
21 * // Implement a signal handler
22 * void myClass::OnDynamicsCollision( Dali::DynamicsWorld world, Dali::DynamicsCollision collisionData )
24 * std::cout << "Collision between "
25 * << collisionData.GetActorA().GetName() << " and "
26 * << collisionData.GetActorB().GetName() << " ";
28 * if( collisionData.GetImpactForce() != 0.0f )
30 * std::cout << "detected (impact force: " << collisionData.GetImpactForce() << " )";
34 * std::cout << "ended";
36 * std::cout << std::endl;
41 * \section collision-filtering Collision Filtering
44 * When a large number of Dali::DynamicsBody objects are added to the simulation, collision detection can become a
45 * significant performance drain, where every possible pairing of objects needs to be checked for collisions.</p>
46 * <p>You can significantly reduce the number of pairs considered for collision detection by using a collision filter.</p>
47 * <p>Each Dali::DynamicsBody can belong to a user defined collision filter group and have a user defined collision filter mask.<p>
48 * <p>A Dali::DynamicsBody pair are considered for collision detection if one or more bits in the filter group from each Dali::DynamicsBody
49 * matches one or more bits in the filter mask of the other Dali::DynamicsBody.
51 * <center><table border="1">
52 * <caption>Truth table</caption>
54 * <th> P </th>
55 * <th> Q </th>
56 * <th>tested for collision?</th>
80 * where <b>P</b> = bitwise AND of the collision group from the first Dali::DynamicsBody and the collision mask from the second Dali::DynamicsBody\n
81 * and <b>Q</b> = bitwise AND of the collision group from the second Dali::DynamicsBody and the collision mask from the first Dali::DynamicsBody.
84 * <b>Pseudo code for the filter check.</b>
86 * const bool canCollide( ( firstBody->GetCollisionGroup() & secondBody->GetCollisionMask() &&
87 * ( secondBody->GetCollisionGroup() & firstBody->GetCollisionMask() );
90 * <h3 class="pg">Code example - Illustrating how to create multiple filter groups and masks.</h3>
92 * // Define some collision groups
93 * const short int group0( 1 << 1 );
94 * const short int group1( 1 << 2 );
95 * const short int group2( 1 << 3 );
97 * // Create some Dali::DynamicsBodyConfig objects
98 * Dali::DynamicsBodyConfig bodyConfig0( Dali::DynamicsBodyConfig::New() );
99 * Dali::DynamicsBodyConfig bodyConfig1( Dali::DynamicsBodyConfig::New() );
100 * Dali::DynamicsBodyConfig bodyConfig2( Dali::DynamicsBodyConfig::New() );
102 * // Assign the collision filters to the configurations
103 * bodyConfig0->SetCollisionGroup(group0);
104 * bodyConfig0->SetCollisionMask( group1 | group2 );
105 * bodyConfig1->SetCollisionGroup(group1);
106 * bodyConfig1->SetCollisionMask(group0);
107 * bodyConfig2->SetCollisionGroup(group2);
108 * bodyConfig2->SetCollisionMask(group0 | group2);
111 * Collision detection is \b enabled between Dali::DynamicsBody pairs of...
113 * <li>group0 and group1 objects.</li>
114 * <li>group0 and group2 objects.</li>
115 * <li>group2 objects.</li>
117 * Collision detection is \b disabled between Dali::DynamicsBody pairs of...
119 * <li>group0 objects.</li>
120 * <li>group1 objects.</li>
121 * <li>group1 and group2 objects.</li>
127 * <li>Dali::DynamicsWorld::SignalCollision</li>
128 * <li>Dali::DynamicsCollision</li>
129 * <li>\ref Dali::DynamicsBodyConfig::SetCollisionGroup - to set the collision group</li>
130 * <li>\ref Dali::DynamicsBodyConfig::SetCollisionMask - to set the collision mask</li>