Repository navigation
Place each sweep-and-prune endpoint independently - #2
Draft
xuchen-han wants to merge 5 commits into
Draft
xuchen-han wants to merge 5 commits into
xuchen-han wants to merge 5 commits into
Conversation
update_() took one direction from the interval's "lo" endpoint and used it to place both endpoints, which only holds while an object's AABB keeps its width. When the width changes, "lo" and "hi" travel in opposite directions, the walk for "hi" stops on the endpoint being moved, and the splice links that node to itself. The lists are then cut, so the manager misses overlaps or walks a cycle forever. An AABB changes width whenever an object leaves or returns to an identity rotation, because computeAABB() bounds an unrotated geometry by its local box and a rotated one by the cube around its bounding sphere. Give each endpoint its own direction, and move the one travelling right first so that "lo" stays behind "hi" at every intermediate step. When the width does not change the two directions agree and the behaviour is unchanged.
1) Windows test recovery would occasionally fail after successful completion of build. The default time is five seconds. We've explicitly extended it to 20 seconds to give the flakes a bit more time to settle out. 2) The github action jobs (mac and linux) no longer stop evaluation if any other test (including appveyor) fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The broadphase is the first stage of collision detection. It finds the pairs of
objects that are near each other.
SaPCollisionManagerdoes this with sweep and prune. For each of the threeaxes, it gives every object one interval. An interval has two endpoints,
loand
hi. The manager holds all endpoints in a sorted list, one list per axis.When an object moves,
update_()moves that object's two endpoints to theirnew places in the list. It does not sort the whole list again.
The problem
update_()calculates one direction, and it uses only theloendpoint:It then moves both endpoints in that direction.
This is correct only while the interval keeps its width. In that case
loandhialways move together. If the width changes, the two endpoints move inopposite directions. The single direction is then wrong for one of them.
What breaks
Look at the branch for
direction == -1, with ahiendpoint that must move tothe right. The loop that walks to the left stops immediately:
tempis stillcurrent->hi. The code after the loop puts that node afteritself. It sets
hi->prev = hiandhi->next = hi.The node now points to itself and the list is broken. Each later walk gives a
wrong result, or it never stops. The branch for
direction == 1has the samefault on the
loendpoint.I put a temporary assert at that splice and it fired:
dir=-1 but hi must move RIGHT (coord=2): hi=-435.94 new_max=-434.62.Master has this fault today
A collision object cannot replace its geometry. The width of an AABB can
therefore change only inside
computeAABB().computeAABB()has two paths. For an object with no rotation, it uses theobject's local AABB. For a rotated object, it uses a cube around the bounding
sphere. The two boxes have different widths. An object that starts or stops
being axis-aligned changes the width of its AABB. The new test does exactly
this, and it fails on master.
On master the result is a wrong answer: sweep and prune loses pairs that are
really overlapping.
I found the fault while I worked on flexible-collision-library#664. That change makes the AABB depend on
the orientation, so the width changes at every step. The result is an endless
loop instead of a wrong answer, and that loop stops CI with a timeout. This fix
does not need flexible-collision-library#664 and corrects the fault on its own.
The correction
Each endpoint now calculates its own direction. The endpoint that moves to the
right moves first. This keeps
lobehindhiafter each step.The four blocks of code that place an endpoint do not change. Only the choice
of block and the order change. If the width does not change, the two directions
agree, the same blocks run in the same order, and the behavior stays the same as
before.
Each block now runs only when its own endpoint must move. Each loop therefore
makes at least one step, and the bad splice cannot happen again.
Tests
test/broadphase/test_broadphase_SaP.cppis new. It puts twelve long boxes intoa
SaPCollisionManagerand aNaiveCollisionManager. It turns the boxes aboutthe z axis eight times. After each turn the two managers must report the same
pairs.
Without the correction the test fails at the first turn. Sweep and prune reports
25 pairs, and the reference reports more than 60.
I built this branch from source and ran these tests:
update_;test_fcl_broadphase_collision_1,_2,_distanceandtest_broadphase_dynamic_AABB_treepass, which is 18 tests;computeAABB(), so the correctionis safe by itself.
This change is