New sample renderer and UI (#10)

No changes to simulation
This commit is contained in:
Erin Catto 2026-06-06 10:06:05 -07:00 • committed by GitHub
commit 9e02b7f3b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
196 changed files with 116992 additions and 29969 deletions

View file

@ -1,5 +1,4 @@
include(GNUInstallDirs)
include(FetchContent)
set(BOX3D_SOURCE_FILES
aabb.c

View file

@ -1016,7 +1016,7 @@ static void b3ValidateMetrics( const b3DynamicTree* tree, int index )
const b3TreeNode* node = tree->nodes + index;
B3_VALIDATE( b3IsSaneAABB( node->aabb ) );
B3_VALIDATE( b3IsValidAABB( node->aabb ) );
if ( b3IsLeaf( node ) )
{

View file

@ -156,10 +156,7 @@ static inline void b3QHList_Init( b3QHListNode* head )
head->next = head;
}
static inline bool b3QHList_Empty( const b3QHListNode* head )
{
return head->next == head;
}
#define B3_LIST_EMPTY( A ) ( ( A )->next == (A) )
static inline bool b3QHList_Contains( const b3QHListNode* node )
{
@ -806,7 +803,7 @@ static void b3HullBuilder_DrainConflictList( b3HullBuilder* b, b3QHFace* face )
b3QHList_Remove( &orphan->link );
b3QHList_PushBack( &b->orphanedList.link, &orphan->link );
}
B3_ASSERT( b3QHList_Empty( &face->conflictListHead.link ) );
B3_ASSERT( B3_LIST_EMPTY( &face->conflictListHead.link ) );
}
// Mark a face for deletion, drain its conflict list, and populate a fresh DFS frame for it.
@ -1023,7 +1020,7 @@ static void b3HullBuilder_AbsorbFaces( b3HullBuilder* b, b3QHFace* face )
}
}
B3_ASSERT( b3QHList_Empty( head ) );
B3_ASSERT( B3_LIST_EMPTY( head ) );
// Conflict list is now drained. Retire this face to the free list.
b3HullBuilder_RetireFace( b, b->mergedFaces[i] );
@ -1228,7 +1225,7 @@ static void b3HullBuilder_ResolveVertices( b3HullBuilder* b )
// Otherwise: vertex is interior to the hull. Its slot in the bump pool is abandoned.
}
B3_ASSERT( b3QHList_Empty( &b->orphanedList.link ) );
B3_ASSERT( B3_LIST_EMPTY( &b->orphanedList.link ) );
}
static void b3HullBuilder_ResolveFaces( b3HullBuilder* b )
@ -1243,7 +1240,7 @@ static void b3HullBuilder_ResolveFaces( b3HullBuilder* b )
if ( face->mark == B3_MARK_DELETE && b3QHList_Contains( &face->link ) )
{
B3_ASSERT( b3QHList_Empty( &face->conflictListHead.link ) );
B3_ASSERT( B3_LIST_EMPTY( &face->conflictListHead.link ) );
b3QHList_Remove( &face->link );
}
}

View file

