Pawel
Pawel

Reputation: 18222

Bullet physics(ammo.js in asm.js) how to get collision impact force

So I managed to get collisions detection working in ammo.js like they do in Physijs. Here's the code which works

var i,
    dp = this.dispatcher,
    num = dp.getNumManifolds(),
    manifold, num_contacts, j, pt;

for (i = 0; i < num; i++) {
    manifold = dp.getManifoldByIndexInternal(i);

    num_contacts = manifold.getNumContacts();
    if (num_contacts === 0) {
        continue;
    }

    for (j = 0; j < num_contacts; j++) {
        pt = manifold.getContactPoint(j);

        //console.log('body 1: ', manifold.getBody0());
        //console.log('body 2: ', manifold.getBody1());

        console.log('COLLISION DETECTED!');
        // HERE: how to get impact force details?
        // pt.getAppliedImpulse() is not working
    }
}

On some forums I found that this function gives information about impact force:

getAppliedImpulse()

but there's no such function in ammo.js. I text searched the code and it's not there. Maybe the API is newer or the approach to reading force is completely different?

Edit:

Here's my custom-built ammo with getAppliedImpulse() and many essential functions enabled. https://github.com/DVLP/ammo.js/tree/master/builds

Upvotes: 1

Views: 2061

Answers (1)

zakki
zakki

Reputation: 2353

Add a binding description to ammo.idl, and rebuild ammo.js.

interface btManifoldPoint {
    ...
    [Const] double getAppliedImpulse();
}

Upvotes: 2

Related Questions