Box2D 3.2.0
A 2D physics engine for games
Loading...
Searching...
No Matches

Joints allow you to connect rigid bodies together while allowing various forms of relative motion. More...

Topics

 Distance Joint
 Functions for the distance joint.
 Filter Joint
 Functions for the filter joint.
 Motor Joint
 Functions for the motor joint.
 Mover Joint
 Functions for the mover joint.
 Pogo Joint
 Functions for the pogo joint.
 Prismatic Joint
 A prismatic joint allows for translation along a single axis with no rotation.
 Revolute Joint
 A revolute joint allows for relative rotation in the 2D plane with no relative translation.
 Weld Joint
 A weld joint fully constrains the relative transform between two bodies while allowing for springiness.
 Wheel Joint
 The wheel joint can be used to simulate wheels on vehicles.

Data Structures

struct  b2JointDef
 Base joint definition used by all joint types. More...

Enumerations

enum  b2JointType
 Joint type enumeration. More...

Functions

void b2DestroyJoint (b2JointId jointId)
 Destroy a joint.
bool b2Joint_IsValid (b2JointId id)
 Joint identifier validation. Provides validation for up to 64K allocations.
b2JointType b2Joint_GetType (b2JointId jointId)
 Get the joint type.
b2BodyId b2Joint_GetBodyA (b2JointId jointId)
 Get body A id on a joint.
b2BodyId b2Joint_GetBodyB (b2JointId jointId)
 Get body B id on a joint.
b2WorldId b2Joint_GetWorld (b2JointId jointId)
 Get the world that owns this joint.
void b2Joint_SetLocalFrameA (b2JointId jointId, b2Transform localFrame)
 Set the local frame on bodyA.
b2Transform b2Joint_GetLocalFrameA (b2JointId jointId)
 Get the local frame on bodyA.
void b2Joint_SetLocalFrameB (b2JointId jointId, b2Transform localFrame)
 Set the local frame on bodyB.
b2Transform b2Joint_GetLocalFrameB (b2JointId jointId)
 Get the local frame on bodyB.
void b2Joint_SetCollideConnected (b2JointId jointId, bool shouldCollide)
 Toggle collision between connected bodies.
bool b2Joint_GetCollideConnected (b2JointId jointId)
 Is collision allowed between connected bodies?
void b2Joint_SetUserData (b2JointId jointId, void *userData)
 Set the user data on a joint.
void * b2Joint_GetUserData (b2JointId jointId)
 Get the user data on a joint.
void b2Joint_WakeBodies (b2JointId jointId)
 Wake the bodies connected to this joint.
b2Vec2 b2Joint_GetConstraintForce (b2JointId jointId)
 Get the current constraint force for this joint. Usually in Newtons.
float b2Joint_GetConstraintTorque (b2JointId jointId)
 Get the current constraint torque for this joint. Usually in Newton * meters.
float b2Joint_GetLinearSeparation (b2JointId jointId)
 Get the current linear separation error for this joint.
float b2Joint_GetAngularSeparation (b2JointId jointId)
 Get the current angular separation error for this joint.
void b2Joint_SetConstraintTuning (b2JointId jointId, float hertz, float dampingRatio)
 Set the joint constraint tuning.
void b2Joint_GetConstraintTuning (b2JointId jointId, float *hertz, float *dampingRatio)
 Get the joint constraint tuning. Advanced feature.
void b2Joint_SetForceThreshold (b2JointId jointId, float threshold)
 Set the force threshold for joint events (Newtons).
float b2Joint_GetForceThreshold (b2JointId jointId)
 Get the force threshold for joint events (Newtons).
void b2Joint_SetTorqueThreshold (b2JointId jointId, float threshold)
 Set the torque threshold for joint events (N-m).
float b2Joint_GetTorqueThreshold (b2JointId jointId)
 Get the torque threshold for joint events (N-m).

Detailed Description

Joints allow you to connect rigid bodies together while allowing various forms of relative motion.


Data Structure Documentation

◆ b2JointDef

struct b2JointDef

Base joint definition used by all joint types.

The local frames are measured from the body's origin rather than the center of mass because:

  1. you might not know where the center of mass will be.
  2. if you add/remove shapes from a body and recompute the mass, the joints will be broken.
Data Fields
b2BodyId bodyIdA The first attached body.
b2BodyId bodyIdB The second attached body.
bool collideConnected Set this flag to true if the attached bodies should collide.
float constraintDampingRatio Constraint damping ratio (advanced feature).
float constraintHertz Constraint hertz (advanced feature).
float drawScale Debug draw scale.
float forceThreshold Force threshold for joint events.
b2Transform localFrameA The first local joint frame.
b2Transform localFrameB The second local joint frame.
float torqueThreshold Torque threshold for joint events.
void * userData User data pointer.

Enumeration Type Documentation

◆ b2JointType

Joint type enumeration.

This is useful because all joint types use b2JointId and sometimes you want to get the type of a joint.

Enumerator
b2_distanceJoint 

constrain the distance between two points

b2_filterJoint 

filter collision between two bodies

b2_motorJoint 

fully control the movement of a body

b2_moverJoint 

control the movement of the dynamic character mover

b2_pogoJoint 

ground interaction for the dynamic character mover

b2_prismaticJoint 

slide along an axis

b2_revoluteJoint 

rotate around a pivot

b2_weldJoint 

bring two bodies together with some flex

b2_wheelJoint 

wheel spins with shock absorber

Function Documentation

◆ b2Joint_GetAngularSeparation()

float b2Joint_GetAngularSeparation ( b2JointId jointId)

Get the current angular separation error for this joint.

Does not consider admissible movement. Radians.

◆ b2Joint_GetLinearSeparation()

float b2Joint_GetLinearSeparation ( b2JointId jointId)

Get the current linear separation error for this joint.

Does not consider admissible movement. Usually in meters.

◆ b2Joint_SetConstraintTuning()

void b2Joint_SetConstraintTuning ( b2JointId jointId,
float hertz,
float dampingRatio )

Set the joint constraint tuning.

Advanced feature.

Parameters
jointIdthe joint
hertzthe stiffness in Hertz (cycles per second)
dampingRatiothe non-dimensional damping ratio (one for critical damping)