Fixing issues (#94)
- option to draw kinematic shapes with transparency - slight change to triangle vs hull to reduce ghost collisions - changed return of b3DebugDraw.DrawShapeFcn to void #66 #48 #69 #75 #76
This commit is contained in:
parent
c37cfe4cd7
commit
dfa5e6add0
27 changed files with 906 additions and 433 deletions
|
|
@ -18,27 +18,27 @@
|
|||
// Double precision accumulates body positions in double, so the settle/sleep step and the
|
||||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define EXPECTED_SLEEP_STEP 297
|
||||
#define EXPECTED_HASH 0x27FF38C1
|
||||
#define WAVE_PILE_SLEEP_STEP 287
|
||||
#define WAVE_PILE_HASH 0xFFC8DA49
|
||||
#define RAGDOLL_SLEEP_STEP 297
|
||||
#define RAGDOLL_HASH 0x27FF38C1
|
||||
#define WAVE_PILE_SLEEP_STEP 258
|
||||
#define WAVE_PILE_HASH 0xA3CDC61B
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x1737F5BC
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0x31F090DC
|
||||
#define MESH_DROP_SLEEP_STEP 206
|
||||
#define MESH_DROP_HASH 0xB6A9E1DE
|
||||
#define MESH_DROP_SLEEP_STEP 251
|
||||
#define MESH_DROP_HASH 0x465381C5
|
||||
#else
|
||||
#define EXPECTED_SLEEP_STEP 308
|
||||
#define EXPECTED_HASH 0x1E5EDD79
|
||||
#define WAVE_PILE_SLEEP_STEP 285
|
||||
#define WAVE_PILE_HASH 0x4057173C
|
||||
#define RAGDOLL_SLEEP_STEP 308
|
||||
#define RAGDOLL_HASH 0x1E5EDD79
|
||||
#define WAVE_PILE_SLEEP_STEP 239
|
||||
#define WAVE_PILE_HASH 0xA2F4D472
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xB9F993A5
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0xB9D3863D
|
||||
#define MESH_DROP_SLEEP_STEP 205
|
||||
#define MESH_DROP_HASH 0x8F55FB2D
|
||||
#define MESH_DROP_SLEEP_STEP 251
|
||||
#define MESH_DROP_HASH 0xE58C7240
|
||||
#endif
|
||||
|
||||
static int SingleMultithreadingTest( int workerCount )
|
||||
|
|
@ -68,13 +68,13 @@ static int SingleMultithreadingTest( int workerCount )
|
|||
|
||||
b3DestroyWorld( worldId );
|
||||
|
||||
if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH )
|
||||
if ( data.sleepStep != RAGDOLL_SLEEP_STEP || data.hash != RAGDOLL_HASH )
|
||||
{
|
||||
printf( " workers=%d sleepStep=%d hash=0x%08X\n", workerCount, data.sleepStep, data.hash );
|
||||
}
|
||||
|
||||
ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP );
|
||||
ENSURE( data.hash == EXPECTED_HASH );
|
||||
ENSURE( data.sleepStep == RAGDOLL_SLEEP_STEP );
|
||||
ENSURE( data.hash == RAGDOLL_HASH );
|
||||
|
||||
DestroyFallingRagdolls( &data );
|
||||
|
||||
|
|
@ -113,13 +113,13 @@ static int CrossPlatformTest( void )
|
|||
done = UpdateFallingRagdolls( worldId, &data );
|
||||
}
|
||||
|
||||
if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH )
|
||||
if ( data.sleepStep != RAGDOLL_SLEEP_STEP || data.hash != RAGDOLL_HASH )
|
||||
{
|
||||
printf( " cross-platform sleepStep=%d hash=0x%08X\n", data.sleepStep, data.hash );
|
||||
}
|
||||
|
||||
ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP );
|
||||
ENSURE( data.hash == EXPECTED_HASH );
|
||||
ENSURE( data.sleepStep == RAGDOLL_SLEEP_STEP );
|
||||
ENSURE( data.hash == RAGDOLL_HASH );
|
||||
|
||||
DestroyFallingRagdolls( &data );
|
||||
|
||||
|
|
|
|||
|
|
@ -448,13 +448,12 @@ static void RecTestDestroyDebugShape( void* userShape, void* userContext )
|
|||
counters->destroyed += 1;
|
||||
}
|
||||
|
||||
static bool RecTestDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, void* context )
|
||||
static void RecTestDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, void* context )
|
||||
{
|
||||
(void)userShape;
|
||||
(void)transform;
|
||||
(void)color;
|
||||
(void)context;
|
||||
return true;
|
||||
}
|
||||
|
||||
// b3World_Draw lazily fires createDebugShape for shapes entering the draw set, the same way the
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "box3d/math_functions.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
// This is a simple example of building and running a simulation
|
||||
// using Box3D. Here we create a large ground box and a small dynamic
|
||||
|
|
@ -617,6 +618,139 @@ static int TestCompoundHitEvents( void )
|
|||
return 0;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
kChild0MaterialId = 101,
|
||||
kChild1MaterialId = 202,
|
||||
kProbeMaterialId = 999,
|
||||
};
|
||||
|
||||
// No context pointer on mixing callbacks, so capture through file scope
|
||||
static struct
|
||||
{
|
||||
int callCount;
|
||||
bool sawChild0;
|
||||
bool sawChild1;
|
||||
float mixedFriction;
|
||||
} materialCapture;
|
||||
|
||||
static float CaptureFrictionMix( float frictionA, uint64_t userMaterialIdA, float frictionB, uint64_t userMaterialIdB )
|
||||
{
|
||||
materialCapture.callCount += 1;
|
||||
|
||||
if ( userMaterialIdA == kChild0MaterialId || userMaterialIdB == kChild0MaterialId )
|
||||
{
|
||||
materialCapture.sawChild0 = true;
|
||||
}
|
||||
|
||||
if ( userMaterialIdA == kChild1MaterialId || userMaterialIdB == kChild1MaterialId )
|
||||
{
|
||||
materialCapture.sawChild1 = true;
|
||||
materialCapture.mixedFriction = sqrtf( frictionA * frictionB );
|
||||
}
|
||||
|
||||
return sqrtf( frictionA * frictionB );
|
||||
}
|
||||
|
||||
// Contact material selection must use the struck compound child's material, not entry 0
|
||||
// of the compound material table. Child 0 gets low friction, child 1 high friction, and a
|
||||
// unit friction sphere strikes only child 1, so the mixing callback must see child 1's
|
||||
// values. Covers sphere, capsule, and hull children. Issue #69.
|
||||
static int TestCompoundContactMaterials( void )
|
||||
{
|
||||
b3SurfaceMaterial mat0 = b3DefaultSurfaceMaterial();
|
||||
mat0.friction = 0.04f;
|
||||
mat0.userMaterialId = kChild0MaterialId;
|
||||
|
||||
b3SurfaceMaterial mat1 = b3DefaultSurfaceMaterial();
|
||||
mat1.friction = 0.81f;
|
||||
mat1.userMaterialId = kChild1MaterialId;
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f );
|
||||
|
||||
// Children at x = -3 and x = +3, all with their top face or surface at y = 0.5
|
||||
b3CompoundSphereDef spheres[2] = {
|
||||
{ .sphere = { { -3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat0 },
|
||||
{ .sphere = { { 3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat1 },
|
||||
};
|
||||
|
||||
b3CompoundCapsuleDef capsules[2] = {
|
||||
{ .capsule = { { -3.0f, 0.0f, -0.5f }, { -3.0f, 0.0f, 0.5f }, 0.5f }, .material = mat0 },
|
||||
{ .capsule = { { 3.0f, 0.0f, -0.5f }, { 3.0f, 0.0f, 0.5f }, 0.5f }, .material = mat1 },
|
||||
};
|
||||
|
||||
b3CompoundHullDef hulls[2] = {
|
||||
{ .hull = &box.base, .transform = { { -3.0f, 0.0f, 0.0f }, b3Quat_identity }, .material = mat0 },
|
||||
{ .hull = &box.base, .transform = { { 3.0f, 0.0f, 0.0f }, b3Quat_identity }, .material = mat1 },
|
||||
};
|
||||
|
||||
for ( int childType = 0; childType < 3; ++childType )
|
||||
{
|
||||
b3CompoundDef compoundDef = { 0 };
|
||||
if ( childType == 0 )
|
||||
{
|
||||
compoundDef.spheres = spheres;
|
||||
compoundDef.sphereCount = 2;
|
||||
}
|
||||
else if ( childType == 1 )
|
||||
{
|
||||
compoundDef.capsules = capsules;
|
||||
compoundDef.capsuleCount = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
compoundDef.hulls = hulls;
|
||||
compoundDef.hullCount = 2;
|
||||
}
|
||||
|
||||
b3CompoundData* compound = b3CreateCompound( &compoundDef );
|
||||
ENSURE( compound != NULL );
|
||||
|
||||
memset( &materialCapture, 0, sizeof( materialCapture ) );
|
||||
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
worldDef.frictionCallback = CaptureFrictionMix;
|
||||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_staticBody;
|
||||
b3BodyId compoundBodyId = b3CreateBody( worldId, &bodyDef );
|
||||
b3ShapeDef compoundShapeDef = b3DefaultShapeDef();
|
||||
b3CreateBakedCompoundShape( compoundBodyId, &compoundShapeDef, compound );
|
||||
|
||||
// Sphere driven straight down onto child 1
|
||||
bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.gravityScale = 0.0f;
|
||||
bodyDef.position = (b3Pos){ 3.0f, 3.0f, 0.0f };
|
||||
bodyDef.linearVelocity = (b3Vec3){ 0.0f, -30.0f, 0.0f };
|
||||
b3BodyId sphereBodyId = b3CreateBody( worldId, &bodyDef );
|
||||
b3ShapeDef sphereShapeDef = b3DefaultShapeDef();
|
||||
sphereShapeDef.density = 1.0f;
|
||||
sphereShapeDef.baseMaterial.friction = 1.0f;
|
||||
sphereShapeDef.baseMaterial.userMaterialId = kProbeMaterialId;
|
||||
b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f };
|
||||
b3CreateSphereShape( sphereBodyId, &sphereShapeDef, &sphere );
|
||||
|
||||
for ( int i = 0; i < 30; ++i )
|
||||
{
|
||||
b3World_Step( worldId, 1.0f / 60.0f, 4 );
|
||||
}
|
||||
|
||||
b3DestroyWorld( worldId );
|
||||
b3DestroyCompound( compound );
|
||||
|
||||
ENSURE( materialCapture.callCount > 0 );
|
||||
// The pre-fix code fed material table entry 0 to the mixing callback for every child
|
||||
ENSURE( materialCapture.sawChild0 == false );
|
||||
ENSURE( materialCapture.sawChild1 == true );
|
||||
// sqrt(0.81 * 1.0)
|
||||
ENSURE_SMALL( materialCapture.mixedFriction - 0.9f, 1e-5f );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int TestSetWorkerCount( void )
|
||||
{
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
|
|
@ -1038,6 +1172,7 @@ int WorldTest( void )
|
|||
RUN_SUBTEST( TestContactEvents );
|
||||
RUN_SUBTEST( TestHitEvents );
|
||||
RUN_SUBTEST( TestCompoundHitEvents );
|
||||
RUN_SUBTEST( TestCompoundContactMaterials );
|
||||
RUN_SUBTEST( TestOverflowColorPile );
|
||||
RUN_SUBTEST( SetBulletDriftTest );
|
||||
RUN_SUBTEST( EnableSleepFlagSyncTest );
|
||||
|
|
|
|||
Loading…
Reference in a new issue