ContactManager Class Reference

Aggregates all the contact information generated by the collision detection engine. More...

#include <physics/physics.hh>

Public Member Functions

 ContactManager ()
 Constructor. More...
 
virtual ~ContactManager ()
 Destructor. More...
 
void Clear ()
 Clear all stored contacts. More...
 
std::string CreateFilter (const std::string &_topic, const std::vector< std::string > &_collisions)
 Create a filter for contacts. More...
 
std::string CreateFilter (const std::string &_topic, const std::string &_collision)
 Create a filter for contacts. More...
 
std::string CreateFilter (const std::string &_name, const std::map< std::string, physics::CollisionPtr > &_collisions)
 Create a filter for contacts. More...
 
ContactGetContact (unsigned int _index) const
 Get a single contact by index. More...
 
unsigned int GetContactCount () const
 Return the number of valid contacts. More...
 
const std::vector< Contact * > & GetContacts () const
 Get all the contacts. More...
 
unsigned int GetFilterCount ()
 Get the number of filters in the contact manager. More...
 
bool HasFilter (const std::string &_name)
 Check if a filter with the specified name exists. More...
 
void Init (WorldPtr _world)
 Initialize the ContactManager. More...
 
bool NeverDropContacts () const
 returns the value last set with SetNeverDropContacts(). More...
 
ContactNewContact (Collision *_collision1, Collision *_collision2, const common::Time &_time)
 Add a new contact. More...
 
void PublishContacts ()
 Publish all contacts in a msgs::Contacts message. More...
 
void RemoveFilter (const std::string &_name)
 Remove a contacts filter and the associated custom publisher param[in] _name Filter name. More...
 
void ResetCount ()
 Set the contact count to zero. More...
 
void SetNeverDropContacts (const bool _neverDrop)
 If set to true, NewContact() will always add contacts even if there are no subscribers. More...
 
bool SubscribersConnected (Collision *_collision1, Collision *_collision2) const
 Returns true if any subscribers are connected which would be interested in contact details of either collision _collision1 or collision2, given that they have been loaded into the world already. More...
 

Detailed Description

Aggregates all the contact information generated by the collision detection engine.

Constructor & Destructor Documentation

◆ ContactManager()

Constructor.

◆ ~ContactManager()

virtual ~ContactManager ( )
virtual

Destructor.

Member Function Documentation

◆ Clear()

void Clear ( )

Clear all stored contacts.

◆ CreateFilter() [1/3]

std::string CreateFilter ( const std::string &  _topic,
const std::vector< std::string > &  _collisions 
)

Create a filter for contacts.

A new publisher will be created that publishes contacts associated to the input collisions. param[in] _name Filter name. param[in] _collisions A list of collision names used for filtering.

Returns
New topic where filtered messages will be published to.

◆ CreateFilter() [2/3]

std::string CreateFilter ( const std::string &  _topic,
const std::string &  _collision 
)

Create a filter for contacts.

A new publisher will be created that publishes contacts associated to the input collision. param[in] _name Filter name. param[in] _collision A collision name used for filtering.

Returns
New topic where filtered messages will be published to.

◆ CreateFilter() [3/3]

std::string CreateFilter ( const std::string &  _name,
const std::map< std::string, physics::CollisionPtr > &  _collisions 
)

Create a filter for contacts.

A new publisher will be created that publishes contacts associated to the input collision. param[in] _name Filter name. param[in] _collisions A map of collision name to collision object.

Returns
New topic where filtered messages will be published to.

◆ GetContact()

Contact* GetContact ( unsigned int  _index) const

Get a single contact by index.

The index must be between 0 and ContactManager::GetContactCount.

Parameters
[in]_indexIndex of the Contact to return.
Returns
Pointer to a contact, NULL If index is invalid.

◆ GetContactCount()

unsigned int GetContactCount ( ) const

Return the number of valid contacts.

◆ GetContacts()

const std::vector<Contact *>& GetContacts ( ) const

Get all the contacts.

The return vector may have invalid contacts. Only use contents of the vector between 0 and ContactManager::GetContactCount

Returns
Vector of contact pointers.

◆ GetFilterCount()

unsigned int GetFilterCount ( )

Get the number of filters in the contact manager.

return Number of filters

◆ HasFilter()

bool HasFilter ( const std::string &  _name)

Check if a filter with the specified name exists.

param[in] _name Name of filter. return True if the filter exists.

◆ Init()

void Init ( WorldPtr  _world)

Initialize the ContactManager.

This is required in order to publish contact messages via the ContactManager::PublishContacts method.

Parameters
[in]_worldPointer to the world that is initializing the contact manager.

◆ NeverDropContacts()

bool NeverDropContacts ( ) const

returns the value last set with SetNeverDropContacts().

Returns
the value last set with SetNeverDropContacts(). If SetNeverDropContacts() was never called, this will return false.

◆ NewContact()

Contact* NewContact ( Collision _collision1,
Collision _collision2,
const common::Time _time 
)

Add a new contact.

Normally this is only used by a Physics/Collision engine when a new contact is generated. All other users should just make use of the accessor functions.

If no one is listening, then the return value will be NULL (unless SetNeverDropContacts(true) was called). This is then a signal to the Physics engine that it can skip the extra processing necessary to get back contact information.

Parameters
[in]_collision1the first collision object
[in]_collision2the second collision object
[in]_timethe time of the contact
Returns
The new contact. The physics engine should populate the contact's parameters. NULL will be returned if there are no subscribers to the contact topic and NeverDropContacts() returns false (default).

◆ PublishContacts()

void PublishContacts ( )

Publish all contacts in a msgs::Contacts message.

◆ RemoveFilter()

void RemoveFilter ( const std::string &  _name)

Remove a contacts filter and the associated custom publisher param[in] _name Filter name.

◆ ResetCount()

void ResetCount ( )

Set the contact count to zero.

◆ SetNeverDropContacts()

void SetNeverDropContacts ( const bool  _neverDrop)

If set to true, NewContact() will always add contacts even if there are no subscribers.

Parameters
[in]_neverDropif true, never drop contact computation

◆ SubscribersConnected()

bool SubscribersConnected ( Collision _collision1,
Collision _collision2 
) const

Returns true if any subscribers are connected which would be interested in contact details of either collision _collision1 or collision2, given that they have been loaded into the world already.

This is the same test which NewContact() uses to determine whether there are any subscribers for the contacts, but the test here is optimized because it returns as soon as one subscriber is found which listens to either of the collisions. Note that this function needs to go through the list of custom publishers and check whether _collsion1 or _collision2 are part of the custom publishers and whether they have been loaded into the world, which comes at a cost. Unless there are any benefits in calling this function ahead of NewContact, it may be better to just use NewContact() directly. Also note that in order to exclude that NewContact() returns NULL, it is advisable to check NeverDropContacts() first (if it returns true, NewContacts() never returns NULL).

Parameters
[in]_collision1the first collision object
[in]_collision2the second collision object
Returns
true if any subscribers are connected for this pair

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