Box2D 3.1.0
A 2D physics engine for games
Loading...
Searching...
No Matches
Distance Joint

Functions for the distance joint. More...

Collaboration diagram for Distance Joint:

Data Structures

struct  b2DistanceJointDef
 Distance joint definition. More...
 

Functions

b2JointId b2CreateDistanceJoint (b2WorldId worldId, const b2DistanceJointDef *def)
 Create a distance joint.
 
void b2DistanceJoint_SetLength (b2JointId jointId, float length)
 Set the rest length of a distance joint.
 
float b2DistanceJoint_GetLength (b2JointId jointId)
 Get the rest length of a distance joint.
 
void b2DistanceJoint_EnableSpring (b2JointId jointId, bool enableSpring)
 Enable/disable the distance joint spring. When disabled the distance joint is rigid.
 
bool b2DistanceJoint_IsSpringEnabled (b2JointId jointId)
 Is the distance joint spring enabled?
 
void b2DistanceJoint_SetSpringHertz (b2JointId jointId, float hertz)
 Set the spring stiffness in Hertz.
 
void b2DistanceJoint_SetSpringDampingRatio (b2JointId jointId, float dampingRatio)
 Set the spring damping ratio, non-dimensional.
 
float b2DistanceJoint_GetSpringHertz (b2JointId jointId)
 Get the spring Hertz.
 
float b2DistanceJoint_GetSpringDampingRatio (b2JointId jointId)
 Get the spring damping ratio.
 
void b2DistanceJoint_EnableLimit (b2JointId jointId, bool enableLimit)
 Enable joint limit.
 
bool b2DistanceJoint_IsLimitEnabled (b2JointId jointId)
 Is the distance joint limit enabled?
 
void b2DistanceJoint_SetLengthRange (b2JointId jointId, float minLength, float maxLength)
 Set the minimum and maximum length parameters of a distance joint.
 
float b2DistanceJoint_GetMinLength (b2JointId jointId)
 Get the distance joint minimum length.
 
float b2DistanceJoint_GetMaxLength (b2JointId jointId)
 Get the distance joint maximum length.
 
float b2DistanceJoint_GetCurrentLength (b2JointId jointId)
 Get the current length of a distance joint.
 
void b2DistanceJoint_EnableMotor (b2JointId jointId, bool enableMotor)
 Enable/disable the distance joint motor.
 
bool b2DistanceJoint_IsMotorEnabled (b2JointId jointId)
 Is the distance joint motor enabled?
 
void b2DistanceJoint_SetMotorSpeed (b2JointId jointId, float motorSpeed)
 Set the distance joint motor speed, typically in meters per second.
 
float b2DistanceJoint_GetMotorSpeed (b2JointId jointId)
 Get the distance joint motor speed, typically in meters per second.
 
void b2DistanceJoint_SetMaxMotorForce (b2JointId jointId, float force)
 Set the distance joint maximum motor force, typically in newtons.
 
float b2DistanceJoint_GetMaxMotorForce (b2JointId jointId)
 Get the distance joint maximum motor force, typically in newtons.
 
float b2DistanceJoint_GetMotorForce (b2JointId jointId)
 Get the distance joint current motor force, typically in newtons.
 
b2DistanceJointDef b2DefaultDistanceJointDef (void)
 Use this to initialize your joint definition.
 

Detailed Description

Functions for the distance joint.


Data Structure Documentation

◆ b2DistanceJointDef

struct b2DistanceJointDef

Distance joint definition.

This requires defining an anchor point on both bodies and the non-zero distance of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game.

Collaboration diagram for b2DistanceJointDef:
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 dampingRatio The spring linear damping ratio, non-dimensional.
bool enableLimit Enable/disable the joint limit.
bool enableMotor Enable/disable the joint motor.
bool enableSpring Enable the distance constraint to behave like a spring.

If false then the distance joint will be rigid, overriding the limit and motor.

float hertz The spring linear stiffness Hertz, cycles per second.
int32_t internalValue Used internally to detect a valid definition. DO NOT SET.
float length The rest length of this joint. Clamped to a stable minimum value.
b2Vec2 localAnchorA The local anchor point relative to bodyA's origin.
b2Vec2 localAnchorB The local anchor point relative to bodyB's origin.
float maxLength Maximum length. Must be greater than or equal to the minimum length.
float maxMotorForce The maximum motor force, usually in newtons.
float minLength Minimum length. Clamped to a stable minimum value.
float motorSpeed The desired motor speed, usually in meters per second.
void * userData User data pointer.

Function Documentation

◆ b2CreateDistanceJoint()

b2JointId b2CreateDistanceJoint ( b2WorldId worldId,
const b2DistanceJointDef * def )

Create a distance joint.

See also
b2DistanceJointDef for details

◆ b2DistanceJoint_EnableLimit()

void b2DistanceJoint_EnableLimit ( b2JointId jointId,
bool enableLimit )

Enable joint limit.

The limit only works if the joint spring is enabled. Otherwise the joint is rigid and the limit has no effect.

◆ b2DistanceJoint_SetLength()

void b2DistanceJoint_SetLength ( b2JointId jointId,
float length )

Set the rest length of a distance joint.

Parameters
jointIdThe id for a distance joint
lengthThe new distance joint length