所以我设法在ammo.js中进行碰撞检测,就像在Physijs中一样。这是有效的代码
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
}
}
在某些论坛上,我发现此功能提供了有关冲击力的信息:
getAppliedImpulse()
但ammo.js中没有这样的功能。我发短信搜索了代码而它没有。也许API更新或读取力的方法完全不同?
修改
这是我使用getAppliedImpulse()定制的弹药,并启用了许多基本功能。 https://github.com/DVLP/ammo.js/tree/master/builds
答案 0 :(得分:1)
向ammo.idl
添加绑定说明,并重建ammo.js。
interface btManifoldPoint {
...
[Const] double getAppliedImpulse();
}