NewtonMaterialSetCollisionCallback

From Newton Wiki
Jump to: navigation, search

NewtonMaterialSetCollisionCallback

Syntax:

void NewtonMaterialSetCompoundCollisionCallback(const NewtonWorld* const newtonWorld, int id0, int id1, NewtonOnCompoundSubCollisionAABBOverlap compoundAabbOverlap)

Usage

Set userData and the functions event handlers for the material defined by the interaction between two physics groups.

Parameters

  • const NewtonWorld *newtonWorld - is the pointer to the Newton world.
  • int id0 - group id0.
  • int id1 - group id1.
  • void *userData - user data value.
  • NewtonOnAABBOverlap aabbOverlap - address of the event function called before contact calculation for collision. This parameter can be NULL.
  • NewtonContactsProcess process - address of the event function called for every contact resulting from contact calculation. This parameter can be NULL.

Description

  • Registers a set of events, which allow a program to retrieve all body contact events, this is highly useful to control things that happen when objects come in contact or to finely control or modify the generated contacts.

Remarks

  • When the AABB extend of the collision geometry of two bodies overlap, Newton collision system retrieves the material interaction that defines the behavior between the pair of bodies. The material interaction is collected from a database of materials, indexed by the material groupID assigned to the bodies.
  • If the material is tagged as non collidable, then no action is taken and the simulation continues.
  • If the material is tagged as collidable, and a aabbOverlap was set for this material, then the aabbOverlap function is called. If the function aabbOverlap returns 0, no further action is taken for this material (this can be used to ignore the interaction under certain conditions).
  • The application passes the address of structure in the userData along with three event function callbacks.
  • If the function aabbOverlap returns 1, Newton proceeds to calculate the array of contacts for the pair of colliding bodies.
  • If the function processCallback was set, the application receives a callback for every contact found between the two colliding bodies.
  • The application can perform fine grain control over the behavior of the collision system during this callback, for example, rejecting the contact, making the contact frictionless, applying special effects to the surface etc..

Porting old newton 1.53 code to newton 2.0 version of the callback

See: Difference between collision callback in newton 1.53 and 2.0

Examples

The application can collect information gathered during the contact-processing phase and provide some feedback to the player, a typical use for the material callback is to play sound effects:

When the function aabbOverlap is called by Newton, the application resets a variable, say maximumImpactSpeed, then for every call to the function processCallback, the application compares the impact speeds for all contacts with the value of maximumImpactSpeed, if the value is larger, then the application stores the new values along with the positions, and any other quantity desired.

At the end of process callback, the application plays a 3d sound based in the position and strength of the contacts.

See also