Esempio n. 1
0
        public void TestCloseMiss()
        {
            Vector3      boxExtents = new Vector3(10.0f, 10.0f, 10.0f);
            LineContacts contacts   = Line3Aabb3Collider.FindContacts(
                new Vector3(0.0f, 0.0f, 10.1f), Vector3.Right, boxExtents
                );

            Assert.IsNaN(contacts.EntryTime);
            Assert.IsNaN(contacts.ExitTime);
        }
Esempio n. 2
0
        public void TestContactOnCornerDefinedBox()
        {
            LineContacts contacts = Line3Aabb3Collider.FindContacts(
                new Vector3(97.5f, -102.5f, 0.0f), Vector3.Up,
                new Vector3(90.0f, -110.0f, -10.0f), new Vector3(110.0f, -90.0f, 10.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
                );
        }
Esempio n. 3
0
        public void TestContact()
        {
            Vector3      boxExtents = new Vector3(10.0f, 10.0f, 10.0f);
            LineContacts contacts   = Line3Aabb3Collider.FindContacts(
                new Vector3(-2.5f, -2.5f, -2.5f), Vector3.Up, 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
                );
        }
Esempio n. 4
0
        public void TestDiagonalCloseMiss()
        {
            Vector3 boxExtents     = new Vector3(5.0f, 5.0f, 5.0f);
            Vector3 diagonalVector = Vector3.Normalize(Vector3.One);

            LineContacts contacts = Line3Aabb3Collider.FindContacts(
                new Vector3(-10.1f, 0.0f, 0.0f), diagonalVector, boxExtents
                );

            Assert.IsNaN(contacts.EntryTime);
            Assert.IsNaN(contacts.ExitTime);

            diagonalVector.Y = -diagonalVector.Y;

            contacts = Line3Aabb3Collider.FindContacts(
                new Vector3(0.0f, 10.1f, 0.0f), diagonalVector, boxExtents
                );

            Assert.IsNaN(contacts.EntryTime);
            Assert.IsNaN(contacts.ExitTime);
        }
Esempio n. 5
0
        /// <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 axis aligned box </param>
        /// <returns>The intersection points between the ray and the box, if any</returns>
        public static LineContacts FindContacts(
            Vector3 rayStart, Vector3 rayDirection, Vector3 boxExtents
            )
        {
            LineContacts contacts = Line3Aabb3Collider.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);
        }