/// <summary> /// Adds a contact to the arbiter (threadsafe). No more than four contacts /// are stored in the contactList. When adding a new contact /// to the arbiter the existing are checked and the best are kept. /// </summary> /// <param name="point1">Point on body1. In world space.</param> /// <param name="point2">Point on body2. In world space.</param> /// <param name="normal">The normal pointing to body2.</param> /// <param name="penetration">The estimated penetration depth.</param> public void AddContact(JVector point1, JVector point2, JVector normal, JVector[] triangle, float penetration, ContactSettings contactSettings) { // Returning false means that the contact doesn't need to be kept (likely because data from the contact // was used to manually update controllers). if (!World.Events.RaiseContactCreated(body1, body2, point1, point2, normal, triangle, penetration)) { return; } JVector.Subtract(ref point1, ref body1.position, out var relPos1); lock (contactList) { int index; if (contactList.Count == 4) { index = SortCachedPoints(ref relPos1, penetration); ReplaceContact(ref point1, ref point2, ref normal, triangle, penetration, index, contactSettings); // TODO: I added this return (to prevent contact count blowing up). Is this correct? return; } index = GetCacheEntry(ref relPos1, contactSettings.breakThreshold); if (index >= 0) { ReplaceContact(ref point1, ref point2, ref normal, triangle, penetration, index, contactSettings); } Contact contact = Contact.Pool.GetNew(); contact.Initialize(body1, body2, ref point1, ref point2, ref normal, triangle, penetration, true, contactSettings); contactList.Add(contact); } }
public Contact AddContact( JVector point1, JVector point2, JVector normal, float penetration, ContactSettings contactSettings) { JVector.Subtract(point1, body1.position, out var relPos1); int index; lock (contactList) { if (contactList.Count == 4) { index = SortCachedPoints(relPos1, penetration); ReplaceContact(point1, point2, normal, penetration, index, contactSettings); return(null); } index = GetCacheEntry(relPos1, contactSettings.breakThreshold); if (index >= 0) { ReplaceContact(point1, point2, normal, penetration, index, contactSettings); return(null); } else { var contact = Contact.Pool.GetNew(); contact.Initialize(body1, body2, point1, point2, normal, penetration, true, contactSettings); contactList.Add(contact); return(contact); } } }