Ejemplo n.º 1
0
        /// <inheritdoc />
        public RayCastResults IntersectRay(MapId mapId, CollisionRay ray, float maxLength = 50, IEntity ignoredEnt = null)
        {
            RayCastResults result = default;

            this[mapId].Query((ref IPhysBody body, in Vector2 point, float distFromOrigin) => {
                if (distFromOrigin > maxLength)
                {
                    return(true);
                }

                if (body.Owner == ignoredEnt)
                {
                    return(true);
                }

                if (!body.CollisionEnabled)
                {
                    return(true);
                }

                if ((body.CollisionLayer & ray.CollisionMask) == 0x0)
                {
                    return(true);
                }

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (result.Distance != 0f && distFromOrigin > result.Distance)
                {
                    return(true);
                }

                result = new RayCastResults(distFromOrigin, point, body.Owner);

                return(true);
            }, ray.Position, ray.Direction);
Ejemplo n.º 2
0
        /// <inheritdoc />
        public RayCastResults IntersectRayWithPredicate(MapId mapId, CollisionRay ray, float maxLength = 50, Func <IEntity, bool> predicate = null, bool ignoreNonHardCollidables = false)
        {
            RayCastResults result = default;

            this[mapId].Query((ref IPhysBody body, in Vector2 point, float distFromOrigin) => {
                if (distFromOrigin > maxLength)
                {
                    return(true);
                }

                if (predicate.Invoke(body.Owner))
                {
                    return(true);
                }

                if (!body.CollisionEnabled)
                {
                    return(true);
                }

                if ((body.CollisionLayer & ray.CollisionMask) == 0x0)
                {
                    return(true);
                }

                if (ignoreNonHardCollidables && !body.IsHardCollidable)
                {
                    return(true);
                }

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (result.Distance != 0f && distFromOrigin > result.Distance)
                {
                    return(true);
                }

                result = new RayCastResults(distFromOrigin, point, body.Owner);

                return(true);
            }, ray.Position, ray.Direction);
Ejemplo n.º 3
0
        /// <inheritdoc />
        public IEnumerable <RayCastResults> IntersectRayWithPredicate(MapId mapId, CollisionRay ray,
                                                                      float maxLength = 50F,
                                                                      Func <IEntity, bool>?predicate = null, bool returnOnFirstHit = true)
        {
            List <RayCastResults> results = new List <RayCastResults>();

            this[mapId].Query((ref IPhysBody body, in Vector2 point, float distFromOrigin) =>
            {
                if (returnOnFirstHit && results.Count > 0)
                {
                    return(true);
                }

                if (distFromOrigin > maxLength)
                {
                    return(true);
                }

                if (!body.CanCollide)
                {
                    return(true);
                }

                if ((body.CollisionLayer & ray.CollisionMask) == 0x0)
                {
                    return(true);
                }

                if (predicate != null && predicate.Invoke(body.Entity))
                {
                    return(true);
                }

                var result = new RayCastResults(distFromOrigin, point, body.Entity);
                results.Add(result);
                DebugDrawRay?.Invoke(new DebugRayData(ray, maxLength, result));
                return(true);
            }, ray.Position, ray.Direction);