fix bullet contact data error (#13210) (#12195)

This commit is contained in:
Ling Zhan
2022-07-26 20:18:44 +08:00
committed by GitHub
parent 4644228090
commit c682c7c809
2 changed files with 18 additions and 13 deletions
+8 -5
View File
@@ -33,12 +33,15 @@ import { bullet2CocosQuat, bullet2CocosVec3 } from './bullet-utils';
export class BulletContactData implements IContactEquation {
get isBodyA (): boolean {
const sb = (this.event.selfCollider.shape as BulletShape).sharedBody.body;
return sb === bt.PersistentManifold_getBody0(this.impl);
return sb === bt.PersistentManifold_getBody0(this.event.impl);
}
impl: Bullet.ptr = 0;
impl: Bullet.ptr = 0; //btManifoldPoint
event: ICollisionEvent;
constructor (public event: ICollisionEvent) { }
constructor (event: ICollisionEvent) {
this.event = event;
}
getLocalPointOnA (out: IVec3Like): void {
if (this.impl) bullet2CocosVec3(out, bt.ManifoldPoint_get_m_localPointA(this.impl));
@@ -59,7 +62,7 @@ export class BulletContactData implements IContactEquation {
getLocalNormalOnA (out: IVec3Like): void {
if (this.impl) {
const bt_rot = BulletCache.instance.BT_QUAT_0;
const body = bt.PersistentManifold_getBody0(this.impl);
const body = bt.PersistentManifold_getBody0(this.event.impl);
const trans = bt.CollisionObject_getWorldTransform(body);
bt.Transform_getRotation(trans, bt_rot);
const inv_rot = CC_QUAT_0;
@@ -74,7 +77,7 @@ export class BulletContactData implements IContactEquation {
getLocalNormalOnB (out: IVec3Like): void {
if (this.impl) {
const bt_rot = BulletCache.instance.BT_QUAT_0;
const body = bt.PersistentManifold_getBody1(this.impl);
const body = bt.PersistentManifold_getBody1(this.event.impl);
const trans = bt.CollisionObject_getWorldTransform(body);
bt.Transform_getRotation(trans, bt_rot);
const inv_rot = CC_QUAT_0;
+10 -8
View File
@@ -276,7 +276,7 @@ export class BulletWorld implements IPhysicsWorld {
TriggerEventObject.type = 'onTriggerEnter';
this.triggerArrayMat.set(shape0.id, shape1.id, true);
}
TriggerEventObject.impl = data.impl;
TriggerEventObject.impl = data.impl; //btPersistentManifold
TriggerEventObject.selfCollider = collider0;
TriggerEventObject.otherCollider = collider1;
collider0.emit(TriggerEventObject.type, TriggerEventObject);
@@ -303,16 +303,18 @@ export class BulletWorld implements IPhysicsWorld {
}
for (let i = 0; i < data.contacts.length; i++) {
const cq = data.contacts[i];
const cq = data.contacts[i]; //btManifoldPoint
if (contactsPool.length > 0) {
const c = contactsPool.pop(); c!.impl = cq;
const c = contactsPool.pop();
c!.impl = cq; //btManifoldPoint
CollisionEventObject.contacts.push(c!);
} else {
const c = new BulletContactData(CollisionEventObject); c.impl = cq;
const c = new BulletContactData(CollisionEventObject);
c.impl = cq; //btManifoldPoint
CollisionEventObject.contacts.push(c);
}
}
CollisionEventObject.impl = data.impl;
CollisionEventObject.impl = data.impl; //btPersistentManifold
CollisionEventObject.selfCollider = collider0;
CollisionEventObject.otherCollider = collider1;
collider0.emit(CollisionEventObject.type, CollisionEventObject);
@@ -383,10 +385,10 @@ export class BulletWorld implements IPhysicsWorld {
gatherConatactData () {
const numManifolds = bt.Dispatcher_getNumManifolds(this._dispatcher);
for (let i = 0; i < numManifolds; i++) {
const manifold = bt.Dispatcher_getManifoldByIndexInternal(this._dispatcher, i);
const manifold = bt.Dispatcher_getManifoldByIndexInternal(this._dispatcher, i);//btPersistentManifold
const numContacts = bt.PersistentManifold_getNumContacts(manifold);
for (let j = 0; j < numContacts; j++) {
const manifoldPoint = bt.PersistentManifold_getContactPoint(manifold, j);
const manifoldPoint = bt.PersistentManifold_getContactPoint(manifold, j);//btManifoldPoint
const s0 = bt.ManifoldPoint_getShape0(manifoldPoint);
const s1 = bt.ManifoldPoint_getShape1(manifoldPoint);
const shape0: BulletShape = BulletCache.getWrapper(s0, BulletShape.TYPE);
@@ -400,7 +402,7 @@ export class BulletWorld implements IPhysicsWorld {
item = this.contactsDic.set(shape0.id, shape1.id,
{ shape0, shape1, contacts: [], impl: manifold });
}
item.contacts.push(manifoldPoint);
item.contacts.push(manifoldPoint);//btManifoldPoint
}
}
}