dynamic mover

This commit is contained in:
Erin Catto 2026-10-20 23:33:18 -07:00
commit f0b1ed2fca
29 changed files with 3078 additions and 432 deletions

View file

@ -1358,6 +1358,77 @@ B3_API float b3MotorJoint_GetMaxSpringTorque( b3JointId jointId );
/**@}*/ // motor_joint
/**
* @defgroup mover_joint Mover Joint
* @brief Functions for the mover joint.
*
* The mover joint is designed for a dynamic character mover.
*
* @warning Experimental. The mover joint may change in future versions.
* @{
*/
/// Create a mover joint
/// @see b3MoverJointDef for details
B3_API b3JointId b3CreateMoverJoint( b3WorldId worldId, const b3MoverJointDef* def );
/// Set the desired relative linear velocity in meters per second
B3_API void b3MoverJoint_SetLinearVelocity( b3JointId jointId, b3Vec3 velocity );
/// Get the desired relative linear velocity in meters per second
B3_API b3Vec3 b3MoverJoint_GetLinearVelocity( b3JointId jointId );
/// Set the joint maximum force, usually in newtons
B3_API void b3MoverJoint_SetMaxVelocityForce( b3JointId jointId, b3Vec3 maxForce );
/// Get the joint maximum force, usually in newtons
B3_API b3Vec3 b3MoverJoint_GetMaxVelocityForce( b3JointId jointId );
/**@}*/ // mover_joint
/**
* @defgroup pogo_joint Pogo Joint
* @brief Functions for the pogo joint. Used for dynamic character movers.
*
* @warning Experimental. The pogo joint may change in future versions.
* @{
*/
/// Create a pogo joint
/// @see b3PogoJointDef for details
B3_API b3JointId b3CreatePogoJoint( b3WorldId worldId, const b3PogoJointDef* def );
/// Set the rest length of a pogo joint
/// @param jointId The id for a pogo joint
/// @param length The new pogo joint length
B3_API void b3PogoJoint_SetRestLength( b3JointId jointId, float length );
/// Get the rest length of a pogo joint
B3_API float b3PogoJoint_GetRestLength( b3JointId jointId );
/// Set the spring stiffness in Hertz
B3_API void b3PogoJoint_SetSpringHertz( b3JointId jointId, float hertz );
/// Get the spring Hertz
B3_API float b3PogoJoint_GetSpringHertz( b3JointId jointId );
/// Set the spring damping ratio, non-dimensional
B3_API void b3PogoJoint_SetSpringDampingRatio( b3JointId jointId, float dampingRatio );
/// Get the spring damping ratio
B3_API float b3PogoJoint_GetSpringDampingRatio( b3JointId jointId );
/// Get the current length of the pogo.
B3_API float b3PogoJoint_GetCurrentLength( b3JointId jointId );
/// Get the internal pogo velocity.
B3_API float b3PogoJoint_GetCurrentSpeed( b3JointId jointId );
/// Get the internal pogo impulse.
B3_API float b3PogoJoint_GetImpulse( b3JointId jointId );
/**@}*/ // pogo_joint
/**
* @defgroup filter_joint Filter Joint
* @brief Functions for the filter joint.

View file

@ -1053,6 +1053,20 @@ B3_INLINE b3Vec3 b3ClosestPointToAABB( b3Vec3 point, b3AABB a )
return b3Clamp( point, a.lowerBound, a.upperBound );
}
/// One-dimensional mass-spring-damper simulation. Returns the new velocity given the position and
/// time step. You can then compute the new position using:
/// position += timeStep * newVelocity
/// This drives towards a zero position. By using implicit integration we get a stable solution that
/// doesn't require transcendental functions.
B3_INLINE float b3SpringDamper( float hertz, float dampingRatio, float position, float velocity,
float timeStep )
{
float omega = 2.0f * B3_PI * hertz;
float omegaH = omega * timeStep;
return ( velocity - omega * omegaH * position ) /
( 1.0f + 2.0f * dampingRatio * omegaH + omegaH * omegaH );
}
/// The closest points between to segments or infinite lines.
typedef struct b3SegmentDistanceResult
{

View file

@ -628,6 +628,8 @@ typedef enum b3JointType
b3_sphericalJoint,
b3_weldJoint,
b3_wheelJoint,
b3_moverJoint,
b3_pogoJoint,
} b3JointType;
/// Base joint definition used by all joint types. The local frames are measured from the
@ -767,6 +769,63 @@ typedef struct b3MotorJointDef
/// @ingroup motor_joint
B3_API b3MotorJointDef b3DefaultMotorJointDef( void );
/// A mover joint is used to move a dynamic character mover through velocity commands. The x, y, and
/// z directions are handled separately. Does not affect rotation.
/// @ingroup mover_joint
typedef struct b3MoverJointDef
{
/// Base joint definition
b3JointDef base;
/// The desired linear velocity
b3Vec3 linearVelocity;
/// The maximum motor force in newtons.
b3Vec3 maxVelocityForce;
} b3MoverJointDef;
/// Use this to initialize your joint definition
/// @ingroup mover_joint
B3_API b3MoverJointDef b3DefaultMoverJointDef( void );
/// Pogo joint definition
/// @ingroup pogo_joint
typedef struct b3PogoJointDef
{
/// Base joint definition
b3JointDef base;
/// Normal vector at the contact
b3Vec3 normal;
/// The spring stiffness Hertz, cycles per second
float hertz;
/// The spring damping ratio, non-dimensional
float dampingRatio;
/// Spring length.
float restLength;
/// Maximum tension force. Controls how sticky the mover is to ground.
float maxTensionForce;
/// Maximum compression force. How hard the pogo pushes the mover up from the ground.
float maxCompressionForce;
/// The initial pogo internal impulse. The pogo is typically recreated every frame. This gives a
/// way to move the internal state forward for smoother spring behavior.
float impulse;
/// The initial pogo internal velocity. The pogo is typically recreated every frame. This gives
/// a way to move the internal state forward for smoother spring behavior.
float velocity;
} b3PogoJointDef;
/// Use this to initialize your joint definition
/// @ingroup pogo_joint
B3_API b3PogoJointDef b3DefaultPogoJointDef( void );
/// A filter joint is used to disable collision between two specific bodies.
/// @ingroup filter_joint
typedef struct b3FilterJointDef