public void TestCloseMiss()
 {
     Assert.IsFalse(
         Line3Sphere3Collider.FindContacts(
             new Vector3(0.0f, 10.1f, 0.0f), Vector3.Right,
             Vector3.Zero, 10.0f
             ).HasContact
         );
 }
        public void TestCenterCrossing()
        {
            Vector3      diagonalUnit = Vector3.Normalize(Vector3.One);
            LineContacts contacts     = Line3Sphere3Collider.FindContacts(
                diagonalUnit * -15.0f, diagonalUnit,
                Vector3.Zero, 10.0f
                );

            Assert.That(
                contacts.EntryTime,
                Is.EqualTo(5.0f).Within(Specifications.MaximumDeviation).Ulps
                );
            Assert.That(
                contacts.ExitTime,
                Is.EqualTo(25.0f).Within(Specifications.MaximumDeviation).Ulps
                );
        }
Beispiel #3
0
        /// <summary>Determines where a ray will hit a sphere, 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="sphereCenter">Center of the sphere</param>
        /// <param name="sphereRadius">Radius of the sphere</param>
        /// <returns>The intersection points between the ray and the box, if any</returns>
        public static LineContacts FindContacts(
            Vector3 rayStart, Vector3 rayDirection, Vector3 sphereCenter, float sphereRadius
            )
        {
            LineContacts contacts = Line3Sphere3Collider.FindContacts(
                rayStart, rayDirection, sphereCenter, sphereRadius
                );

            // 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);
        }