/** * \page dynamics-collisions Collisions * \section collision-detection Collision Detection *
* Collision detection is automatic and occurs between all Dali::DynamicsBody objects in the simulation.@n * To respond to a detected collisions, the application developer can connect to a signal provided by * a Dali::DynamicsWorld object. * \code * ... * * // DynamicsWorld initialization code * * ... * * // Connect a signal handler to the signal * Dali::DynamicsWorld theWorld( Stage::GetCurrent().GetDynamicsWorld() ); * theWorld.SignalCollision().Connect( this, &myClass::OnDynamicsCollision ); * * ... * * // Implement a signal handler * void myClass::OnDynamicsCollision( Dali::DynamicsWorld world, Dali::DynamicsCollision collisionData ) * { * std::cout << "Collision between " * << collisionData.GetActorA().GetName() << " and " * << collisionData.GetActorB().GetName() << " "; * * if( collisionData.GetImpactForce() != 0.0f ) * { * std::cout << "detected (impact force: " << collisionData.GetImpactForce() << " )"; * } * else * { * std::cout << "ended"; * } * std::cout << std::endl; * } * \endcode * *
* When a large number of Dali::DynamicsBody objects are added to the simulation, collision detection can become a * significant performance drain, where every possible pairing of objects needs to be checked for collisions.
*You can significantly reduce the number of pairs considered for collision detection by using a collision filter.
*Each Dali::DynamicsBody can belong to a user defined collision filter group and have a user defined collision filter mask.
*
A Dali::DynamicsBody pair are considered for collision detection if one or more bits in the filter group from each Dali::DynamicsBody * matches one or more bits in the filter mask of the other Dali::DynamicsBody. *
*P | *Q | *tested for collision? | *
---|---|---|
0 * | 0 * | no * |
0 * | 1 * | no * |
1 * | 0 * | no * |
1 * | 1 * | yes * |
* where P = bitwise AND of the collision group from the first Dali::DynamicsBody and the collision mask from the second Dali::DynamicsBody\n * and Q = bitwise AND of the collision group from the second Dali::DynamicsBody and the collision mask from the first Dali::DynamicsBody. *
* Pseudo code for the filter check. * \code * const bool canCollide( ( firstBody->GetCollisionGroup() & secondBody->GetCollisionMask() && * ( secondBody->GetCollisionGroup() & firstBody->GetCollisionMask() ); * \endcode *
** Collision detection is \b enabled between Dali::DynamicsBody pairs of... *