Contact lifetime is over 0 when checking for the first time.

Post Reply
Midnightas
Posts: 8
Joined: Fri Aug 24, 2018 9:03 pm

Contact lifetime is over 0 when checking for the first time.

Post by Midnightas »

Here's what I've done so far.

Code: Select all

int numManifolds = phys->getDispatcher()->getNumManifolds();
for(int i = 0; i < numManifolds; i++) {
    btPersistentManifold* manifold = phys->getDispatcher()->getManifoldByIndexInternal(i);
    printf("%i\n", manifold->getContactPoint(0).getLifeTime()); // this line is from memory.
    if(manifold->getContactPoint(0).getLifeTime() == 0) {
        ent* one = (ent*) manifold->getBody0()->getUserPointer();
        ent* two = (ent*) manifold->getBody1()->getUserPointer();

        one->onCollide(two);
        two->onCollide(one);

        printf("collid\n");
    }
}
The printf call sometimes prints values of 1, entirely skipping the zero, but otherwise I can't do proper collision callbacks..
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Contact lifetime is over 0 when checking for the first time.

Post by drleviathan »

If you want to know when two objects start touching and when they stop you could write your own pair-wise-contact map and check for new/expired contact manifolds. In pseudo code:

Code: Select all

given frame N
for each contact manifold:
    if object pair is known in map:
        set map entry to N
    else:
        add pair to map
        set entry to N
        emit collision START event

for each map entry:
    if entry value is not N:
        erase map entry
        emit collision END event
Midnightas
Posts: 8
Joined: Fri Aug 24, 2018 9:03 pm

Re: Contact lifetime is over 0 when checking for the first time.

Post by Midnightas »

Thank you, works perfectly!
Post Reply