Thanks for your work. I’ll definitely study those tests and figure out what’s going on.
EDIT: You’ve got good ideas. This is an interesting test.
Here’s what I see when I run Test_Main2.java:
- Initially, with the ball is resting on the floor,
contactTest()
and pairTest()
both report 1, and the console output shows a single onContactStarted
(for that contact).
- When I press the space bar, the ball jumps upward.
contactTest()
and pairTest()
both report 0 because the ball and the floor are no longer in contact. The console output shows onContactEnded
, indicating that the initial contact has been broken.
- When the ball falls back to the floor,
contactTest()
and pairTest()
briefly report 2 contacts, then one. The console output shows another onContactStarted
, indicating the ball and the plane are back in contact.
- If I keep triggering jumps, eventually
contactTest()
and pairTest()
will report zero contacts even when the ball appears to be at rest on the floor. The console output implies that there’s a contact.
The most interesting results are the zeroes reported at the end. Why don’t contactTest()
and pairTest()
report 1 contact, as they did in the beginning?
Well, there’s an important distinction between contactTest()
/pairTest()
and a ContactListener
. A ContactListener
reports actual contacts between objects in the space, whereas contactTest()
and pairTest()
report hypothetical contacts: intersections that would be created if the specified object(s) were added to the space in the specified position(s).
In “Test_Main2.java”, the collision objects being tested are already added to the space, which is not the intended use case for contactTest()
and pairTest()
. If I wanted to know how many contacts there were for objects already added to the space, I’d use countManifolds()
.
Is there an automatic passivation mechanism?
There’s an activation/sleep mechanism for rigid bodies, but it shouldn’t interfere with contact reporting. In fact, creation of a new contact is one of the things that will re-activate a sleeping body.
Here’s what I believe is happening …
In its rest position, the ball is roughly tangent with the floor, which for contactTest()
and pairTest()
is an edge case. Either the ball barely intersects the floor, or it barely doesn’t intersect; it’s difficult to say. Probably the distinction between no contacts and non-zero contacts boils down rounding errors.
A more typical use for contactTest()
is when you want to add a collision object to the space, but only if it won’t intersect something that’s already there. (Intersecting rigid bodies tend to exhibit violent motion and/or unrealistic vibration.) So you do a contactTest()
and then add the object only if the test returns zero. Perhaps you keep trying different positions at random until you find one that works, or perhaps the obstruction is mobile, and you wait for it to move out of the spawning area.
For an example of contactTest()
, see the DropTest
app in the MinieExamples project. Before a new “drop” (set of connected bodies) gets added to the space, the Drop.hasHullContacts()
method is invoked to make sure the drop (actually its convex hull) won’t be entangled with objects previously added to the space.
I haven’t used pairTest()
very much. I think a typical use case would be when you want to simultaneously add multiple collision objects to the space. In addition to a contactTest()
for each object to be added, you’d also do a pairTest()
for each pair of objects to be added, to see whether they’ll intersect with one another.
Does all this seem plausible to you?