BulletWorld contactTest for multiple nodes

It seems contactTest only accepts a singel node. Is it possible to check all collisions in Bullet, just like the addCollider and traverse methods of a CollisionTraverser?

I noticed the collision handler mentioned in Panda Bullet - #545 by Vincent22 may help solve the problem, but it remains confusing how to choose a proper dt for the doPhysics method since I am not assuming any dynamics.

I think that they were asking whether there was such a handler, not stating that there was such a handler.

However, look at the next post in that thread: there enn0x mentions that you can register events to be fired on collision, which (depending on just what you’re doing) might serve your purposes.

If that doesn’t serve, could you perhaps expand on what you’re trying to do? That might help us to find approaches that might work in your case.

I’m not quite sure of what you’re saying here: are you saying that you’re not using the physics side of Bullet, just the detection of intersections?

If so, then you could perhaps try just feeding it the current dt, rather than a fixed dt–see whether that works in your case.

Thanks. Yes, I agree the “bullet-contact-added” event may help solve my problem.
My goal was to manually set the poses of several objects and then detect their overlaps with obstacles…calling the doPhysics function seems a bit confusing …

I’m glad to read it. :slight_smile:

Ah, I see! That makes sense! Thank you for the explanation! :slight_smile:

As I understand it, the “doPhysics” method is just Bullet’s “update” method: it tells Bullet to update the state of its “physics world”. As part of that, it tells Bullet how much time to consider to have passed, and how to “slice up” that time into chunks of fixed duration.

For your purposes, I would say to try just passing in the actual current “dt” and to ignore the rest of the parameters–see if that works. After all, if you’re not planning on having actual physical interactions, you likely don’t need the precision of slicing up the “dt”.

If it doesn’t work, then revisit the issue.

Thanks! It seems I did not correctly express myself. By “a bit confusing”, I did not mean the function interface was difficult to uncerstand. Instead, I mean the name “do physics” is misleading if it was only used for detecting collisions. I guess I will use doPhysics to solve this problem right now.

By the way, there does exist one thing that confused me. Take the following code for example:

shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
node = BulletRigidBodyNode('Ground')
node.addShape(shape)
np = render.attachNewNode(node)
np.setPos(0, 0, -2)
world.attachRigidBody(node)

The rigidbodynode is attached to both the render and the world. np.setPos(0, 0, -2) function is applied to the nodepath under render. How could this position be obtained by the BulletWorld?

NOTE: In my implementation, my BulletRigidBodyNode is not attached to a render and I used the setTransformState function to notify its pose to the BulletWorld. See the following code. Is there a more elegent way to work on it?

physicsworld = BulletWorld()
pdbrbd_nd0.setTransform(TransformState.makeMat(xxx.getMat()))
pdbrbd_nd1.setTransform(TransformState.makeMat(xxx.getMat()))
physicsworld.attach(pdbrbd_nd0)
physicsworld.attach(pdbrbd_nd1)
result = physicsworld.contactTestPair(pdbrbd_nd0, pdbrbd_nd1)
contacts = result.getContacts()
contact_points = [ct.getManifoldPoint().getPositionWorldOnB() for ct in contacts]
contact_points += [ct.getManifoldPoint().getPositionWorldOnA() for ct in contacts]
contact_points = contact_points[0:max_contacts] # trim
physicsworld.remove(pdbrbd_nd0)
physicsworld.remove(pdbrbd_nd1)

Also, I obtained the contact points in the above program. Unfortunately, I got a list of repeated points. They all stay at the red sphere in the following figure. I might misunderstood something, and I appreciate it a lot if you could point out my mistakes. Thank you.

Ah, I see–my mistake, and my apologies!

As to that confusion, well, in all fairness I’m not sure that using Bullet for detection only is really its intended use-case, or at least its primary use-case.

My understanding is that Panda internally syncs its own nodes with Bullet’s internal representation, keeping the two in accord.

Hmm… I fear that I don’t know that I’ve used Bullet in quite that way, so I’m not sure of how to expect it to behave…

I would have thought that, as per the above, Panda would keep the two synced. That said, it’s also possible that this syncing requires a call to “doPhysics”, which I don’t see happening in that section of code.

(This might call for one of the forum-members better versed than I in Bullet!)

I’m guessing somewhat here, but I imagine that this is just because you’re getting the points on both B and A–it seems natural to me that when B is in contact with A, the contact-points between them will be found on both.

But it’s very possible that I’m mistaken in my understanding of how Bullet works here!

Hmm… It does look like you’re setting your objects to have the same transform (“xxx.getMat()”)…

I see that one of your shapes is a bunny–what is the other? I’m not managing to make it out in the screenshot…