public void TestCloseMiss() { Vector2 boxExtents = new Vector2(10.0f, 10.0f); LineContacts contacts = Line2Aabb2Collider.FindContacts( new Vector2(0.0f, 10.1f), Vector2.UnitX, boxExtents ); Assert.IsNaN(contacts.EntryTime); Assert.IsNaN(contacts.ExitTime); }
public void TestContact() { Vector2 boxExtents = new Vector2(10.0f, 10.0f); LineContacts contacts = Line2Aabb2Collider.FindContacts( new Vector2(-2.5f, -2.5f), Vector2.UnitY, boxExtents ); Assert.That( contacts.EntryTime, Is.EqualTo(-7.5f).Within(Specifications.MaximumDeviation).Ulps ); Assert.That( contacts.ExitTime, Is.EqualTo(12.5f).Within(Specifications.MaximumDeviation).Ulps ); }
public void TestContactOnCornerDefinedBox() { LineContacts contacts = Line2Aabb2Collider.FindContacts( new Vector2(97.5f, -102.5f), Vector2.UnitY, new Vector2(90.0f, -110.0f), new Vector2(110.0f, -90.0f) ); Assert.That( contacts.EntryTime, Is.EqualTo(-7.5f).Within(Specifications.MaximumDeviation).Ulps ); Assert.That( contacts.ExitTime, Is.EqualTo(12.5f).Within(Specifications.MaximumDeviation).Ulps ); }
public void TestDiagonalCloseMiss() { Vector2 boxExtents = new Vector2(5.0f, 5.0f); Vector2 diagonalVector = Vector2.Normalize(Vector2.One); LineContacts contacts = Line2Aabb2Collider.FindContacts( new Vector2(-10.1f, 0.0f), diagonalVector, boxExtents ); Assert.IsNaN(contacts.EntryTime); Assert.IsNaN(contacts.ExitTime); diagonalVector.Y = -diagonalVector.Y; contacts = Line2Aabb2Collider.FindContacts( new Vector2(0.0f, 10.1f), diagonalVector, boxExtents ); Assert.IsNaN(contacts.EntryTime); Assert.IsNaN(contacts.ExitTime); }
/// <summary>Determines where a ray will hit a box, if at all</summary> /// <param name="rayStart">Starting point of the ray</param> /// <param name="rayDirection">Direction into which the ray extends</param> /// <param name="boxExtents">Extents of the box</param> /// <returns>The intersection points between the ray and the box, if any</returns> public static LineContacts FindContacts( Vector2 rayStart, Vector2 rayDirection, Vector2 boxExtents ) { LineContacts contacts = Line2Aabb2Collider.FindContacts( rayStart, rayDirection, boxExtents ); // If the line has entered the box before the reference point, this means // that the ray starts within the box, thus, its first contact occurs immediately if (!float.IsNaN(contacts.EntryTime)) { if (contacts.ExitTime < 0.0f) // Entry & exit before the ray's beginning? { return(LineContacts.None); } else if (contacts.EntryTime < 0.0f) // Only entry before ray's beginning? { contacts.EntryTime = 0.0f; } } return(contacts); }