Example #1
0
        /// <summary>
        /// Reports all edges intersecting specified line segment while ISegmentCast.RegisterCollision returns true.
        /// Collisions are reported in order of their distance from segmentCast.Origin.
        /// </summary>
        /// <param name="segmentCast">Cast data</param>
        /// <param name="allocator">Allocator used to create internal buffers</param>
        public static void CastSegment <T>(this Navmesh navmesh, T segmentCast, Allocator allocator) where T : ISegmentCast
        {
            var open = new NativeList <IntPtr>(allocator);

            navmesh.CastSegment(segmentCast, open);
            open.Dispose();
        }
Example #2
0
        /// <summary>
        /// Reports all edges intersecting specified ray while ISegmentCast.RegisterCollision returns true.
        /// Collisions are reported in order of their distance from rayCast.Origin.
        /// </summary>
        /// <param name="segmentCast">Cast data</param>
        /// <param name="open">NativeList for internal use, is cleared before use</param>
        public static void CastRay <T>(this Navmesh navmesh, T rayCast, NativeList <IntPtr> open) where T : IRayCast
        {
            Assert.IsTrue(rayCast.Distance >= 0, "Ray cast distance should be larger than or equal to zero");
            Assert.IsTrue(math.abs(1 - math.length(rayCast.Direction)) < .001f, "Ray cast direction should be normalized");

            open.Clear();
            var h    = navmesh.Max;
            var dist = math.min(math.max(h.x, h.y) * 4, rayCast.Distance);
            var org  = rayCast.Origin;
            var dest = org + rayCast.Direction * dist;

            if (!navmesh.Contains(dest))
            {
                var d = dest;
                if (!IntersectSegSeg(org, d, -h, new double2(h.x, -h.y), out dest) &&
                    !IntersectSegSeg(org, d, new double2(h.x, -h.y), h, out dest) &&
                    !IntersectSegSeg(org, d, h, new double2(-h.x, h.y), out dest))
                {
                    IntersectSegSeg(org, d, new double2(-h.x, h.y), -h, out dest);
                }
            }

            var segmentCast = new RayCastWrapper <T>(dest, rayCast);

            navmesh.CastSegment(segmentCast, open);
        }
Example #3
0
 public void Execute()
 {
     Navmesh.CastSegment(Input, Allocator.Temp);
 }