Box2D  3.0.0
A Real-Time-Oriented 2-D Physics Engine
Public Types | Public Member Functions | List of all members
box2d::ContactListener Class Reference

An interface for "listeners" for contacts. More...

#include <WorldCallbacks.hpp>

Public Types

using iteration_type = unsigned
 

Public Member Functions

virtual ~ContactListener ()
 
virtual void BeginContact (Contact &contact)
 Called when two fixtures begin to touch. More...
 
virtual void EndContact (Contact &contact)
 End contact callback. More...
 
virtual void PreSolve (Contact &contact, const Manifold &oldManifold)
 Pre-solve callback. More...
 
virtual void PostSolve (Contact &contact, const ContactImpulsesList &impulse, iteration_type solved)
 Post-solve callback. More...
 

Detailed Description

An interface for "listeners" for contacts.

Implement this class to get contact information. You can use these results for things like sounds and game logic. You can also get contact results by traversing the contact lists after the time step. However, you might miss some contacts because continuous physics leads to sub-stepping. Additionally you may receive multiple callbacks for the same contact in a single time step. You should strive to make your callbacks efficient because there may be many callbacks per time step.

Warning
You cannot create/destroy Box2D entities inside these callbacks.

Member Typedef Documentation

◆ iteration_type

Constructor & Destructor Documentation

◆ ~ContactListener()

virtual box2d::ContactListener::~ContactListener ( )
inlinevirtual

Member Function Documentation

◆ BeginContact()

virtual void box2d::ContactListener::BeginContact ( Contact contact)
inlinevirtual

Called when two fixtures begin to touch.

◆ EndContact()

virtual void box2d::ContactListener::EndContact ( Contact contact)
inlinevirtual

End contact callback.

Called when the contact's "touching" property becomes false, or just before the contact is destroyed.

Note
This contact persists until the broadphase determines there's no overlap anymore between the two fixtures.
If the contact's "touching" property becomes true again, BeginContact will be called again for this contact.
See also
Contact::IsTouching().
Parameters
contactContact that's about to be destroyed or whose "touching" property has become false.

◆ PostSolve()

virtual void box2d::ContactListener::PostSolve ( Contact contact,
const ContactImpulsesList impulse,
iteration_type  solved 
)
inlinevirtual

Post-solve callback.

This lets you inspect a contact after the solver is finished. This is useful for inspecting impulses.

Note
The contact manifold does not include time of impact impulses, which can be arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly in a separate data structure.
This is only called for contacts that are touching, solid, and awake.

◆ PreSolve()

virtual void box2d::ContactListener::PreSolve ( Contact contact,
const Manifold oldManifold 
)
inlinevirtual

Pre-solve callback.

This is called after a contact is updated. This allows you to inspect a contact before it goes to the solver. If you are careful, you can modify the contact manifold (e.g. disable contact). A copy of the old manifold is provided so that you can detect changes.

Note
This is called only for awake bodies.
This is called even when the number of contact points is zero.
This is not called for sensors.
If you set the number of contact points to zero, you will not get an EndContact callback. However, you may get a BeginContact callback the next step.

The documentation for this class was generated from the following file: