C4 Engine
C4 Engine API Documentation

RigidBodyController::HandleNewRigidBodyContact

Defined in:  C4Physics.h
Called when a new contact is made with another rigid body.
Prototype

virtual RigidBodyStatus HandleNewRigidBodyContact(const RigidBodyContact *contact, RigidBodyController *contactBody);

Parameters
contact The new contact.
contactBody The rigid body with which contact was made.
Description
The HandleNewRigidBodyContact function is called by the Physics Manager when a rigid body makes a new contact with another rigid body. This function can be overridden in a subclass of RigidBodyController in order to carry out a specialized response to a collision.

The contact parameter specifies the newly created RigidBodyContact object, which is an edge in the contact graph maintained by the Physics Manager. The rigid body for which the HandleNewRigidBodyContact function is called can be either the start element or finish element for this edge. The contactBody parameter specifies the other rigid body involved in the new contact, which is always on the opposite end of the contact edge relative to the rigid body for which the HandleNewRigidBodyContact function is called.

When a collision occurs between two rigid bodies, the HandleNewRigidBodyContact function is called once for each rigid body. The order of the two calls is not defined, so any overridden function should not depend on the HandleNewRigidBodyContact function being called for the start element of the contact parameter before the finish element or vice-versa.

An overridden HandleNewRigidBodyContact function can call the RigidBodyContact::GetWorldContactPosition function to obtain the world-space position and normal corresponding to one of the rigid bodies involving in the contact.

The HandleNewRigidBodyContact function should return one of the following constants.
kRigidBodyUnchanged No change was made to the rigid body or its contacts.
kRigidBodyContactsBroken One or more contacts with the rigid body were broken or may have been broken.
kRigidBodyDestroyed The rigid body was destroyed.
An implementation of the HandleNewRigidBodyContact function is allowed to destroy the contact specified by the contact parameter using the delete operator. In this case, the function must return kRigidBodyContactsBroken.

The default implementation of the HandleNewRigidBodyContact function calls the World::HandleNewRigidBodyContact function.
See Also

RigidBodyController::HandleNewGeometryContact

World::HandleNewRigidBodyContact

RigidBodyController::PurgeContacts

RigidBodyContact