private void CollisionDetected(RigidBody body1, RigidBody body2, JVector point1, JVector point2, JVector normal, float penetration) { Arbiter arbiter = null; lock (arbiterMap) { arbiterMap.LookUpArbiter(body1, body2, out arbiter); if (arbiter == null) { arbiter = Arbiter.Pool.GetNew(); arbiter.body1 = body1; arbiter.body2 = body2; arbiterMap.Add(new ArbiterKey(body1, body2), arbiter); addedArbiterQueue.Enqueue(arbiter); events.RaiseBodiesBeginCollide(body1, body2); } } Contact contact = null; if (arbiter.body1 == body1) { JVector.Negate(ref normal, out normal); contact = arbiter.AddContact(point1, point2, normal, penetration, contactSettings); } else { contact = arbiter.AddContact(point2, point1, normal, penetration, contactSettings); } if (contact != null) { events.RaiseContactCreated(contact); } }
private void CollisionDetected(RigidBody body1, RigidBody body2, FPVector point1, FPVector point2, FPVector normal, FP penetration) { bool anyBodyColliderOnly = body1.IsColliderOnly || body2.IsColliderOnly; Arbiter arbiter = null; ArbiterMap selectedArbiterMap = null; if (anyBodyColliderOnly) { selectedArbiterMap = arbiterTriggerMap; } else { selectedArbiterMap = arbiterMap; } bool arbiterCreated = false; lock (selectedArbiterMap) { selectedArbiterMap.LookUpArbiter(body1, body2, out arbiter); if (arbiter == null) { arbiter = Arbiter.Pool.GetNew(); arbiter.body1 = body1; arbiter.body2 = body2; selectedArbiterMap.Add(new ArbiterKey(body1, body2), arbiter); arbiterCreated = true; } } Contact contact = null; if (arbiter.body1 == body1) { FPVector.Negate(ref normal, out normal); contact = arbiter.AddContact(point1, point2, normal, penetration, contactSettings); } else { contact = arbiter.AddContact(point2, point1, normal, penetration, contactSettings); } if (arbiterCreated) { if (anyBodyColliderOnly) { /*if (body1.isColliderOnly) { * events.RaiseTriggerBeginCollide(body1, body2); * } else { * events.RaiseTriggerBeginCollide(body2, body1); * }*/ events.RaiseTriggerBeginCollide(contact); body1.arbitersTrigger.Add(arbiter); body2.arbitersTrigger.Add(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = contact; initialTriggers.Add(overlapContact); } else { events.RaiseBodiesBeginCollide(contact); addedArbiterQueue.Enqueue(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = contact; initialCollisions.Add(overlapContact); } } if (!anyBodyColliderOnly && contact != null) { events.RaiseContactCreated(contact); } }
private void CollisionDetected(RigidBody body1, RigidBody body2, TSVector point1, TSVector point2, TSVector normal, FP penetration) { bool anyBodyColliderOnly = body1.IsColliderOnly || body2.IsColliderOnly; Arbiter arbiter = null; ArbiterMap selectedArbiterMap = null; if (anyBodyColliderOnly) { selectedArbiterMap = arbiterTriggerMap; } else { selectedArbiterMap = arbiterMap; } bool arbiterCreated = false; lock (selectedArbiterMap) { selectedArbiterMap.LookUpArbiter(body1, body2, out arbiter); if (arbiter == null) { arbiter = Arbiter.Pool.GetNew(); arbiter.body1 = body1; arbiter.body2 = body2; selectedArbiterMap.Add(new ArbiterKey(body1, body2), arbiter); arbiterCreated = true; } } Contact contact = null; if (arbiter.body1 == body1) { TSVector.Negate(ref normal, out normal); contact = arbiter.AddContact(point1, point2, normal, penetration, contactSettings); } else { contact = arbiter.AddContact(point2, point1, normal, penetration, contactSettings); } if (arbiterCreated) { if (anyBodyColliderOnly) { /*if (body1.isColliderOnly) { * events.RaiseTriggerBeginCollide(body1, body2); * } else { * events.RaiseTriggerBeginCollide(body2, body1); * }*/ events.RaiseTriggerBeginCollide(contact); body1.arbitersTrigger.Add(arbiter); body2.arbitersTrigger.Add(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = contact; initialTriggers.Add(overlapContact); } else { events.RaiseBodiesBeginCollide(contact); addedArbiterQueue.Enqueue(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = contact; initialCollisions.Add(overlapContact); } } else if (contact != null) { cacheOverPairContact.SetBodies(body1, body2); //if (!initialTriggers.Contains(cacheOverPairContact)) Debug.LogWarning("不包含=========="); int cacheOverPairContactHashCode = cacheOverPairContact.GetHashCode(); //cacheOverPairContact.contact = contact;//为什么不在这里这里赋值?因为cacheOverPairContact居然不一定能正确拿到对应在initialTriggers里面的op //所以只能在下面循环查找出对应的实例化对象 for (int index = 0, length = initialTriggers.Count; index < length; index++) { OverlapPairContact op = initialTriggers[index]; if (op.GetHashCode() == cacheOverPairContactHashCode) { op.contact = contact; //Debug.LogErrorFormat("包含3=====:法向量{0},穿透{1},哈希{2}", op.contact.normal.ToString(), op.contact.Penetration, op.GetHashCode()); } } } if (!anyBodyColliderOnly && contact != null) { events.RaiseContactCreated(contact); } }
private void CollisionDetected(RigidBody body1, RigidBody body2, TSVector point1, TSVector point2, TSVector normal, FP penetration) { bool anyBodyColliderOnly = body1.IsColliderOnly || body2.IsColliderOnly; Arbiter arbiter = null; ArbiterMap selectedArbiterMap = null; if (anyBodyColliderOnly) { selectedArbiterMap = arbiterTriggerMap; } else { selectedArbiterMap = arbiterMap; } bool arbiterCreated = false; if (!selectedArbiterMap.LookUpArbiter(body1, body2, out arbiter)) { arbiter = Arbiter.Pool.GetNew(); arbiter.body1 = body1; arbiter.body2 = body2; selectedArbiterMap.lookUpKey.body1 = body1; selectedArbiterMap.lookUpKey.body2 = body2; selectedArbiterMap.Add(selectedArbiterMap.lookUpKey.GetHashCode(), arbiter); arbiterCreated = true; } Contact contact = null; if (arbiter.body1 == body1) { TSVector.Negate(ref normal, out normal); contact = arbiter.AddContact(point1, point2, normal, penetration, contactSettings); } else { contact = arbiter.AddContact(point2, point1, normal, penetration, contactSettings); } if (arbiterCreated) { Contact raiseContact = Contact.Pool.GetNew(); if (contact != null) { raiseContact.Initialize(contact.body1, contact.body2, ref contact.p1, ref contact.p2, ref contact.normal, contact.penetration, contact.newContact, contact.settings); } if (anyBodyColliderOnly) { /*if (body1.isColliderOnly) { * events.RaiseTriggerBeginCollide(body1, body2); * } else { * events.RaiseTriggerBeginCollide(body2, body1); * }*/ events.RaiseTriggerBeginCollide(raiseContact); body1.arbitersTrigger.Add(arbiter); body2.arbitersTrigger.Add(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = raiseContact; //initialTriggers.Add(overlapContact); initialTriggers[overlapContact] = raiseContact; } else { events.RaiseBodiesBeginCollide(raiseContact); addedArbiterQueue.Enqueue(arbiter); OverlapPairContact overlapContact = new OverlapPairContact(body1, body2); overlapContact.contact = raiseContact; //initialCollisions.Add(overlapContact); initialCollisions[overlapContact] = raiseContact; } } if (!anyBodyColliderOnly && contact != null) { events.RaiseContactCreated(contact); } }