Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions aephysics/manifold/module.ae
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,23 @@ collide_hull_and_sphere(m: *LocalManifold, capacity: int, hull_a: *HullData, sph
return
}
if output.distance > 100.0 * FLOAT_EPSILON {
// Shallow.
normal = math.normalize(math.sub(output.point_b, output.point_a))
c_a = math.mul_add(center, radius_a - math.dot(math.sub(center, output.point_a), normal), normal)
c_b = math.mul_sub(center, radius_b, normal)
one_point(m, normal, math.lerp(c_a, c_b, 0.5), output.distance - radius, feature_pair_single())
// Shallow: the normal and point from the closest points in single
// precision, the manifold's own and the reference's (its distance
// runs in float). In double the closest points keep a last bit of
// noise (8.9e-16 across a resting sphere's normal), which a float
// drops: kept, it pushed a resting sphere sideways each step, and
// the residual it rolled with never came to the exact zero the
// reference rests at, leaving subnormal velocities every later
// step paid for in microcode assists.
point_a = math.narrow3(output.point_a)
point_b = math.narrow3(output.point_b)
centre_f = math.narrow3(center)
normal_f = math.normalizef(math.subf(point_b, point_a))
f32 radius_a_f = radius_a as f32
f32 radius_b_f = radius_b as f32
c_a = math.mul_addf(centre_f, radius_a_f - math.dotf(math.subf(centre_f, point_a), normal_f), normal_f)
c_b = math.mul_subf(centre_f, radius_b_f, normal_f)
one_point(m, math.widen3(normal_f), math.widen3(math.lerpf(c_a, c_b, 0.5)), output.distance - radius, feature_pair_single())
return
}
// Deep: the face the centre is least below.
Expand Down
7 changes: 6 additions & 1 deletion aephysics/triangle_manifold/module.ae
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ collide_triangle_and_sphere(m: *LocalManifold, capacity: int, v1: Vec3, v2: Vec3

d = math.sqrt_float(squared_distance)
normal = math.normalize(math.cross(math.sub(v2, v1), math.sub(v3, v1)))
if d * d > 1000.0 * FLOAT_MIN { normal = math.mul_sv(1.0 / d, math.sub(center, closest.point)) }
// The normal from the centre to its closest point in single precision,
// the manifold's own and the reference's (b3CollideTriangleAndSphere
// works in float): the double closest point keeps a last bit of noise
// across a resting sphere's normal, which pushed it sideways each step
// (collide_hull_and_sphere has the same note).
if d * d > 1000.0 * FLOAT_MIN { normal = math.widen3(math.normalizef(math.subf(math.narrow3(center), math.narrow3(closest.point)))) }
contact = math.mul_sv(0.5, math.add(math.sub(center, math.mul_sv(radius, normal)), closest.point))
m.normal = normal
m.point_count = 1
Expand Down
22 changes: 22 additions & 0 deletions bench/suite.ae
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,27 @@ tiny() {
run("tiny", world_id, 20000, SCENE_NONE)
}

// Not the reference's either: the same eight spheres touching in a row,
// so their contacts with each other take colours beside the ground's and
// a step's fixed cost per colour shows (the large world's spheres meet
// four colours a step with almost nothing in each).
tiny_row() {
world_id = world_with(1, 8, 1, 8, 64)
ground_box(world_id, 0.0 - 1.0, 20.0, 1.0, 20.0)
bdef = dynamics.default_body_def()
bdef.kind = dynamics.BODY_DYNAMIC
bdef.enable_sleep = false
sdef = dynamics.default_shape_def()
i = 0
while i < 8 {
bdef.position = math.vec3((i as float) - 3.5, 0.5, 0.0)
body = dynamics.create_body(world_id, &bdef)
dynamics.create_sphere_shape(body, &sdef, manifold.sphere(math.vec3_zero(), 0.5))
i = i + 1
}
run("tiny_row", world_id, 20000, SCENE_NONE)
}

// --- convex pile: a huge pile of PEEL's large convexes ------------------------------------------------------

convex_pile() {
Expand Down Expand Up @@ -926,6 +947,7 @@ main() {
if wanted("trees100") { trees("trees100", 1) }
if wanted("washer") { washer() }
if wanted("tiny") { tiny() }
if wanted("tiny_row") { tiny_row() }
if wanted("sat") { sat_runs() }
free(g_hulls)
free(g_meshes)
Expand Down
23 changes: 23 additions & 0 deletions bench/suite_box3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ static void CreateTiny( b3WorldId worldId )
}
}

// The same eight spheres touching in a row, as bench/suite.ae's tiny_row.
static void CreateTinyRow( b3WorldId worldId )
{
b3BodyDef groundDef = b3DefaultBodyDef();
groundDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f };
b3BodyId groundId = b3CreateBody( worldId, &groundDef );
b3BoxHull box = b3MakeBoxHull( 20.0f, 1.0f, 20.0f );
b3ShapeDef shapeDef = b3DefaultShapeDef();
b3CreateHullShape( groundId, &shapeDef, &box.base );

b3BodyDef bodyDef = b3DefaultBodyDef();
bodyDef.type = b3_dynamicBody;
bodyDef.enableSleep = false;
b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f };
for ( int i = 0; i < 8; ++i )
{
bodyDef.position = (b3Pos){ (float)i - 3.5f, 0.5f, 0.0f };
b3BodyId bodyId = b3CreateBody( worldId, &bodyDef );
b3CreateSphereShape( bodyId, &shapeDef, &sphere );
}
}

// benchmark/main.c's RunSatBenchmarks: each hull pair's GJK cold and warm
// and SAT with and without the inscribed-sphere bound, the best of four
// runs of twenty repeats, in microseconds a query.
Expand Down Expand Up @@ -233,6 +255,7 @@ int main( void )
{ "trees100", NULL, CreateTrees100, DestroyTrees, NULL, 500 },
{ "washer", GetWasherCapacity, CreateWasher, NULL, NULL, 1000 },
{ "tiny", NULL, CreateTiny, NULL, NULL, 20000 },
{ "tiny_row", NULL, CreateTinyRow, NULL, NULL, 20000 },
};

const char* asked = getenv( "AEPHYSICS_BENCH_SCENE" );
Expand Down
Loading
Loading