Пример #1
0
        private Vector2f[] IntersectionPoints(FloatLine ray, RectangleShape shape)
        {
            var l1 = new FloatLine(shape.Position, shape.Position + new Vector2f(shape.Size.X, 0));
            var l2 = new FloatLine(shape.Position, shape.Position + new Vector2f(0, shape.Size.Y));
            var l3 = new FloatLine(
                shape.Position.X,
                shape.Position.Y + shape.Size.Y,
                shape.Position.X + shape.Size.X,
                shape.Position.Y + shape.Size.Y
                );
            var l4 = new FloatLine(
                shape.Position.X + shape.Size.X,
                shape.Position.Y,
                shape.Position.X + shape.Size.X,
                shape.Position.Y + shape.Size.Y
                );

            var intersections = new List <Vector2f?>
            {
                ray.Intersects(l1),
                ray.Intersects(l2),
                ray.Intersects(l3),
                ray.Intersects(l4),
            };

            return(intersections
                   .Where(x => x != null)
                   .Cast <Vector2f>()
                   .ToArray());
        }
Пример #2
0
        private Vector2f[] IntersectionPoints(FloatLine ray, LineShape shape)
        {
            var line = new FloatLine(shape.P1, shape.P2);
            var intersectionPoint = ray.Intersects(line);

            return(intersectionPoint.HasValue ? new[] { intersectionPoint.Value } : new Vector2f[0]);
        }
Пример #3
0
        private Vector2f[] IntersectionPoints(FloatLine ray, CircleShape shape)
        {
            var circle = new FloatCircle(shape.Position, shape.Radius);

            var circleDelta = (shape.Position - Position);
            var product     = Direction.Dot(circleDelta);

            if (product <= 0) // if ray is facing in the opposite direction of the circle
            {
                return(Array.Empty <Vector2f>());
            }

            return(ray.Intersects(circle));
        }