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

Functions for the distance joint. More...

Data Structures

struct  b2DistanceJointDef
 Distance joint definition Connects a point on body A with a point on body B by a segment. More...

Functions

b2JointId b2CreateDistanceJoint (b2WorldId worldId, const b2DistanceJointDef *def)
 Create a distance joint.
void b2DistanceJoint_SetRestLength (b2JointId jointId, float length)
 Set the rest length of a distance joint.
float b2DistanceJoint_GetRestLength (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_SetSpringForceRange (b2JointId jointId, float lowerForce, float upperForce)
 Set the force range for the spring.
void b2DistanceJoint_GetSpringForceRange (b2JointId jointId, float *lowerForce, float *upperForce)
 Get the force range for the spring.
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.
float b2DistanceJoint_GetSpringForce (b2JointId jointId)
 Get the current spring force.
void b2DistanceJoint_EnableLimit (b2JointId jointId, bool enableLimit)
 Enable joint limit.
bool b2DistanceJoint_IsLimitEnabled (b2JointId jointId)
 Is the distance joint limit enabled?
void b2DistanceJoint_SetLimits (b2JointId jointId, float minLength, float maxLength)
 Set the minimum and maximum length parameters of a distance joint.
float b2DistanceJoint_GetLowerLimit (b2JointId jointId)
 Get the distance joint minimum length.
float b2DistanceJoint_GetUpperLimit (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_SetTargetMotorSpeed (b2JointId jointId, float motorSpeed)
 Set the distance joint motor speed, usually in meters per second.
float b2DistanceJoint_GetTargetMotorSpeed (b2JointId jointId)
 Get the distance joint motor speed, usually in meters per second.
void b2DistanceJoint_SetMaxMotorForce (b2JointId jointId, float force)
 Set the distance joint maximum motor force, usually in newtons.
float b2DistanceJoint_GetMaxMotorForce (b2JointId jointId)
 Get the distance joint maximum motor force, usually in newtons.
float b2DistanceJoint_GetCurrentMotorForce (b2JointId jointId)
 Get the distance joint current motor force, usually 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 Connects a point on body A with a point on body B by a segment.

Useful for ropes and springs.

Data Fields
b2JointDef base Base joint definition.
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.
int 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.
float lowerSpringForce The lower spring force controls how much tension it can sustain.
float maxLength Maximum length for limit. Must be greater than or equal to the minimum length.
float maxMotorForce The maximum motor force, usually in newtons.
float minLength Minimum length for limit. Clamped to a stable minimum value.
float motorSpeed The desired motor speed, usually in meters per second.
float upperSpringForce The upper spring force controls how much compression it can sustain.

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_SetRestLength()

void b2DistanceJoint_SetRestLength ( b2JointId jointId,
float length )

Set the rest length of a distance joint.

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