Rapier C — 2D / f64 0.36.0+c.0
Loading...
Searching...
No Matches
Events, contacts, and debug drawing

Event collectors own their recorded events. More...

Data Structures

struct  R2CollisionEvent
 Collision start/stop flags match Rapier CollisionEventFlags. More...
struct  R2ContactForceEvent
 Contact-force event, enabled by flags and the collider force threshold. More...
struct  R2ContactModification
 Mutable per-manifold properties. More...
struct  R2DebugLine
 World-space line segment produced by physics debug rendering. More...
struct  R2ContactPair
 Current narrow-phase pair and accumulated solver impulse summary. More...
struct  R2IntersectionPair
 Sensor intersection state for a collider pair. More...
struct  R2ContactPoint
 One manifold contact and its normal solver impulse. More...
struct  R2OptionalContactPair
 Optional contact pair; check found before reading the pair. More...
struct  R2OptionalIntersectionPair
 Optional intersection pair; check found before reading the pair. More...
struct  R2ContactManifold
 Geometric contact manifold of a contact pair: contacts sharing one normal. More...
struct  R2SolverContact
 Contact seen by the constraint solver. More...
struct  R2EventCallbacks
 Callbacks invoked while stepping, in addition to collecting the events. More...
struct  R2DebugRenderStyle
 Debug-render colors and sizes. More...

Macros

#define R2_DEBUG_COLLIDER_SHAPES   1
 Debug-render flag: collider shapes.
#define R2_DEBUG_RIGID_BODY_AXES   2
 Debug-render flag: rigid body axes.
#define R2_DEBUG_MULTIBODY_JOINTS   4
 Debug-render flag: multibody joints.
#define R2_DEBUG_IMPULSE_JOINTS   8
 Debug-render flag: impulse joints.
#define R2_DEBUG_SOLVER_CONTACTS   16
 Debug-render flag: solver contacts.
#define R2_DEBUG_CONTACTS   32
 Debug-render flag: contacts.
#define R2_DEBUG_COLLIDER_AABBS   64
 Debug-render flag: collider aabbs.
#define R2_DEBUG_SOFT_BODIES   128
 Debug-render flag: soft bodies.
#define R2_DEBUG_PSEUDO_NORMALS   256
 Debug-render flag: pseudo normals.
#define R2_DEBUG_SOFT_VOLUME_CONTACTS   512
 Debug-render flag: soft volume contacts.
#define R2_DEBUG_SOFT_BODY_STRESS   1024
 Debug-render flag: soft body stress.
#define R2_COLLISION_EVENT_SENSOR   1
 Collision event flag: at least one of the colliders was a sensor when the event fired.
#define R2_COLLISION_EVENT_REMOVED   2
 Collision event flag: the collision stopped because at least one collider was removed.

Typedefs

typedef struct R2EventCollector R2EventCollector
 Events accumulate across steps until r2EventCollector_Clear: reading them never drains the collector, allowing two-call buffer sizing.
typedef struct R2SoftBodyTearEvent R2SoftBodyTearEvent
 Owned copy of a tear event.
typedef struct R2CollisionEvent R2CollisionEvent
 Collision start/stop flags match Rapier CollisionEventFlags.
typedef struct R2ContactForceEvent R2ContactForceEvent
 Contact-force event, enabled by flags and the collider force threshold.
typedef struct R2ContactModification R2ContactModification
 Mutable per-manifold properties.
typedef struct R2DebugLine R2DebugLine
 World-space line segment produced by physics debug rendering.
typedef struct R2ContactPair R2ContactPair
 Current narrow-phase pair and accumulated solver impulse summary.
typedef struct R2IntersectionPair R2IntersectionPair
 Sensor intersection state for a collider pair.
typedef struct R2ContactPoint R2ContactPoint
 One manifold contact and its normal solver impulse.
typedef struct R2OptionalContactPair R2OptionalContactPair
 Optional contact pair; check found before reading the pair.
typedef struct R2OptionalIntersectionPair R2OptionalIntersectionPair
 Optional intersection pair; check found before reading the pair.
typedef struct R2ContactManifold R2ContactManifold
 Geometric contact manifold of a contact pair: contacts sharing one normal.