@ -1131,59 +1131,77 @@ static bool DrawQueryCallback( int proxyId, uint64_t userData, void* context )
if ( shape->materials[0].customColor != 0 )
{
// May already carry a packed material preset, pass through unchanged
color = (b3HexColor)shape->materials[0].customColor;
}
else if ( body->type == b3_dynamicBody && body->mass == 0.0f )
{
// Bad body
color = b3_colorRed;
}
else if ( body->setIndex == b3_disabledSet )
{
color = b3_colorSlateGray;
}
else if ( shape->sensorIndex != B3_NULL_INDEX )
{
color = b3_colorWheat;
}
else if ( body->flags & b3_hadTimeOfImpact )
{
color = b3_colorLime;
}
else if ( ( bodySim->flags & b3_isBullet ) && body->setIndex == b3_awakeSet )
{
color = b3_colorTurquoise;
}
else if ( body->flags & b3_isSpeedCapped )
{
color = b3_colorYellow;
}
else if ( bodySim->flags & b3_isFast )
{
color = b3_colorSalmon;
}
else if ( body->type == b3_staticBody )
{
color = b3_colorPaleGreen;
}
else if ( body->type == b3_kinematicBody )
{
if ( body->setIndex == b3_awakeSet )
{
color = b3_colorRoyalBlue;
}
else
{
color = b3_colorDarkBlue;
}
}
else if ( body->setIndex == b3_awakeSet )
{
color = b3_colorPink;
}
else
{
color = b3_colorGray;
// Hue carries the state, material carries its energy. Calm matte for the
// resting masses, glossy for fast bodies, metallic for the driven kinematic.
// Diagnostic states keep a saturated hue and the default material so they pop.
b3HexColor rgb;
b3DebugMaterial material = b3_debugMaterialDefault;
if ( body->type == b3_dynamicBody && body->mass == 0.0f )
{
// Bad body
rgb = b3_colorRed;
}
else if ( body->setIndex == b3_disabledSet )
{
rgb = b3_colorSlateGray;
}
else if ( shape->sensorIndex != B3_NULL_INDEX )
{
rgb = b3_colorWheat;
}
else if ( body->flags & b3_hadTimeOfImpact )
{
rgb = b3_colorLime;
}
else if ( ( bodySim->flags & b3_isBullet ) && body->setIndex == b3_awakeSet )
{
rgb = b3_colorTurquoise;
}
else if ( body->flags & b3_isSpeedCapped )
{
rgb = b3_colorYellow;
}
else if ( bodySim->flags & b3_isFast )
{
rgb = b3_colorOrange;
material = b3_debugMaterialGlossy;
}
else if ( body->type == b3_staticBody )
{
rgb = b3_colorDarkGray;
material = b3_debugMaterialMatte;
}
else if ( body->type == b3_kinematicBody )
{
if ( body->setIndex == b3_awakeSet )
{
rgb = b3_colorSteelBlue;
material = b3_debugMaterialMetallic;
}
else
{
rgb = b3_colorLightSteelBlue;
material = b3_debugMaterialMatte;
}
}
else if ( body->setIndex == b3_awakeSet )
{
rgb = b3_colorTan;
material = b3_debugMaterialSoft;
}
else
{
rgb = b3_colorLightSlateGray;
material = b3_debugMaterialDead;
}
color = (b3HexColor)b3MakeDebugColor( rgb, material );
}
if ( shape->userShape == NULL && world->createDebugShape != NULL )

View file

@ -78,6 +78,11 @@ void b3Yield( void )
SwitchToThread();
}
void b3Sleep( int milliseconds )
{
Sleep( (DWORD)milliseconds );
}
typedef struct b3Mutex
{
CRITICAL_SECTION cs;
@ -250,6 +255,14 @@ void b3Yield( void )
sched_yield();
}
void b3Sleep( int milliseconds )
{
struct timespec ts;
ts.tv_sec = milliseconds / 1000;
ts.tv_nsec = ( milliseconds % 1000 ) * 1000000L;
nanosleep( &ts, NULL );
}
#include <pthread.h>
typedef struct b3Mutex
{
@ -373,6 +386,7 @@ void b3JoinThread( b3Thread* t )
#include <mach/mach_time.h>
#include <sched.h>
#include <sys/time.h>
#include <time.h>
static double s_invFrequency = 0.0;
@ -418,6 +432,14 @@ void b3Yield( void )
sched_yield();
}
void b3Sleep( int milliseconds )
{
struct timespec ts;
ts.tv_sec = milliseconds / 1000;
ts.tv_nsec = ( milliseconds % 1000 ) * 1000000L;
nanosleep( &ts, NULL );
}
#include <pthread.h>
typedef struct b3Mutex
{
@ -560,6 +582,11 @@ void b3Yield( void )
{
}
void b3Sleep( int milliseconds )
{
( (void)( milliseconds ) );
}
typedef struct b3Mutex
{
int dummy;