示例#1
0
        public void TestParallelLineAbovePlane()
        {
            LineContacts contacts = Line3Plane3Collider.FindContacts(
                new Vector3(0.0f, 10.0f, 0.0f), Vector3.Right,
                new Vector3(0.0f, 0.0f, 0.0f), Vector3.Up
                );

            Assert.IsFalse(contacts.HasContact);
        }
示例#2
0
        public void TestParallelLineBelowPlane()
        {
            LineContacts contacts = Line3Plane3Collider.FindContacts(
                new Vector3(-10.0f, 0.0f, 0.0f), Vector3.Up,
                new Vector3(0.0f, 0.0f, 0.0f), Vector3.Left
                );

            Assert.IsFalse(contacts.HasContact);
        }
示例#3
0
        public void TestLineCrossingPlaneDiagonally()
        {
            LineContacts contacts = Line3Plane3Collider.FindContacts(
                new Vector3(-10.0f, 0.0f, 0.0f), Vector3.Normalize(Vector3.One),
                new Vector3(0.0f, 0.0f, 0.0f), Vector3.Left
                );
            float touchTime = 10.0f / Vector3.Normalize(Vector3.One).X;

            Assert.That(
                contacts.EntryTime,
                Is.EqualTo(touchTime).Within(Specifications.MaximumDeviation).Ulps
                );
            Assert.That(
                contacts.ExitTime,
                Is.EqualTo(touchTime).Within(Specifications.MaximumDeviation).Ulps
                );
        }
示例#4
0
        /// <summary>Determines where a ray will hit a plane, 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="planeOffset">Offset of the plane</param>
        /// <param name="planeNormal">Normal vector of the plane</param>
        /// <returns>The intersection points between the ray and the plane, if any</returns>
        public static LineContacts FindContacts(
            Vector3 rayStart, Vector3 rayDirection,
            Vector3 planeOffset, Vector3 planeNormal
            )
        {
            LineContacts contacts = Line3Plane3Collider.FindContacts(
                rayStart, rayDirection, planeOffset, planeNormal
                );

            // If the contact occured before the starting offset of the ray,
            // no collision took place since we're a ray
            if (!float.IsNaN(contacts.EntryTime))
            {
                if (contacts.EntryTime < 0.0f)
                {
                    return(LineContacts.None);
                }
            }

            return(contacts);
        }