Dynamic Mover (#202)

Port the dynamic character mover from Box2D including the mover joint
and pogo joint.

Match the mover and sample structure of Box2D.
This commit is contained in:
Erin Catto 2026-10-27 22:33:17 -07:00 • committed by GitHub
commit 3362633204
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 4580 additions and 885 deletions

View file

@ -122,6 +122,10 @@ typedef struct
bool transparentDynamic;
bool transparentKinematic;
// One body drawn with reduced alpha, such as a character the camera is close to
b3BodyId alphaBodyId;
float bodyAlpha;
// View box for compound child culling, world space, refreshed once per frame.
b3AABB viewBounds;
bool hasViewBounds;
@ -158,6 +162,8 @@ void InitAdapter( void )
s_adapter.selectedShapeId = b3_nullShapeId;
s_adapter.transparentDynamic = false;
s_adapter.transparentKinematic = false;
s_adapter.alphaBodyId = b3_nullBodyId;
s_adapter.bodyAlpha = 1.0f;
s_adapter.hasViewBounds = false;
s_adapter.lastCompoundAppended = 0;
@ -197,6 +203,8 @@ void ResetAdapterPool( void )
s_adapter.selectedShapeId = b3_nullShapeId;
s_adapter.transparentDynamic = false;
s_adapter.transparentKinematic = false;
s_adapter.alphaBodyId = b3_nullBodyId;
s_adapter.bodyAlpha = 1.0f;
s_adapter.hasViewBounds = false;
s_adapter.lastCompoundAppended = 0;
@ -239,6 +247,12 @@ void SetTransparentKinematic( bool enabled )
s_adapter.transparentKinematic = enabled;
}
void SetBodyAlpha( b3BodyId bodyId, float alpha )
{
s_adapter.alphaBodyId = bodyId;
s_adapter.bodyAlpha = alpha;
}
void SetViewBounds( b3AABB bounds )
{
s_adapter.viewBounds = bounds;
@ -862,6 +876,11 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo
c.w = BOX3D_TRANSPARENT_ALPHA;
}
if ( s_adapter.bodyAlpha < 1.0f && B3_ID_EQUALS( us->bodyId, s_adapter.alphaBodyId ) )
{
c.w = b3MinFloat( c.w, s_adapter.bodyAlpha );
}
if ( s_adapter.transparentKinematic && us->bodyType == b3_kinematicBody )
{
c.w = BOX3D_TRANSPARENT_ALPHA;