public Initialize ( RigidBody body1, RigidBody body2, Jitter.LinearMath.JVector &point1, Jitter.LinearMath.JVector &point2, Jitter.LinearMath.JVector &n, float penetration, bool newContact, |
||
body1 | RigidBody | The first body. |
body2 | RigidBody | The second body. |
point1 | Jitter.LinearMath.JVector | The collision point in worldspace |
point2 | Jitter.LinearMath.JVector | The collision point in worldspace |
n | Jitter.LinearMath.JVector | The normal pointing to body2. |
penetration | float | The estimated penetration depth. |
newContact | bool | |
settings | ||
Результат | void |
/// <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 Contact AddContact(JVector point1, JVector point2, JVector normal, float penetration, ContactSettings contactSettings) { JVector relPos1; JVector.Subtract(ref point1, ref body1.position, out relPos1); int index; lock (contactList) { if (this.contactList.Count == 4) { index = SortCachedPoints(ref relPos1, penetration); ReplaceContact(ref point1, ref point2, ref normal, penetration, index, contactSettings); return(null); } index = GetCacheEntry(ref relPos1, contactSettings.breakThreshold); if (index >= 0) { ReplaceContact(ref point1, ref point2, ref normal, penetration, index, contactSettings); return(null); } else { Contact contact = Contact.Pool.GetNew(); contact.Initialize(body1, body2, ref point1, ref point2, ref normal, penetration, true, contactSettings); contactList.Add(contact); return(contact); } } }
private void ReplaceContact(ref JVector point1, ref JVector point2, ref JVector n, float p, int index, ContactSettings contactSettings) { Contact contact = contactList[index]; Debug.Assert(body1 == contact.body1, "Body1 and Body2 not consistent."); contact.Initialize(body1, body2, ref point1, ref point2, ref n, p, false, contactSettings); }
/// <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); } }