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
7 changes: 6 additions & 1 deletion aephysics/shape/module.ae
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ shape_cast_shape(shape: *Shape, t: Transform, proxy: ShapeProxy, translation: Ve
return output
}

overlap_shape(shape: *Shape, t: Transform, proxy: ShapeProxy) -> bool {
overlap_shape(shape: *Shape, t: Transform, given: ShapeProxy) -> bool {
// The proxy's points copied first, as shape_cast_shape does: one made by
// make_shape_proxy for a sphere or capsule lives in the scratch the
// sphere's and capsule's overlaps write their own shape into, so GJK
// would have tested the shape against itself.
proxy = mesh.make_local_proxy(given, math.transform_identity(), local_buffer())
kind = shape.kind
if kind == SHAPE_CAPSULE { return capsule.overlap_capsule(shape.capsule, t, proxy) }
if kind == SHAPE_COMPOUND { return compound.overlap_compound(shape.compound, t, proxy) }
Expand Down
16 changes: 16 additions & 0 deletions tests/test_shape.ae
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,21 @@ test_far_origin() {
free(offsets_block)
}

// A proxy made from one sphere tested against another far away: the
// sphere's (and capsule's) overlap used to write its own shape into the
// scratch the proxy's points live in, and so found its own copy touching.
test_overlap_own_proxy() {
ball_a = shape.sphere_shape(manifold.sphere(math.vec3_zero(), 0.5), 1.0)
ball_b = shape.sphere_shape(manifold.sphere(math.vec3(10.0, 0.0, 0.0), 0.5), 1.0)
rod = shape.capsule_shape(manifold.capsule(math.vec3(10.0, 0.0, 0.0), math.vec3(10.0, 2.0, 0.0), 0.5), 1.0)
p = shape.make_shape_proxy(&ball_a)
ensure("own proxy: far sphere apart", shape.overlap_shape(&ball_b, math.transform_identity(), p) == false)
p = shape.make_shape_proxy(&ball_a)
ensure("own proxy: far capsule apart", shape.overlap_shape(&rod, math.transform_identity(), p) == false)
near = shape.sphere_shape(manifold.sphere(math.vec3(0.8, 0.0, 0.0), 0.5), 1.0)
p = shape.make_shape_proxy(&ball_a)
ensure("own proxy: near sphere touching", shape.overlap_shape(&near, math.transform_identity(), p))
}
test_dispatch() {
origin = math.vec3(0.0 - 4.0, 0.0, 0.0)
translation = math.vec3(8.0, 0.0, 0.0)
Expand Down Expand Up @@ -817,6 +832,7 @@ test_filters() {
main() {
before = basics.alloc_count()
test_mass()
test_overlap_own_proxy()
test_aabb()
test_ray_cast_sphere()
test_ray_cast_capsule()
Expand Down
Loading