typedef struct R2SolverContact R2SolverContact
 Contact seen by the constraint solver.
typedef void(*) R2CollisionEventCallback(void *user_data, const struct R2ReadContext *read, const struct R2CollisionEvent *event, const struct R2ContactPoint *contacts, size_t contact_count)
 Called during the step for each collision event, after it was added to the collector.
typedef void(*) R2ContactForceEventCallback(void *user_data, const struct R2ReadContext *read, const struct R2ContactForceEvent *event)
 Called during the step for each contact-force event, after it was added to the collector.
typedef struct R2EventCallbacks R2EventCallbacks
 Callbacks invoked while stepping, in addition to collecting the events.
typedef struct R2DebugRenderStyle R2DebugRenderStyle
 Debug-render colors and sizes.

Functions

struct R2EventCollector * r2NewEventCollector (void)
 Allocate an empty event collector; release it with r2FreeEventCollector.
R2Status r2FreeEventCollector (struct R2EventCollector *events)
 Release an owned event collector.
R2Status r2EventCollector_Clear (struct R2EventCollector *events)
 Discard all collected events.
size_t r2EventCollector_CollisionEvents (const struct R2EventCollector *events, struct R2CollisionEvent *buffer, size_t capacity)
 Copy the collision start/stop events collected since the last clear, without removing them.
size_t r2EventCollector_ContactForceEvents (const struct R2EventCollector *events, struct R2ContactForceEvent *buffer, size_t capacity)
 Copy the contact-force events collected since the last clear, without removing them.
size_t r2EventCollector_TearEventCount (const struct R2EventCollector *events)
 Return the number of soft-body tear events collected since the last clear.
struct R2SoftBodyTearEvent * r2EventCollector_TearEvent (const struct R2EventCollector *events, size_t index)
 Return an owned copy of a queued tear event; release with r2FreeSoftBodyTearEvent.
size_t r2DebugRender (const struct R2World *world, uint32_t mode, struct R2DebugLine *buffer, size_t capacity)
 Copy the debug-render lines of the world with the default style.
size_t r2ContactPairs (const struct R2World *world, struct R2ContactPair *buffer, size_t capacity)
 Copy current narrow-phase contact pairs, including pairs without active solver contacts.
struct R2ContactPair r2ContactPair (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2)
 Return the narrow-phase contact pair for two colliders, or report R2_NOT_FOUND.
size_t r2IntersectionPairs (const struct R2World *world, struct R2IntersectionPair *buffer, size_t capacity)
 Copy current sensor intersection pairs from the narrow phase.
size_t r2ContactPoints (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2, struct R2ContactPoint *buffer, size_t capacity)
 Contact points in collider-local space; normal in world space.
struct R2OptionalContactPair r2TryContactPair (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2)
 Return the narrow-phase contact pair for two colliders, with found = 0 if the broad phase found no potential contact between them (R2_OK).
struct R2IntersectionPair r2IntersectionPair (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2)
 Return the intersection state of two colliders involving a sensor, or report R2_NOT_FOUND if the broad phase found no potential intersection.
struct R2OptionalIntersectionPair r2TryIntersectionPair (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2)
 Return the intersection state of two colliders involving a sensor, with found = 0 if the broad phase found no potential intersection (R2_OK).
size_t r2Collider_ContactPairs (struct R2ColliderHandle handle, struct R2ContactPair *buffer, size_t capacity)
 Copy the narrow-phase contact pairs involving the collider, including pairs without active solver contacts.
size_t r2Collider_IntersectionPairs (struct R2ColliderHandle handle, struct R2IntersectionPair *buffer, size_t capacity)
 Copy the intersection pairs involving the collider, in the narrow-phase order.
size_t r2ContactManifolds (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2, struct R2ContactManifold *buffer, size_t capacity)
 Copy the geometric contact manifolds of a contact pair, or report R2_NOT_FOUND without a pair.
size_t r2SolverContacts (struct R2ColliderHandle collider1, struct R2ColliderHandle collider2, size_t manifold_index, struct R2SolverContact *buffer, size_t capacity)
 Copy the solver contacts of one manifold of a contact pair, or report R2_NOT_FOUND without a pair.
