//Test for Plane --> Sphere Collision public Contact Collides(Plane plane) { return base.Collides(this, plane); }
//Sphere --> Plane Collision Detection and Contact Info generation //Returns null if no collision, a contact object if a collision occurs protected Contact Collides(Sphere sphere, Plane plane) { //Remove the absolute value to allow full penetration of the sphere //float Distance = Vector3.Dot(plane.Normal, sphere.position - plane.position) / plane.Normal.Length(); float Distance = Math.Abs(Vector3.Dot(plane.Normal, sphere.Position - plane.Position)) / plane.Normal.Length(); if (Distance <= sphere.Radius) { Contact contact = new Contact(); contact.ContactType = CollisionType.FaceFace; contact.ContactNormal = plane.Normal; contact.PenetrationDepth = sphere.Radius - Distance; contact.ContactPoint = sphere.Position - contact.ContactNormal * Distance; contact.DeepestPoint = sphere.Position - contact.ContactNormal * (Distance + contact.PenetrationDepth); return contact; } //No Collision return null; }
//Box --> Plane Collision Detection and Contact Info generation //Returns null if no collision, a contact List object if a collision occurs protected List<Contact> Collides(Box box, Plane plane) { List<Contact> contacts = new List<Contact>(); Vector3[] Vertices = box.GetVertices(); foreach (Vector3 vertex in Vertices) { float Distance = Vector3.Dot(plane.Normal, vertex - plane.Position) / plane.Normal.Length(); if (Distance <= 0) { Contact contact = new Contact(); contact.ContactType = CollisionType.VertexFace; contact.ContactNormal = plane.Normal; contact.PenetrationDepth = -Distance; contact.ContactPoint = vertex; contact.DeepestPoint = vertex; contacts.Add(contact); } } return contacts; }
public List<Contact> Collides(Plane plane) { return base.Collides(this, plane); }