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

@ -14,6 +14,7 @@
#include "gfx/debug_adapter.h"
#include "gfx/keycodes.h"
#include "gfx/renderer.h"
#include "gfx/text.h"
#include "host/gui.h"
#include "sample.h"
#include "sokol_app.h"
@ -160,6 +161,17 @@ static void OnEvent( const sapp_event* e )
s_context.camera.OnEvent( e );
}
// Releases go to the key table even when the UI captures them. Otherwise Ctrl let go
// while the Ctrl+O picker is open stays down in the next sample.
if ( e->type == SAPP_EVENTTYPE_KEY_UP )
{
SetKeyDown( e->key_code, false );
}
else if ( e->type == SAPP_EVENTTYPE_UNFOCUSED )
{
ClearKeysDown();
}
if ( uiCaptured )
{
return;
@ -181,7 +193,18 @@ static void OnEvent( const sapp_event* e )
switch ( e->key_code )
{
case SAPP_KEYCODE_TAB:
s_context.showUI = !s_context.showUI;
if ( mods & SAPP_MODIFIER_SHIFT )
{
bool hide = s_context.showUI || s_context.showText;
s_context.showUI = !hide;
s_context.showText = !hide;
}
else
{
// Plain Tab also restores text so it always leads back to the full view
s_context.showUI = !s_context.showUI;
s_context.showText = true;
}
break;
case SAPP_KEYCODE_ESCAPE:
@ -267,10 +290,6 @@ static void OnEvent( const sapp_event* e )
}
break;
case SAPP_EVENTTYPE_KEY_UP:
SetKeyDown( e->key_code, false );
break;
case SAPP_EVENTTYPE_CHAR:
// ? toggles the controls window. Read the typed character so it works
// on any layout and a text field can still type a literal ?, since the
@ -406,6 +425,12 @@ static void OnFrame( void )
s_context.sample->Step();
s_context.sample->Render();
// Before RenderFrame so world labels drop too
if ( s_context.showText == false )
{
ResetTextArena();
}
FrameInput fi{};
fi.view = camera.View();
fi.viewInv = camera.ViewInverse();