R2Status r2EventCollector_SetCallbacks (struct R2EventCollector *events, const struct R2EventCallbacks *callbacks)
 Replace the callbacks invoked while stepping with this collector; NULL removes them.
struct R2DebugRenderStyle r2DefaultDebugRenderStyle (void)
 Return native default debug-render style.
size_t r2DebugRenderWithStyle (const struct R2World *world, uint32_t mode, const struct R2DebugRenderStyle *style, struct R2DebugLine *buffer, size_t capacity)
 Copy the debug-render lines of the world drawn with the given style.

Detailed Description

Event collectors own their recorded events.

Enable event flags on colliders and pass a collector when stepping. Copying events does not drain the collector; Clear discards them. Contact-force events also honor the collider force threshold.

Macro Definition Documentation

◆ R2_COLLISION_EVENT_REMOVED

#define R2_COLLISION_EVENT_REMOVED   2

Collision event flag: the collision stopped because at least one collider was removed.

◆ R2_COLLISION_EVENT_SENSOR

#define R2_COLLISION_EVENT_SENSOR   1

Collision event flag: at least one of the colliders was a sensor when the event fired.

◆ R2_DEBUG_COLLIDER_AABBS

#define R2_DEBUG_COLLIDER_AABBS   64

Debug-render flag: collider aabbs.

◆ R2_DEBUG_COLLIDER_SHAPES

#define R2_DEBUG_COLLIDER_SHAPES   1

Debug-render flag: collider shapes.

◆ R2_DEBUG_CONTACTS

#define R2_DEBUG_CONTACTS   32

Debug-render flag: contacts.

◆ R2_DEBUG_IMPULSE_JOINTS

#define R2_DEBUG_IMPULSE_JOINTS   8

Debug-render flag: impulse joints.

◆ R2_DEBUG_MULTIBODY_JOINTS

#define R2_DEBUG_MULTIBODY_JOINTS   4

Debug-render flag: multibody joints.

◆ R2_DEBUG_PSEUDO_NORMALS

#define R2_DEBUG_PSEUDO_NORMALS   256

Debug-render flag: pseudo normals.

◆ R2_DEBUG_RIGID_BODY_AXES

#define R2_DEBUG_RIGID_BODY_AXES   2

Debug-render flag: rigid body axes.

◆ R2_DEBUG_SOFT_BODIES

#define R2_DEBUG_SOFT_BODIES   128

Debug-render flag: soft bodies.

◆ R2_DEBUG_SOFT_BODY_STRESS

#define R2_DEBUG_SOFT_BODY_STRESS   1024

Debug-render flag: soft body stress.

◆ R2_DEBUG_SOFT_VOLUME_CONTACTS

#define R2_DEBUG_SOFT_VOLUME_CONTACTS   512

Debug-render flag: soft volume contacts.

◆ R2_DEBUG_SOLVER_CONTACTS

#define R2_DEBUG_SOLVER_CONTACTS   16

Debug-render flag: solver contacts.

Typedef Documentation

◆ R2CollisionEvent

typedef struct R2CollisionEvent R2CollisionEvent

Collision start/stop flags match Rapier CollisionEventFlags.

◆ R2CollisionEventCallback

typedef void(*) R2CollisionEventCallback(void *user_data, const struct R2ReadContext *read, const struct R2CollisionEvent *event, const struct R2ContactPoint *contacts, size_t contact_count)

Called during the step for each collision event, after it was added to the collector.

contacts holds the geometric contacts of the pair at that time (none for sensors), in the event's collider order; it is borrowed for this call only.

◆ R2ContactForceEvent

typedef struct R2ContactForceEvent R2ContactForceEvent

Contact-force event, enabled by flags and the collider force threshold.

◆ R2ContactForceEventCallback

typedef void(*) R2ContactForceEventCallback(void *user_data, const struct R2ReadContext *read, const struct R2ContactForceEvent *event)

Called during the step for each contact-force event, after it was added to the collector.

◆ R2ContactManifold

typedef struct R2ContactManifold R2ContactManifold

Geometric contact manifold of a contact pair: contacts sharing one normal.

Local data follow the pair's own collider1/collider2 order (see r2ContactPair).

◆ R2ContactModification

typedef struct R2ContactModification R2ContactModification

Mutable per-manifold properties.

Set enabled=0 to discard all its solver contacts.

