fix beam ghosts

This commit is contained in:
Erin Catto 2026-11-10 22:33:36 -08:00
commit 73f2333585
8 changed files with 81 additions and 13 deletions

View file

@ -103,3 +103,7 @@ rail,0,1,capsule,0,2
rail,0,1,upright,0,5
rail,0,1,sphere,0,4
rail,0,1,cylinder,0,3
beams,0,0,box,0,3
beams,0,0,cylinder,0,3
beams,0,1,box,0,3
beams,0,1,cylinder,0,3

1 scene preset mirror body ghosts runs
103 rail 0 1 upright 0 5
104 rail 0 1 sphere 0 4
105 rail 0 1 cylinder 0 3
106 beams 0 0 box 0 3
107 beams 0 0 cylinder 0 3
108 beams 0 1 box 0 3
109 beams 0 1 cylinder 0 3

View file

@ -103,3 +103,7 @@ rail,0,1,capsule,0,4
rail,0,1,upright,0,5
rail,0,1,sphere,0,5
rail,0,1,cylinder,0,4
beams,0,0,box,0,3
beams,0,0,cylinder,0,3
beams,0,1,box,0,3
beams,0,1,cylinder,0,3

1 scene preset mirror body ghosts runs
103 rail 0 1 upright 0 5
104 rail 0 1 sphere 0 5
105 rail 0 1 cylinder 0 4
106 beams 0 0 box 0 3
107 beams 0 0 cylinder 0 3
108 beams 0 1 box 0 3
109 beams 0 1 cylinder 0 3

View file

