dynamic mover
This commit is contained in:
parent
f36d061ba2
commit
f0b1ed2fca
29 changed files with 3078 additions and 432 deletions
|
|
@ -51,6 +51,7 @@ set(BOX3D_SOURCE_FILES
|
|||
mesh.c
|
||||
motor_joint.c
|
||||
mover.c
|
||||
mover_joint.c
|
||||
name_cache.c
|
||||
name_cache.h
|
||||
parallel_for.c
|
||||
|
|
@ -59,6 +60,7 @@ set(BOX3D_SOURCE_FILES
|
|||
physics_world.c
|
||||
physics_world.h
|
||||
platform.h
|
||||
pogo_joint.c
|
||||
prismatic_joint.c
|
||||
qsort.h
|
||||
rapidhash.h
|
||||
|
|
|
|||
143
src/joint.c
143
src/joint.c
|
|
@ -62,6 +62,21 @@ b3MotorJointDef b3DefaultMotorJointDef( void )
|
|||
return def;
|
||||
}
|
||||
|
||||
b3MoverJointDef b3DefaultMoverJointDef( void )
|
||||
{
|
||||
b3MoverJointDef def = { 0 };
|
||||
def.base = b3DefaultJointDef();
|
||||
return def;
|
||||
}
|
||||
|
||||
b3PogoJointDef b3DefaultPogoJointDef( void )
|
||||
{
|
||||
b3PogoJointDef def = { 0 };
|
||||
def.base = b3DefaultJointDef();
|
||||
def.normal = b3Vec3_axisY;
|
||||
return def;
|
||||
}
|
||||
|
||||
b3FilterJointDef b3DefaultFilterJointDef( void )
|
||||
{
|
||||
b3FilterJointDef def = { 0 };
|
||||
|
|
@ -511,6 +526,66 @@ b3JointId b3CreateMotorJoint( b3WorldId worldId, const b3MotorJointDef* def )
|
|||
return jointId;
|
||||
}
|
||||
|
||||
b3JointId b3CreateMoverJoint( b3WorldId worldId, const b3MoverJointDef* def )
|
||||
{
|
||||
B3_CHECK_JOINT_DEF( def );
|
||||
B3_ASSERT( b3IsValidVec3( def->linearVelocity ) );
|
||||
B3_ASSERT( b3IsValidVec3( def->maxVelocityForce ) );
|
||||
|
||||
b3World* world = b3GetUnlockedWorldFromId( worldId );
|
||||
if ( world == NULL )
|
||||
{
|
||||
return (b3JointId){ 0 };
|
||||
}
|
||||
|
||||
b3JointPair pair = b3CreateJoint( world, &def->base, b3_moverJoint );
|
||||
b3JointSim* joint = pair.jointSim;
|
||||
|
||||
joint->moverJoint = (b3MoverJoint){ 0 };
|
||||
joint->moverJoint.linearVelocity = def->linearVelocity;
|
||||
joint->moverJoint.maxVelocityForce = def->maxVelocityForce;
|
||||
|
||||
b3JointId jointId = { joint->jointId + 1, world->worldId, pair.joint->generation };
|
||||
B3_REC_CREATE( world, CreateMoverJoint, jointId, worldId, *def );
|
||||
return jointId;
|
||||
}
|
||||
|
||||
b3JointId b3CreatePogoJoint( b3WorldId worldId, const b3PogoJointDef* def )
|
||||
{
|
||||
B3_CHECK_JOINT_DEF( def );
|
||||
B3_ASSERT( b3IsValidVec3( def->normal ) );
|
||||
B3_ASSERT( b3IsValidFloat( def->restLength ) && def->restLength >= 0.0f );
|
||||
B3_ASSERT( b3IsValidFloat( def->hertz ) && def->hertz >= 0.0f );
|
||||
B3_ASSERT( b3IsValidFloat( def->dampingRatio ) && def->dampingRatio >= 0.0f );
|
||||
B3_ASSERT( b3IsValidFloat( def->maxTensionForce ) && def->maxTensionForce >= 0.0f );
|
||||
B3_ASSERT( b3IsValidFloat( def->maxCompressionForce ) && def->maxCompressionForce >= 0.0f );
|
||||
B3_ASSERT( b3IsValidFloat( def->impulse ) );
|
||||
B3_ASSERT( b3IsValidFloat( def->velocity ) );
|
||||
|
||||
b3World* world = b3GetUnlockedWorldFromId( worldId );
|
||||
if ( world == NULL )
|
||||
{
|
||||
return (b3JointId){ 0 };
|
||||
}
|
||||
|
||||
b3JointPair pair = b3CreateJoint( world, &def->base, b3_pogoJoint );
|
||||
b3JointSim* joint = pair.jointSim;
|
||||
|
||||
joint->pogoJoint = (b3PogoJoint){ 0 };
|
||||
joint->pogoJoint.normal = def->normal;
|
||||
joint->pogoJoint.restLength = def->restLength;
|
||||
joint->pogoJoint.hertz = def->hertz;
|
||||
joint->pogoJoint.dampingRatio = def->dampingRatio;
|
||||
joint->pogoJoint.maxTensionForce = def->maxTensionForce;
|
||||
joint->pogoJoint.maxCompressionForce = def->maxCompressionForce;
|
||||
joint->pogoJoint.impulse = def->impulse;
|
||||
joint->pogoJoint.velocity = def->velocity;
|
||||
|
||||
b3JointId jointId = { joint->jointId + 1, world->worldId, pair.joint->generation };
|
||||
B3_REC_CREATE( world, CreatePogoJoint, jointId, worldId, *def );
|
||||
return jointId;
|
||||
}
|
||||
|
||||
b3JointId b3CreateFilterJoint( b3WorldId worldId, const b3FilterJointDef* def )
|
||||
{
|
||||
B3_CHECK_JOINT_DEF( def );
|
||||
|
|
@ -1120,6 +1195,20 @@ void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, flo
|
|||
}
|
||||
break;
|
||||
|
||||
case b3_moverJoint:
|
||||
{
|
||||
b3MoverJoint* joint = &sim->moverJoint;
|
||||
linearImpulse = b3Length( joint->linearVelocityImpulse );
|
||||
}
|
||||
break;
|
||||
|
||||
case b3_pogoJoint:
|
||||
{
|
||||
b3PogoJoint* joint = &sim->pogoJoint;
|
||||
linearImpulse = b3AbsFloat( joint->impulse );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -1161,6 +1250,12 @@ static b3Vec3 b3GetJointConstraintForce( b3World* world, b3Joint* joint )
|
|||
case b3_wheelJoint:
|
||||
return b3GetWheelJointForce( world, base );
|
||||
|
||||
case b3_moverJoint:
|
||||
return b3GetMoverJointForce( world, base );
|
||||
|
||||
case b3_pogoJoint:
|
||||
return b3GetPogoJointForce( world, base );
|
||||
|
||||
default:
|
||||
B3_ASSERT( false );
|
||||
return b3Vec3_zero;
|
||||
|
|
@ -1200,6 +1295,10 @@ static b3Vec3 b3GetJointConstraintTorque( b3World* world, b3Joint* joint )
|
|||
case b3_wheelJoint:
|
||||
return b3GetWheelJointTorque( world, base );
|
||||
|
||||
case b3_moverJoint:
|
||||
case b3_pogoJoint:
|
||||
return b3Vec3_zero;
|
||||
|
||||
default:
|
||||
B3_ASSERT( false );
|
||||
return b3Vec3_zero;
|
||||
|
|
@ -1268,6 +1367,12 @@ float b3Joint_GetLinearSeparation( b3JointId jointId )
|
|||
case b3_motorJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_moverJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_pogoJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_filterJoint:
|
||||
return 0.0f;
|
||||
|
||||
|
|
@ -1370,6 +1475,12 @@ float b3Joint_GetAngularSeparation( b3JointId jointId )
|
|||
case b3_motorJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_moverJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_pogoJoint:
|
||||
return 0.0f;
|
||||
|
||||
case b3_filterJoint:
|
||||
return 0.0f;
|
||||
|
||||
|
|
@ -1522,6 +1633,14 @@ void b3PrepareJoint( b3JointSim* joint, b3StepContext* context )
|
|||
b3PrepareWheelJoint( joint, context );
|
||||
break;
|
||||
|
||||
case b3_moverJoint:
|
||||
b3PrepareMoverJoint( joint, context );
|
||||
break;
|
||||
|
||||
case b3_pogoJoint:
|
||||
b3PreparePogoJoint( joint, context );
|
||||
break;
|
||||
|
||||
default:
|
||||
B3_ASSERT( false );
|
||||
}
|
||||
|
|
@ -1566,6 +1685,14 @@ void b3WarmStartJoint( b3JointSim* joint, b3StepContext* context )
|
|||
b3WarmStartWheelJoint( joint, context );
|
||||
break;
|
||||
|
||||
case b3_moverJoint:
|
||||
b3WarmStartMoverJoint( joint, context );
|
||||
break;
|
||||
|
||||
case b3_pogoJoint:
|
||||
b3WarmStartPogoJoint( joint, context );
|
||||
break;
|
||||
|
||||
default:
|
||||
B3_ASSERT( false );
|
||||
}
|
||||
|
|
@ -1612,6 +1739,14 @@ void b3SolveJoint( b3JointSim* joint, b3StepContext* context, bool useBias )
|
|||
b3SolveWheelJoint( joint, context, useBias );
|
||||
break;
|
||||
|
||||
case b3_moverJoint:
|
||||
b3SolveMoverJoint( joint, context );
|
||||
break;
|
||||
|
||||
case b3_pogoJoint:
|
||||
b3SolvePogoJoint( joint, context, useBias );
|
||||
break;
|
||||
|
||||
default:
|
||||
B3_ASSERT( false );
|
||||
}
|
||||
|
|
@ -1728,6 +1863,14 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint )
|
|||
b3DrawWheelJoint( draw, jointSim, transformA, transformB, scale );
|
||||
break;
|
||||
|
||||
case b3_moverJoint:
|
||||
draw->DrawPointFcn( pB, 8.0f, b3_colorPlum, draw->context );
|
||||
break;
|
||||
|
||||
case b3_pogoJoint:
|
||||
draw->DrawSegmentFcn( pA, pB, b3_colorLightGray, draw->context );
|
||||
break;
|
||||
|
||||
default:
|
||||
draw->DrawSegmentFcn( transformA.p, pA, color, draw->context );
|
||||
draw->DrawSegmentFcn( pA, pB, color, draw->context );
|
||||
|
|
|
|||
41
src/joint.h
41
src/joint.h
|
|
@ -121,6 +121,37 @@ typedef struct b3MotorJoint
|
|||
b3Matrix3 angularMass;
|
||||
} b3MotorJoint;
|
||||
|
||||
typedef struct b3MoverJoint
|
||||
{
|
||||
b3Vec3 linearVelocity;
|
||||
b3Vec3 maxVelocityForce;
|
||||
|
||||
b3Vec3 linearVelocityImpulse;
|
||||
|
||||
int indexA;
|
||||
int indexB;
|
||||
float linearMass;
|
||||
} b3MoverJoint;
|
||||
|
||||
typedef struct b3PogoJoint
|
||||
{
|
||||
b3Vec3 normal;
|
||||
float restLength;
|
||||
float hertz;
|
||||
float dampingRatio;
|
||||
float maxTensionForce;
|
||||
float maxCompressionForce;
|
||||
|
||||
float impulse;
|
||||
int indexA;
|
||||
int indexB;
|
||||
b3Transform frameA;
|
||||
b3Transform frameB;
|
||||
b3Vec3 deltaCenter;
|
||||
float linearMass;
|
||||
float velocity;
|
||||
} b3PogoJoint;
|
||||
|
||||
typedef struct b3ParallelJoint
|
||||
{
|
||||
float hertz;
|
||||
|
|
@ -336,7 +367,9 @@ typedef struct b3JointSim
|
|||
{
|
||||
b3DistanceJoint distanceJoint;
|
||||
b3MotorJoint motorJoint;
|
||||
b3MoverJoint moverJoint;
|
||||
b3ParallelJoint parallelJoint;
|
||||
b3PogoJoint pogoJoint;
|
||||
b3RevoluteJoint revoluteJoint;
|
||||
b3SphericalJoint sphericalJoint;
|
||||
b3PrismaticJoint prismaticJoint;
|
||||
|
|
@ -365,6 +398,8 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint );
|
|||
|
||||
b3Vec3 b3GetDistanceJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetMotorJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetMoverJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetPogoJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetPrismaticJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetRevoluteJointForce( b3World* world, b3JointSim* base );
|
||||
b3Vec3 b3GetSphericalJointForce( b3World* world, b3JointSim* base );
|
||||
|
|
@ -381,6 +416,8 @@ b3Vec3 b3GetWheelJointTorque( b3World* world, b3JointSim* base );
|
|||
|
||||
void b3PrepareDistanceJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PrepareMotorJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PrepareMoverJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PreparePogoJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PrepareParallelJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PreparePrismaticJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context );
|
||||
|
|
@ -390,6 +427,8 @@ void b3PrepareWheelJoint( b3JointSim* base, b3StepContext* context );
|
|||
|
||||
void b3WarmStartDistanceJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartMotorJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartMoverJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartPogoJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartParallelJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartPrismaticJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3WarmStartRevoluteJoint( b3JointSim* base, b3StepContext* context );
|
||||
|
|
@ -399,6 +438,8 @@ void b3WarmStartWheelJoint( b3JointSim* base, b3StepContext* context );
|
|||
|
||||
void b3SolveDistanceJoint( b3JointSim* base, b3StepContext* context, bool useBias );
|
||||
void b3SolveMotorJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3SolveMoverJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3SolvePogoJoint( b3JointSim* base, b3StepContext* context, bool useBias );
|
||||
void b3SolveParallelJoint( b3JointSim* base, b3StepContext* context );
|
||||
void b3SolvePrismaticJoint( b3JointSim* base, b3StepContext* context, bool useBias );
|
||||
void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBias );
|
||||
|
|
|
|||
173
src/mover_joint.c
Normal file
173
src/mover_joint.c
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "body.h"
|
||||
#include "core.h"
|
||||
#include "joint.h"
|
||||
#include "math_internal.h"
|
||||
#include "physics_world.h"
|
||||
#include "recording.h"
|
||||
#include "solver.h"
|
||||
#include "solver_set.h"
|
||||
|
||||
// needed for dll export
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
void b3MoverJoint_SetLinearVelocity( b3JointId jointId, b3Vec3 velocity )
|
||||
{
|
||||
B3_ASSERT( b3IsValidVec3( velocity ) );
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, MoverJointSetLinearVelocity, jointId, velocity );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint );
|
||||
joint->moverJoint.linearVelocity = velocity;
|
||||
}
|
||||
|
||||
b3Vec3 b3MoverJoint_GetLinearVelocity( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint );
|
||||
return joint->moverJoint.linearVelocity;
|
||||
}
|
||||
|
||||
void b3MoverJoint_SetMaxVelocityForce( b3JointId jointId, b3Vec3 maxForce )
|
||||
{
|
||||
B3_ASSERT( b3IsValidVec3( maxForce ) );
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, MoverJointSetMaxVelocityForce, jointId, maxForce );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint );
|
||||
joint->moverJoint.maxVelocityForce = maxForce;
|
||||
}
|
||||
|
||||
b3Vec3 b3MoverJoint_GetMaxVelocityForce( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint );
|
||||
return joint->moverJoint.maxVelocityForce;
|
||||
}
|
||||
|
||||
b3Vec3 b3GetMoverJointForce( b3World* world, b3JointSim* base )
|
||||
{
|
||||
return b3MulSV( world->inv_h, base->moverJoint.linearVelocityImpulse );
|
||||
}
|
||||
|
||||
void b3PrepareMoverJoint( b3JointSim* base, b3StepContext* context )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_moverJoint );
|
||||
|
||||
int idA = base->bodyIdA;
|
||||
int idB = base->bodyIdB;
|
||||
|
||||
b3World* world = context->world;
|
||||
|
||||
b3Body* bodyA = b3Array_Get( world->bodies, idA );
|
||||
b3Body* bodyB = b3Array_Get( world->bodies, idB );
|
||||
|
||||
B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet );
|
||||
|
||||
b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex );
|
||||
b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex );
|
||||
|
||||
int localIndexA = bodyA->localIndex;
|
||||
int localIndexB = bodyB->localIndex;
|
||||
|
||||
b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA );
|
||||
b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB );
|
||||
|
||||
float mA = bodySimA->invMass;
|
||||
float mB = bodySimB->invMass;
|
||||
|
||||
base->invMassA = mA;
|
||||
base->invMassB = mB;
|
||||
base->invIA = b3Mat3_zero;
|
||||
base->invIB = b3Mat3_zero;
|
||||
|
||||
b3MoverJoint* joint = &base->moverJoint;
|
||||
joint->indexA = bodyA->setIndex == b3_awakeSet ? localIndexA : B3_NULL_INDEX;
|
||||
joint->indexB = bodyB->setIndex == b3_awakeSet ? localIndexB : B3_NULL_INDEX;
|
||||
|
||||
float k = mA + mB;
|
||||
joint->linearMass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||
|
||||
if ( context->enableWarmStarting == false )
|
||||
{
|
||||
joint->linearVelocityImpulse = b3Vec3_zero;
|
||||
}
|
||||
}
|
||||
|
||||
void b3WarmStartMoverJoint( b3JointSim* base, b3StepContext* context )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_moverJoint );
|
||||
|
||||
float mA = base->invMassA;
|
||||
float mB = base->invMassB;
|
||||
|
||||
b3MoverJoint* joint = &base->moverJoint;
|
||||
|
||||
// dummy state for static bodies
|
||||
b3BodyState dummyState = b3_identityBodyState;
|
||||
|
||||
b3BodyState* stateA =
|
||||
joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA;
|
||||
b3BodyState* stateB =
|
||||
joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB;
|
||||
|
||||
if ( stateA->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateA->linearVelocity =
|
||||
b3MulSub( stateA->linearVelocity, mA, joint->linearVelocityImpulse );
|
||||
}
|
||||
|
||||
if ( stateB->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateB->linearVelocity =
|
||||
b3MulAdd( stateB->linearVelocity, mB, joint->linearVelocityImpulse );
|
||||
}
|
||||
}
|
||||
|
||||
void b3SolveMoverJoint( b3JointSim* base, b3StepContext* context )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_moverJoint );
|
||||
|
||||
float mA = base->invMassA;
|
||||
float mB = base->invMassB;
|
||||
|
||||
// dummy state for static bodies
|
||||
b3BodyState dummyState = b3_identityBodyState;
|
||||
|
||||
b3MoverJoint* joint = &base->moverJoint;
|
||||
b3BodyState* stateA =
|
||||
joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA;
|
||||
b3BodyState* stateB =
|
||||
joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB;
|
||||
|
||||
b3Vec3 vA = stateA->linearVelocity;
|
||||
b3Vec3 vB = stateB->linearVelocity;
|
||||
|
||||
b3Vec3 maxForce = joint->maxVelocityForce;
|
||||
if ( maxForce.x > 0.0f || maxForce.y > 0.0f || maxForce.z > 0.0f )
|
||||
{
|
||||
b3Vec3 cdot = b3Sub( b3Sub( vB, vA ), joint->linearVelocity );
|
||||
b3Vec3 impulse = b3MulSV( -joint->linearMass, cdot );
|
||||
|
||||
b3Vec3 oldImpulse = joint->linearVelocityImpulse;
|
||||
b3Vec3 maxImpulse = b3MulSV( context->h, maxForce );
|
||||
joint->linearVelocityImpulse =
|
||||
b3Clamp( b3Add( oldImpulse, impulse ), b3Neg( maxImpulse ), maxImpulse );
|
||||
impulse = b3Sub( joint->linearVelocityImpulse, oldImpulse );
|
||||
|
||||
vA = b3MulSub( vA, mA, impulse );
|
||||
vB = b3MulAdd( vB, mB, impulse );
|
||||
}
|
||||
else
|
||||
{
|
||||
joint->linearVelocityImpulse = b3Vec3_zero;
|
||||
}
|
||||
|
||||
if ( stateA->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateA->linearVelocity = vA;
|
||||
}
|
||||
|
||||
if ( stateB->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateB->linearVelocity = vB;
|
||||
}
|
||||
}
|
||||
281
src/pogo_joint.c
Normal file
281
src/pogo_joint.c
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "body.h"
|
||||
#include "core.h"
|
||||
#include "joint.h"
|
||||
#include "math_internal.h"
|
||||
#include "physics_world.h"
|
||||
#include "recording.h"
|
||||
#include "solver.h"
|
||||
#include "solver_set.h"
|
||||
|
||||
// needed for dll export
|
||||
#include "box3d/box3d.h"
|
||||
|
||||
void b3PogoJoint_SetRestLength( b3JointId jointId, float length )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( length ) && length >= 0.0f );
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetRestLength, jointId, length );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.restLength = length;
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetRestLength( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
return joint->pogoJoint.restLength;
|
||||
}
|
||||
|
||||
void b3PogoJoint_SetSpringHertz( b3JointId jointId, float hertz )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( hertz ) && hertz >= 0.0f );
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetSpringHertz, jointId, hertz );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.hertz = hertz;
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetSpringHertz( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
return joint->pogoJoint.hertz;
|
||||
}
|
||||
|
||||
void b3PogoJoint_SetSpringDampingRatio( b3JointId jointId, float dampingRatio )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( dampingRatio ) && dampingRatio >= 0.0f );
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetSpringDampingRatio, jointId, dampingRatio );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.dampingRatio = dampingRatio;
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetSpringDampingRatio( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
return joint->pogoJoint.dampingRatio;
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetCurrentLength( b3JointId jointId )
|
||||
{
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
b3JointSim* base = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
|
||||
b3WorldTransform worldTransformA = b3GetBodyTransform( world, base->bodyIdA );
|
||||
b3Transform transformA = b3ToRelativeTransform( worldTransformA, worldTransformA.p );
|
||||
b3Transform transformB =
|
||||
b3ToRelativeTransform( b3GetBodyTransform( world, base->bodyIdB ), worldTransformA.p );
|
||||
|
||||
b3Vec3 axis = b3RotateVector( b3MulQuat( transformB.q, base->localFrameB.q ), b3Vec3_axisY );
|
||||
b3Vec3 pA = b3TransformPoint( transformA, base->localFrameA.p );
|
||||
b3Vec3 pB = b3TransformPoint( transformB, base->localFrameB.p );
|
||||
return b3Dot( b3Sub( pB, pA ), axis );
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetImpulse( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
return joint->pogoJoint.impulse;
|
||||
}
|
||||
|
||||
float b3PogoJoint_GetCurrentSpeed( b3JointId jointId )
|
||||
{
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
return joint->pogoJoint.velocity;
|
||||
}
|
||||
|
||||
b3Vec3 b3GetPogoJointForce( b3World* world, b3JointSim* base )
|
||||
{
|
||||
return b3MulSV( world->inv_h * base->pogoJoint.impulse, base->pogoJoint.normal );
|
||||
}
|
||||
|
||||
void b3PreparePogoJoint( b3JointSim* base, b3StepContext* context )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_pogoJoint );
|
||||
|
||||
b3World* world = context->world;
|
||||
|
||||
// chase body id to the solver set where the body lives
|
||||
int idA = base->bodyIdA;
|
||||
int idB = base->bodyIdB;
|
||||
|
||||
b3Body* bodyA = b3Array_Get( world->bodies, idA );
|
||||
b3Body* bodyB = b3Array_Get( world->bodies, idB );
|
||||
|
||||
B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet );
|
||||
|
||||
b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex );
|
||||
b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex );
|
||||
|
||||
int localIndexA = bodyA->localIndex;
|
||||
int localIndexB = bodyB->localIndex;
|
||||
|
||||
b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA );
|
||||
b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB );
|
||||
|
||||
float mA = bodySimA->invMass;
|
||||
float mB = bodySimB->invMass;
|
||||
b3Matrix3 iA = bodySimA->invInertiaWorld;
|
||||
b3Matrix3 iB = bodySimB->invInertiaWorld;
|
||||
|
||||
base->invMassA = mA;
|
||||
base->invMassB = mB;
|
||||
base->invIA = iA;
|
||||
base->invIB = iB;
|
||||
|
||||
b3PogoJoint* joint = &base->pogoJoint;
|
||||
joint->indexA = bodyA->setIndex == b3_awakeSet ? localIndexA : B3_NULL_INDEX;
|
||||
joint->indexB = bodyB->setIndex == b3_awakeSet ? localIndexB : B3_NULL_INDEX;
|
||||
|
||||
// Compute joint anchor frames with world space rotation, relative to center of mass
|
||||
joint->frameA.q = b3MulQuat( bodySimA->transform.q, base->localFrameA.q );
|
||||
joint->frameA.p = b3RotateVector( bodySimA->transform.q,
|
||||
b3Sub( base->localFrameA.p, bodySimA->localCenter ) );
|
||||
joint->frameB.q = b3MulQuat( bodySimB->transform.q, base->localFrameB.q );
|
||||
joint->frameB.p = b3RotateVector( bodySimB->transform.q,
|
||||
b3Sub( base->localFrameB.p, bodySimB->localCenter ) );
|
||||
|
||||
// Compute the initial center delta. Incremental position updates are relative to this.
|
||||
joint->deltaCenter = b3SubPos( bodySimB->center, bodySimA->center );
|
||||
|
||||
b3Vec3 rnA = b3Cross( joint->frameA.p, joint->normal );
|
||||
b3Vec3 rnB = b3Cross( joint->frameB.p, joint->normal );
|
||||
float k = mA + mB + b3Dot( rnA, b3MulMV( iA, rnA ) ) + b3Dot( rnB, b3MulMV( iB, rnB ) );
|
||||
joint->linearMass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||
|
||||
if ( context->enableWarmStarting == false )
|
||||
{
|
||||
joint->impulse = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void b3WarmStartPogoJoint( b3JointSim* base, b3StepContext* context )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_pogoJoint );
|
||||
|
||||
float mA = base->invMassA;
|
||||
float mB = base->invMassB;
|
||||
b3Matrix3 iA = base->invIA;
|
||||
b3Matrix3 iB = base->invIB;
|
||||
|
||||
b3PogoJoint* joint = &base->pogoJoint;
|
||||
|
||||
if ( joint->hertz == 0.0f )
|
||||
{
|
||||
joint->impulse = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
// dummy state for static bodies
|
||||
b3BodyState dummyState = b3_identityBodyState;
|
||||
|
||||
b3BodyState* stateA =
|
||||
joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA;
|
||||
b3BodyState* stateB =
|
||||
joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB;
|
||||
|
||||
b3Vec3 rA = b3RotateVector( stateA->deltaRotation, joint->frameA.p );
|
||||
b3Vec3 rB = b3RotateVector( stateB->deltaRotation, joint->frameB.p );
|
||||
|
||||
b3Vec3 linearImpulse = b3MulSV( joint->impulse, joint->normal );
|
||||
|
||||
if ( stateA->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateA->linearVelocity = b3MulSub( stateA->linearVelocity, mA, linearImpulse );
|
||||
stateA->angularVelocity =
|
||||
b3Sub( stateA->angularVelocity, b3MulMV( iA, b3Cross( rA, linearImpulse ) ) );
|
||||
}
|
||||
|
||||
if ( stateB->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateB->linearVelocity = b3MulAdd( stateB->linearVelocity, mB, linearImpulse );
|
||||
stateB->angularVelocity =
|
||||
b3Add( stateB->angularVelocity, b3MulMV( iB, b3Cross( rB, linearImpulse ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
void b3SolvePogoJoint( b3JointSim* base, b3StepContext* context, bool useBias )
|
||||
{
|
||||
B3_ASSERT( base->type == b3_pogoJoint );
|
||||
|
||||
float mA = base->invMassA;
|
||||
float mB = base->invMassB;
|
||||
b3Matrix3 iA = base->invIA;
|
||||
b3Matrix3 iB = base->invIB;
|
||||
|
||||
// dummy state for static bodies
|
||||
b3BodyState dummyState = b3_identityBodyState;
|
||||
|
||||
b3PogoJoint* joint = &base->pogoJoint;
|
||||
if ( joint->hertz == 0.0f )
|
||||
{
|
||||
joint->impulse = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
b3BodyState* stateA =
|
||||
joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA;
|
||||
b3BodyState* stateB =
|
||||
joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB;
|
||||
|
||||
b3Vec3 vA = stateA->linearVelocity;
|
||||
b3Vec3 wA = stateA->angularVelocity;
|
||||
b3Vec3 vB = stateB->linearVelocity;
|
||||
b3Vec3 wB = stateB->angularVelocity;
|
||||
|
||||
b3Vec3 rA = b3RotateVector( stateA->deltaRotation, joint->frameA.p );
|
||||
b3Vec3 rB = b3RotateVector( stateB->deltaRotation, joint->frameB.p );
|
||||
|
||||
float bias = 0.0f;
|
||||
if ( useBias )
|
||||
{
|
||||
// This is a custom pogo position correction designed to avoid feeding velocity into
|
||||
// the mover body. Otherwise the mover can make huge jumps going up stairs. This still
|
||||
// works with continuous collision.
|
||||
|
||||
b3Vec3 dcA = stateA->deltaPosition;
|
||||
b3Vec3 dcB = stateB->deltaPosition;
|
||||
b3Vec3 d = b3Add( b3Add( b3Sub( dcB, dcA ), b3Sub( rB, rA ) ), joint->deltaCenter );
|
||||
|
||||
// The pogo axis is usually fixed as the world y-axis. Different than the ground normal.
|
||||
b3Vec3 pogoAxis = b3RotateVector( joint->frameB.q, b3Vec3_axisY );
|
||||
float c = b3Dot( pogoAxis, d ) - joint->restLength;
|
||||
|
||||
// This could be divided by dot(joint->normal, pogoAxis) to account for the constraint
|
||||
// direction, but I'd rather diminish the pogo recovery rate than risk making it huge.
|
||||
joint->velocity =
|
||||
b3SpringDamper( joint->hertz, joint->dampingRatio, c, joint->velocity, context->h );
|
||||
bias = -joint->velocity;
|
||||
}
|
||||
|
||||
b3Vec3 vr = b3Sub( b3Add( vB, b3Cross( wB, rB ) ), b3Add( vA, b3Cross( wA, rA ) ) );
|
||||
float cdot = b3Dot( joint->normal, vr );
|
||||
|
||||
float maxTensionImpulse = context->h * joint->maxTensionForce;
|
||||
float maxCompressionImpulse = context->h * joint->maxCompressionForce;
|
||||
float oldImpulse = joint->impulse;
|
||||
float impulse = -joint->linearMass * ( cdot + bias );
|
||||
joint->impulse =
|
||||
b3ClampFloat( joint->impulse + impulse, -maxTensionImpulse, maxCompressionImpulse );
|
||||
impulse = joint->impulse - oldImpulse;
|
||||
|
||||
b3Vec3 P = b3MulSV( impulse, joint->normal );
|
||||
vA = b3MulSub( vA, mA, P );
|
||||
wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, P ) ) );
|
||||
vB = b3MulAdd( vB, mB, P );
|
||||
wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, P ) ) );
|
||||
|
||||
if ( stateA->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateA->linearVelocity = vA;
|
||||
stateA->angularVelocity = wA;
|
||||
}
|
||||
|
||||
if ( stateB->flags & b3_dynamicFlag )
|
||||
{
|
||||
stateB->linearVelocity = vB;
|
||||
stateB->angularVelocity = wB;
|
||||
}
|
||||
}
|
||||
|
|
@ -342,6 +342,10 @@ _Static_assert( sizeof( void* ) != 8 || sizeof( b3WeldJointDef ) == 128,
|
|||
"b3WeldJointDef changed: update b3RecW_WELDJOINTDEF and its reader together" );
|
||||
_Static_assert( sizeof( void* ) != 8 || sizeof( b3WheelJointDef ) == 184,
|
||||
"b3WheelJointDef changed: update b3RecW_WHEELJOINTDEF and its reader together" );
|
||||
_Static_assert( sizeof( void* ) != 8 || sizeof( b3MoverJointDef ) == 136,
|
||||
"b3MoverJointDef changed: update b3RecW_MOVERJOINTDEF and its reader together" );
|
||||
_Static_assert( sizeof( void* ) != 8 || sizeof( b3PogoJointDef ) == 152,
|
||||
"b3PogoJointDef changed: update b3RecW_POGOJOINTDEF and its reader together" );
|
||||
|
||||
void b3RecW_EXPLOSIONDEF( b3RecBuffer* buf, b3ExplosionDef v )
|
||||
{
|
||||
|
|
@ -548,6 +552,26 @@ void b3RecW_WHEELJOINTDEF( b3RecBuffer* buf, b3WheelJointDef v )
|
|||
b3RecW_F32( buf, v.upperSteeringLimit );
|
||||
}
|
||||
|
||||
void b3RecW_MOVERJOINTDEF( b3RecBuffer* buf, b3MoverJointDef v )
|
||||
{
|
||||
b3RecW_JointBase( buf, &v.base );
|
||||
b3RecW_VEC3( buf, v.linearVelocity );
|
||||
b3RecW_VEC3( buf, v.maxVelocityForce );
|
||||
}
|
||||
|
||||
void b3RecW_POGOJOINTDEF( b3RecBuffer* buf, b3PogoJointDef v )
|
||||
{
|
||||
b3RecW_JointBase( buf, &v.base );
|
||||
b3RecW_VEC3( buf, v.normal );
|
||||
b3RecW_F32( buf, v.hertz );
|
||||
b3RecW_F32( buf, v.dampingRatio );
|
||||
b3RecW_F32( buf, v.restLength );
|
||||
b3RecW_F32( buf, v.maxTensionForce );
|
||||
b3RecW_F32( buf, v.maxCompressionForce );
|
||||
b3RecW_F32( buf, v.impulse );
|
||||
b3RecW_F32( buf, v.velocity );
|
||||
}
|
||||
|
||||
// Query recording. A query collects a variable number of hits through a user callback, so the count
|
||||
// is not known until the callback stops firing. The record is built in a local buffer with a
|
||||
// reserved hit-count slot, then committed whole under the lock so concurrent query threads never
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ typedef struct b3World b3World;
|
|||
|
||||
// Minor tracks op-stream additions that keep the 48 byte header shape.
|
||||
// Minor version 7 made the contact body sim locators persistent
|
||||
#define B3_REC_VERSION_MINOR 9
|
||||
#define B3_REC_VERSION_MINOR 10
|
||||
|
||||
// File header, fixed 48 bytes. Contains the registry locator so the player
|
||||
// can load geometry before replaying any ops.
|
||||
|
|
@ -196,6 +196,8 @@ typedef b3RevoluteJointDef b3RecCType_REVOLUTEJOINTDEF;
|
|||
typedef b3SphericalJointDef b3RecCType_SPHERICALJOINTDEF;
|
||||
typedef b3WeldJointDef b3RecCType_WELDJOINTDEF;
|
||||
typedef b3WheelJointDef b3RecCType_WHEELJOINTDEF;
|
||||
typedef b3MoverJointDef b3RecCType_MOVERJOINTDEF;
|
||||
typedef b3PogoJointDef b3RecCType_POGOJOINTDEF;
|
||||
|
||||
// Codegen pass 1a: arg structs. Generated here so call sites (body.c, shape.c, etc.) can see them.
|
||||
#define ARG( TAG, field ) b3RecCType_##TAG field;
|
||||
|
|
@ -266,6 +268,8 @@ void b3RecW_REVOLUTEJOINTDEF( b3RecBuffer* buf, b3RevoluteJointDef v );
|
|||
void b3RecW_SPHERICALJOINTDEF( b3RecBuffer* buf, b3SphericalJointDef v );
|
||||
void b3RecW_WELDJOINTDEF( b3RecBuffer* buf, b3WeldJointDef v );
|
||||
void b3RecW_WHEELJOINTDEF( b3RecBuffer* buf, b3WheelJointDef v );
|
||||
void b3RecW_MOVERJOINTDEF( b3RecBuffer* buf, b3MoverJointDef v );
|
||||
void b3RecW_POGOJOINTDEF( b3RecBuffer* buf, b3PogoJointDef v );
|
||||
|
||||
// Record framing
|
||||
void b3RecBeginRecord( b3Recording* rec, uint8_t opcode );
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// 0x40-0x4F shape create/destroy
|
||||
// 0x50-0x6F shape mutators
|
||||
// 0x80 step
|
||||
// 0x81-0x8F mover and pogo joints
|
||||
// 0x90-0xE7 joints (create, generic, per-type)
|
||||
// 0xE8-0xEF spatial queries
|
||||
// 0xF0-0xFF markers
|
||||
|
|
@ -211,6 +212,17 @@ B3_REC_OP( 0xE5, WheelJointEnableSteeringLimit, RET_NONE, ARG( JOINTID, joint )
|
|||
B3_REC_OP( 0xE6, WheelJointSetSteeringLimits, RET_NONE, ARG( JOINTID, joint ) ARG( F32, lower ) ARG( F32, upper ) )
|
||||
B3_REC_OP( 0xE7, WheelJointSetTargetSteeringAngle, RET_NONE, ARG( JOINTID, joint ) ARG( F32, radians ) )
|
||||
|
||||
// Mover joint
|
||||
B3_REC_OP( 0x81, CreateMoverJoint, RET_JOINTID, ARG( WORLDID, world ) ARG( MOVERJOINTDEF, def ) )
|
||||
B3_REC_OP( 0x82, MoverJointSetLinearVelocity, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, velocity ) )
|
||||
B3_REC_OP( 0x83, MoverJointSetMaxVelocityForce, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, maxForce ) )
|
||||
|
||||
// Pogo joint
|
||||
B3_REC_OP( 0x84, CreatePogoJoint, RET_JOINTID, ARG( WORLDID, world ) ARG( POGOJOINTDEF, def ) )
|
||||
B3_REC_OP( 0x85, PogoJointSetRestLength, RET_NONE, ARG( JOINTID, joint ) ARG( F32, length ) )
|
||||
B3_REC_OP( 0x86, PogoJointSetSpringHertz, RET_NONE, ARG( JOINTID, joint ) ARG( F32, hertz ) )
|
||||
B3_REC_OP( 0x87, PogoJointSetSpringDampingRatio, RET_NONE, ARG( JOINTID, joint ) ARG( F32, dampingRatio ) )
|
||||
|
||||
// Spatial queries. Inputs flow through the manifest (reader side). The hit tail and result are
|
||||
// hand-written in recording.c / recording_replay.c since they are variable length.
|
||||
B3_REC_OP( 0xE8, QueryOverlapAABB, RET_NONE, ARG( WORLDID, world ) ARG( AABB, aabb ) ARG( QUERYFILTER, filter ) )
|
||||
|
|
|
|||
72
src/replay.c
72
src/replay.c
|
|
@ -649,6 +649,30 @@ b3WheelJointDef b3RecR_WHEELJOINTDEF( b3RecReader* rdr )
|
|||
return def;
|
||||
}
|
||||
|
||||
b3MoverJointDef b3RecR_MOVERJOINTDEF( b3RecReader* rdr )
|
||||
{
|
||||
b3MoverJointDef def = b3DefaultMoverJointDef();
|
||||
b3RecR_JointBase( rdr, &def.base );
|
||||
def.linearVelocity = b3RecR_VEC3( rdr );
|
||||
def.maxVelocityForce = b3RecR_VEC3( rdr );
|
||||
return def;
|
||||
}
|
||||
|
||||
b3PogoJointDef b3RecR_POGOJOINTDEF( b3RecReader* rdr )
|
||||
{
|
||||
b3PogoJointDef def = b3DefaultPogoJointDef();
|
||||
b3RecR_JointBase( rdr, &def.base );
|
||||
def.normal = b3RecR_VEC3( rdr );
|
||||
def.hertz = b3RecR_F32( rdr );
|
||||
def.dampingRatio = b3RecR_F32( rdr );
|
||||
def.restLength = b3RecR_F32( rdr );
|
||||
def.maxTensionForce = b3RecR_F32( rdr );
|
||||
def.maxCompressionForce = b3RecR_F32( rdr );
|
||||
def.impulse = b3RecR_F32( rdr );
|
||||
def.velocity = b3RecR_F32( rdr );
|
||||
return def;
|
||||
}
|
||||
|
||||
// Outliner body tracking. Defined after the player struct; forward declared here because the
|
||||
// create/destroy dispatch sits above that struct.
|
||||
static void b3RecTrackBodyCreate( b3RecPlayer* player, b3BodyId id );
|
||||
|
|
@ -1262,6 +1286,24 @@ static void b3RecDispatch_CreateWheelJoint( const b3RecArgs_CreateWheelJoint* a,
|
|||
b3RecCheckJointId( rdr, b3CreateWheelJoint( rdr->replayWorldId, &def ), recId );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_CreateMoverJoint( const b3RecArgs_CreateMoverJoint* a, b3RecReader* rdr )
|
||||
{
|
||||
b3JointId recId = b3RecR_JOINTID( rdr );
|
||||
b3MoverJointDef def = a->def;
|
||||
def.base.bodyIdA = b3RecMakeBodyId( rdr, def.base.bodyIdA );
|
||||
def.base.bodyIdB = b3RecMakeBodyId( rdr, def.base.bodyIdB );
|
||||
b3RecCheckJointId( rdr, b3CreateMoverJoint( rdr->replayWorldId, &def ), recId );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_CreatePogoJoint( const b3RecArgs_CreatePogoJoint* a, b3RecReader* rdr )
|
||||
{
|
||||
b3JointId recId = b3RecR_JOINTID( rdr );
|
||||
b3PogoJointDef def = a->def;
|
||||
def.base.bodyIdA = b3RecMakeBodyId( rdr, def.base.bodyIdA );
|
||||
def.base.bodyIdB = b3RecMakeBodyId( rdr, def.base.bodyIdB );
|
||||
b3RecCheckJointId( rdr, b3CreatePogoJoint( rdr->replayWorldId, &def ), recId );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_DestroyJoint( const b3RecArgs_DestroyJoint* a, b3RecReader* rdr )
|
||||
{
|
||||
b3DestroyJoint( b3RecMakeJointId( rdr, a->joint ), a->wakeAttached );
|
||||
|
|
@ -1668,6 +1710,36 @@ static void b3RecDispatch_WheelJointSetTargetSteeringAngle( const b3RecArgs_Whee
|
|||
b3WheelJoint_SetTargetSteeringAngle( b3RecMakeJointId( rdr, a->joint ), a->radians );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_MoverJointSetLinearVelocity(
|
||||
const b3RecArgs_MoverJointSetLinearVelocity* a, b3RecReader* rdr )
|
||||
{
|
||||
b3MoverJoint_SetLinearVelocity( b3RecMakeJointId( rdr, a->joint ), a->velocity );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_MoverJointSetMaxVelocityForce(
|
||||
const b3RecArgs_MoverJointSetMaxVelocityForce* a, b3RecReader* rdr )
|
||||
{
|
||||
b3MoverJoint_SetMaxVelocityForce( b3RecMakeJointId( rdr, a->joint ), a->maxForce );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_PogoJointSetRestLength( const b3RecArgs_PogoJointSetRestLength* a,
|
||||
b3RecReader* rdr )
|
||||
{
|
||||
b3PogoJoint_SetRestLength( b3RecMakeJointId( rdr, a->joint ), a->length );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_PogoJointSetSpringHertz( const b3RecArgs_PogoJointSetSpringHertz* a,
|
||||
b3RecReader* rdr )
|
||||
{
|
||||
b3PogoJoint_SetSpringHertz( b3RecMakeJointId( rdr, a->joint ), a->hertz );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_PogoJointSetSpringDampingRatio(
|
||||
const b3RecArgs_PogoJointSetSpringDampingRatio* a, b3RecReader* rdr )
|
||||
{
|
||||
b3PogoJoint_SetSpringDampingRatio( b3RecMakeJointId( rdr, a->joint ), a->dampingRatio );
|
||||
}
|
||||
|
||||
static void b3RecDispatch_StateHash( const b3RecArgs_StateHash* a, b3RecReader* rdr )
|
||||
{
|
||||
b3World* world = b3GetWorldFromId( rdr->replayWorldId );
|
||||
|
|
|
|||
|
|
@ -246,6 +246,8 @@ b3RevoluteJointDef b3RecR_REVOLUTEJOINTDEF( b3RecReader* rdr );
|
|||
b3SphericalJointDef b3RecR_SPHERICALJOINTDEF( b3RecReader* rdr );
|
||||
b3WeldJointDef b3RecR_WELDJOINTDEF( b3RecReader* rdr );
|
||||
b3WheelJointDef b3RecR_WHEELJOINTDEF( b3RecReader* rdr );
|
||||
b3MoverJointDef b3RecR_MOVERJOINTDEF( b3RecReader* rdr );
|
||||
b3PogoJointDef b3RecR_POGOJOINTDEF( b3RecReader* rdr );
|
||||
b3QueryFilter b3RecR_QUERYFILTER( b3RecReader* rdr );
|
||||
b3ShapeProxy b3RecR_SHAPEPROXY( b3RecReader* rdr );
|
||||
b3TreeStats b3RecR_TREESTATS( b3RecReader* rdr );
|
||||
|
|
|
|||
Loading…
Reference in a new issue