◆ R2ContactPair

typedef struct R2ContactPair R2ContactPair

Current narrow-phase pair and accumulated solver impulse summary.

◆ R2ContactPoint

typedef struct R2ContactPoint R2ContactPoint

One manifold contact and its normal solver impulse.

◆ R2DebugLine

typedef struct R2DebugLine R2DebugLine

World-space line segment produced by physics debug rendering.

◆ R2DebugRenderStyle

typedef struct R2DebugRenderStyle R2DebugRenderStyle

Debug-render colors and sizes.

Colors are HSLA: hue in degrees, then saturation, lightness and alpha in [0, 1]; multipliers scale each component. Initialize with r2DefaultDebugRenderStyle.

◆ R2EventCallbacks

typedef struct R2EventCallbacks R2EventCallbacks

Callbacks invoked while stepping, in addition to collecting the events.

They follow the R2PhysicsHooks rules: never unwind or retain arguments, read through the ReadContext, never mutate the world, and be safe for concurrent invocation in parallel builds. NULL callbacks are skipped.

◆ R2EventCollector

Events accumulate across steps until r2EventCollector_Clear: reading them never drains the collector, allowing two-call buffer sizing.

Optional callbacks also see each event during the step.

◆ R2IntersectionPair

typedef struct R2IntersectionPair R2IntersectionPair

Sensor intersection state for a collider pair.

◆ R2OptionalContactPair

typedef struct R2OptionalContactPair R2OptionalContactPair

Optional contact pair; check found before reading the pair.

◆ R2OptionalIntersectionPair

typedef struct R2OptionalIntersectionPair R2OptionalIntersectionPair

Optional intersection pair; check found before reading the pair.

◆ R2SoftBodyTearEvent

Owned copy of a tear event.

Read particle remapping before rebuilding render meshes.

◆ R2SolverContact

typedef struct R2SolverContact R2SolverContact

Contact seen by the constraint solver.

Points are world-space, on each body's surface.

Function Documentation

◆ r2Collider_ContactPairs()

size_t r2Collider_ContactPairs ( struct R2ColliderHandle handle,
struct R2ContactPair * buffer,
size_t capacity )

Copy the narrow-phase contact pairs involving the collider, including pairs without active solver contacts.

The collider may be either collider1 or collider2 of each pair.

See also
Arrays and output buffers

◆ r2Collider_IntersectionPairs()

size_t r2Collider_IntersectionPairs ( struct R2ColliderHandle handle,
struct R2IntersectionPair * buffer,
size_t capacity )

Copy the intersection pairs involving the collider, in the narrow-phase order.

The collider may be either collider1 or collider2 of each pair.

See also
Arrays and output buffers

◆ r2ContactManifolds()

size_t r2ContactManifolds ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2,
struct R2ContactManifold * buffer,
size_t capacity )

Copy the geometric contact manifolds of a contact pair, or report R2_NOT_FOUND without a pair.

Their order matches the manifold_index of r2ContactPoints. Soft pairs have no rigid manifolds.

See also
Arrays and output buffers

◆ r2ContactPair()

struct R2ContactPair r2ContactPair ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2 )

Return the narrow-phase contact pair for two colliders, or report R2_NOT_FOUND.

Its collider1 and collider2 follow the narrow-phase order, which may differ from the argument order.

◆ r2ContactPairs()

size_t r2ContactPairs ( const struct R2World * world,
struct R2ContactPair * buffer,
size_t capacity )

Copy current narrow-phase contact pairs, including pairs without active solver contacts.

See also
Arrays and output buffers

◆ r2ContactPoints()

size_t r2ContactPoints ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2,
struct R2ContactPoint * buffer,
size_t capacity )

Contact points in collider-local space; normal in world space.

Geometric manifolds may be recycled. local_p1/local_p2 follow the pair's own collider1/collider2 order (see r2ContactPair), which may differ from the argument order. For clustered solver impulses use contact pair totals. Soft pairs have no rigid manifolds.

See also
Arrays and output buffers

◆ r2DebugRender()

size_t r2DebugRender ( const struct R2World * world,
uint32_t mode,
struct R2DebugLine * buffer,
size_t capacity )

Copy the debug-render lines of the world with the default style.