@ -20,7 +20,9 @@
#include <string.h>
// Command line and result file keys
static const char* s_sceneKeys[e_ghostSceneCount] = { "flat", "ramp", "cliff", "crest", "bumps", "peel", "chamfer", "rail" };
static const char* s_sceneKeys[e_ghostSceneCount] = {
"flat", "ramp", "cliff", "crest", "bumps", "peel", "chamfer", "rail", "beams",
};
static const char* s_bodyKeys[e_ghostBodyCount] = { "box", "capsule", "upright", "sphere", "cylinder" };
#define MAX_CONFIGS 256
@ -99,6 +101,15 @@ static void RunConfig( Config* config, GhostSettings settings, int stepCount, bo
settings.speculative = false;
}
// The s&box character over the beam pits, hovering on speculative contacts. A resting cull that keeps
// the chamfers flush with the top launches it.
if ( config->scene == e_ghostBeams )
{
settings.fixedRotation = true;
settings.speculative = true;
settings.speed = GHOST_BEAM_SPEED;
}
b3WorldDef worldDef = b3DefaultWorldDef();
b3WorldId worldId = b3CreateWorld( &worldDef );
if ( s_recycling == false )
@ -185,7 +196,8 @@ static int BuildConfigs( Config* configs, int sceneFilter, int presetFilter, int
}
// Only a flat bottom can rest on the chamfer edges
if ( scene == e_ghostChamfer && body != e_ghostBox && body != e_ghostCylinder )
bool chamferScene = scene == e_ghostChamfer || scene == e_ghostBeams;
if ( chamferScene && body != e_ghostBox && body != e_ghostCylinder )
{
continue;
}
@ -385,8 +397,10 @@ int main( int argc, char** argv )
{
printf( "Usage: ghost_scan [options]\n"
"Runs the Ghost Collisions sample headless and counts ghost manifolds per scene and body.\n"
" -s, --scene=<key|all> flat, ramp, cliff, crest, bumps, peel, chamfer, rail (default all)\n"
" -s, --scene=<key|all> flat, ramp, cliff, crest, bumps, peel, chamfer, rail, beams (default all)\n"
" chamfer runs only the box and cylinder, fixed rotation without speculative\n"
" beams runs only the box and cylinder, fixed rotation with speculative,\n"
" always at 8 m/s\n"
" -b, --body=<key|all> box, capsule, upright, sphere, cylinder (default all)\n"
" -m, --mirror=<0|1|all> mirrored mesh (default all)\n"
" -p, --preset=<0-3|all> PEEL preset (default all)\n"

View file

@ -2385,6 +2385,19 @@ public:
relaunch = true;
}
// The beams ghost needs the s&box character hovering on speculative contacts
if ( settings.scene == e_ghostBeams )
{
settings.fixedRotation = true;
settings.speculative = true;
settings.speed = GHOST_BEAM_SPEED;
if ( settings.body != e_ghostBox && settings.body != e_ghostCylinder )
{
settings.body = e_ghostBox;
}
relaunch = true;
}
if ( settings.scene == e_ghostInternal )
{
m_camera->SetView( 60.0f, 20.0f, 160.0f, { 0.0f, 30.0f, 0.0f } );

View file

@ -28,6 +28,14 @@
#define GHOST_RAIL_SKIRT 0.4f
// The s&box beam floor at 1/30 m per inch, rounded to whole chamfer cells so a height field grid holds every
// vertex. Beams with chamfered tops over deep pits, the 0.8 m hull always spans a pit.
#define GHOST_BEAM_COUNT 20
#define GHOST_BEAM_START_X -8.0f
#define GHOST_BEAM_PITCH 0.75f
#define GHOST_BEAM_WIDTH 0.4f
#define GHOST_BEAM_PIT_DEPTH 0.8f
typedef struct PeelPreset
{
int columnCount;
@ -43,7 +51,7 @@ static const PeelPreset s_peelPresets[GHOST_PEEL_PRESET_COUNT] = {
};
const char* g_ghostSceneNames[e_ghostSceneCount] = {
"Flat", "Concave", "Cliff", "Crest", "Bumps", "Internal", "Chamfer", "Rail",
"Flat", "Concave", "Cliff", "Crest", "Bumps", "Internal", "Chamfer", "Rail", "Beams",
};
const char* g_ghostBodyNames[e_ghostBodyCount] = { "Box", "H Capsule", "V Capsule", "Sphere", "Cylinder" };
@ -484,6 +492,26 @@ void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data )
PushProfile( data, GHOST_RAIL_THICKNESS, -GHOST_RAIL_SKIRT );
break;
case e_ghostBeams:
{
// A height field cannot hold the vertical pit walls, so there each wall takes one cell
float wallRun = settings->heightField ? GHOST_CHAMFER_WIDTH : 0.0f;
PushProfile( data, -h, 0.0f );
for ( int i = 0; i + 1 < GHOST_BEAM_COUNT; ++i )
{
float pitLeft = GHOST_BEAM_START_X + GHOST_BEAM_PITCH * (float)i + GHOST_BEAM_WIDTH;
float pitRight = GHOST_BEAM_START_X + GHOST_BEAM_PITCH * (float)( i + 1 );
PushProfile( data, pitLeft - GHOST_CHAMFER_WIDTH, 0.0f );
PushProfile( data, pitLeft, -GHOST_CHAMFER_DROP );
PushProfile( data, pitLeft + wallRun, -GHOST_BEAM_PIT_DEPTH );
PushProfile( data, pitRight - wallRun, -GHOST_BEAM_PIT_DEPTH );
PushProfile( data, pitRight, -GHOST_CHAMFER_DROP );
PushProfile( data, pitRight + GHOST_CHAMFER_WIDTH, 0.0f );
}
PushProfile( data, h, 0.0f );
}
break;
default:
PushProfile( data, -h, 0.0f );
PushProfile( data, h, 0.0f );
@ -512,7 +540,7 @@ void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data )
b3ShapeDef shapeDef = b3DefaultShapeDef();
b3CreateHullShape( data->groundId, &shapeDef, &box.base );
}
else if ( settings->scene == e_ghostChamfer )
else if ( settings->scene == e_ghostChamfer || settings->scene == e_ghostBeams )
{
// One cell per chamfer puts every notch vertex on the grid
AddHeightField( worldId, data, -h, h, GetCellCount( 2.0f * h, GHOST_CHAMFER_WIDTH ), groundHalfWidth, cellCountZ,
@ -723,7 +751,8 @@ static bool IsGhost( const GhostCollisionsData* data, b3Vec3 normal, float xMin,
}
GhostBody body = data->settings.body;
bool chamferHull = data->settings.scene == e_ghostChamfer && ( body == e_ghostBox || body == e_ghostCylinder );
bool chamferScene = data->settings.scene == e_ghostChamfer || data->settings.scene == e_ghostBeams;
bool chamferHull = chamferScene && ( body == e_ghostBox || body == e_ghostCylinder );
float lower = B3_PI;
float upper = -B3_PI;

View file

@ -23,6 +23,9 @@ extern "C"
#define GHOST_RAIL_HEIGHT 0.35f
#define GHOST_RAIL_THICKNESS 0.08f
// The beam ghost depends on how the body phases with the pits, at the default speed the box misses it
#define GHOST_BEAM_SPEED 8.0f
typedef enum GhostScene
{
e_ghostFlat,
@ -33,6 +36,7 @@ typedef enum GhostScene
e_ghostInternal,
e_ghostChamfer,
e_ghostRail,
e_ghostBeams,
e_ghostSceneCount
} GhostScene;

View file

@ -1551,7 +1551,7 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape
}
// Padding
hullBottom -= b3MaxFloat( 0.0f, restingSeparation ) + linearSlop;
hullBottom = b3MinFloat( hullBottom, hullBottom - restingSeparation + 0.25f * linearSlop );
for ( int i = 0; i < survivorCount; ++i )
{

View file

@ -21,25 +21,25 @@
#if defined( BOX3D_DOUBLE_PRECISION )
#define RAGDOLL_SLEEP_STEP 282
#define RAGDOLL_HASH 0x6E4B13AD
#define WAVE_PILE_SLEEP_STEP 315
#define WAVE_PILE_HASH 0x15007937
#define WAVE_PILE_SLEEP_STEP 316
#define WAVE_PILE_HASH 0x7CB7D931
#define QUERY_SPAWN_SLEEP_STEP 242
#define QUERY_SPAWN_HASH 0x489585E6
#define QUERY_SPAWN_HIT_COUNT 59
#define QUERY_SPAWN_QUERY_HASH 0x5B4429DC
#define MESH_DROP_SLEEP_STEP 197
#define MESH_DROP_HASH 0x5DA091C3
#define MESH_DROP_HASH 0xA2E8BB21
#else
#define RAGDOLL_SLEEP_STEP 277
#define RAGDOLL_HASH 0x5E042B6E
#define WAVE_PILE_SLEEP_STEP 455
#define WAVE_PILE_HASH 0x854F313D
#define WAVE_PILE_SLEEP_STEP 300
#define WAVE_PILE_HASH 0x3155DA54
#define QUERY_SPAWN_SLEEP_STEP 242
#define QUERY_SPAWN_HASH 0xF3AD9BA6
#define QUERY_SPAWN_HIT_COUNT 59
#define QUERY_SPAWN_QUERY_HASH 0xE3271F3D
#define MESH_DROP_SLEEP_STEP 197
#define MESH_DROP_HASH 0x96D47D4F
#define MESH_DROP_HASH 0x96B62947
#endif
// The goldens above pin exact values for the default four point manifold. A build that