Help with using contactPairTest() and ContactResultCallback?

Post Reply
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Help with using contactPairTest() and ContactResultCallback?

Post by jimjamjack »

I've been having issues trying to find when two specific rigidBodies collide, and I'm having no luck with the "iterating through the contact manifold" method, as Body0 and Body1 never seem to have the expected userPointer or userIndex.

So I've stumbled across contactPairTest(), but I'm unsure as to how I should use it. Since I'm having trouble accessing the Bullet wiki (I also don't think it has example code anyway for this method?), then would anyone be able to help me use this method successfully?

I'm trying to delete the targetRigidBody that gets hit by a bullet, so would I delete it in the ResultCallback?

Any help would be appreciated :)
Last edited by jimjamjack on Mon May 01, 2017 9:55 pm, edited 1 time in total.
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by erbisme4@yahoo.com »

in your resultcallback, virtual btScalar addSingleResult, will be called on contact detected. There you can check the manifold point and determine collision appropriately.
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by jimjamjack »

How do I set up a result callback exactly? Do you have an example?
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by erbisme4@yahoo.com »

Create a struct and inherit from ContactResultCallback. In it you can define members such as collision detected. Implement your version of addSingleResult in the struct.

Code: Select all

struct SimulationContactResultCallback : public ContactResultCallback
{

    bool bCollision;

    SimulationContactResultCallback : bCollision(false)
    {}

    btScalar addSingleResult(btManifoldPoint& cp,
        const btCollisionObjectWrapper* colObj0Wrap,
        int partId0,
        int index0,
        const btCollisionObjectWrapper* colObj1Wrap,
        int partId1,
        in index1)
    {
        //If cp distance less than threshold
        //bCollision = true
    }
};
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by jimjamjack »

Okay, that seems to work, thank you.

I'm now having a different issue though, when I get the collision object's index and print it, it's always the index of the object it ends up on after it stops moving. So for example, I shoot my fast moving bullet at the target (both have rigid bodies, and I'm using continuous collision detection) but rather than giving me the target's index, it's giving me the index of the floor that the bullet is on after losing its velocity.

It doesn't print anything when hitting the target, but prints the index a few times when it bounces around on the floor at the end of its movement.

Do you know why this is happening?
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by erbisme4@yahoo.com »

I can't tell for sure without looking at your code, but maybe instead of using ContactPairTest, which may be expensive(i'm not sure, haven't really used it much) use a btInternalTickCallback which will get called by InternalSingleStepSimulation. In the callback you can iterate over all the collision manifolds and get all the pairs of bodies colliding.
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Help with using contactPairTest() and ContactResultCallb

Post by jimjamjack »

I have continuous collision enabled on the bullet. But this still results in the hit with the target not being registered.
Post Reply