mode combines R2_DEBUG_* bits; colors are HSLA (hue in degrees), matching Rapier DebugColor.

See also
Arrays and output buffers

◆ r2DebugRenderWithStyle()

size_t r2DebugRenderWithStyle ( const struct R2World * world,
uint32_t mode,
const struct R2DebugRenderStyle * style,
struct R2DebugLine * buffer,
size_t capacity )

Copy the debug-render lines of the world drawn with the given style.

mode combines R2_DEBUG_* bits. NULL style uses the default style.

See also
Arrays and output buffers

◆ r2DefaultDebugRenderStyle()

struct R2DebugRenderStyle r2DefaultDebugRenderStyle ( void )

Return native default debug-render style.

This POD value owns no resources.

◆ r2EventCollector_Clear()

R2Status r2EventCollector_Clear ( struct R2EventCollector * events)

Discard all collected events.

Does not change the world or the callbacks.

◆ r2EventCollector_CollisionEvents()

size_t r2EventCollector_CollisionEvents ( const struct R2EventCollector * events,
struct R2CollisionEvent * buffer,
size_t capacity )

Copy the collision start/stop events collected since the last clear, without removing them.

See also
Arrays and output buffers

◆ r2EventCollector_ContactForceEvents()

size_t r2EventCollector_ContactForceEvents ( const struct R2EventCollector * events,
struct R2ContactForceEvent * buffer,
size_t capacity )

Copy the contact-force events collected since the last clear, without removing them.

See also
Arrays and output buffers

◆ r2EventCollector_SetCallbacks()

R2Status r2EventCollector_SetCallbacks ( struct R2EventCollector * events,
const struct R2EventCallbacks * callbacks )

Replace the callbacks invoked while stepping with this collector; NULL removes them.

They take effect from the next Step or DetectCollisions call.

◆ r2EventCollector_TearEvent()

struct R2SoftBodyTearEvent * r2EventCollector_TearEvent ( const struct R2EventCollector * events,
size_t index )

Return an owned copy of a queued tear event; release with r2FreeSoftBodyTearEvent.

Does not remove the queued event.

◆ r2EventCollector_TearEventCount()

size_t r2EventCollector_TearEventCount ( const struct R2EventCollector * events)

Return the number of soft-body tear events collected since the last clear.

◆ r2FreeEventCollector()

R2Status r2FreeEventCollector ( struct R2EventCollector * events)

Release an owned event collector.

NULL is allowed. Do not pass borrowed pointers or free the object twice.

◆ r2IntersectionPair()

struct R2IntersectionPair r2IntersectionPair ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2 )

Return the intersection state of two colliders involving a sensor, or report R2_NOT_FOUND if the broad phase found no potential intersection.

The result keeps the argument order.

◆ r2IntersectionPairs()

size_t r2IntersectionPairs ( const struct R2World * world,
struct R2IntersectionPair * buffer,
size_t capacity )

Copy current sensor intersection pairs from the narrow phase.

See also
Arrays and output buffers

◆ r2NewEventCollector()

struct R2EventCollector * r2NewEventCollector ( void )

Allocate an empty event collector; release it with r2FreeEventCollector.

◆ r2SolverContacts()

size_t r2SolverContacts ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2,
size_t manifold_index,
struct R2SolverContact * buffer,
size_t capacity )

Copy the solver contacts of one manifold of a contact pair, or report R2_NOT_FOUND without a pair.

Points are resolved through the bodies' current poses. With contact clustering (3D composite shapes), the solver may use merged manifolds instead; use contact pair totals then.

See also
Arrays and output buffers

◆ r2TryContactPair()

struct R2OptionalContactPair r2TryContactPair ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2 )

Return the narrow-phase contact pair for two colliders, with found = 0 if the broad phase found no potential contact between them (R2_OK).

The pair's collider1 and collider2 follow the narrow-phase order, which may differ from the argument order.

◆ r2TryIntersectionPair()

struct R2OptionalIntersectionPair r2TryIntersectionPair ( struct R2ColliderHandle collider1,
struct R2ColliderHandle collider2 )

Return the intersection state of two colliders involving a sensor, with found = 0 if the broad phase found no potential intersection (R2_OK).

The pair keeps the argument order.