Exemplo n.º 1
0
 public override void Initialize(Vector2 position)
 {
     navigator = Pathfinding2D.GetInstance().GetPathNavigatorToDestination(
         position,
         destination
         );
 }
Exemplo n.º 2
0
        private void GrowPathNode(PathNode2D node)
        {
            Vector2 position = node.GetPlanarPosition();
            float   radius   = node.GetRadius() + 0.01f;

            foreach (Vector2 direction in directions)
            {
                Vector2 edge_position = position + direction * radius;
                float   new_radius    = Pathfinding2D.GetInstance().GetPotentialFixedEdgeClearingRadius(edge_position, direction, true);

                Seed(edge_position + direction * new_radius, new_radius);
            }
        }
Exemplo n.º 3
0
        static public PathNavigator2D GetPathNavigatorToWander(this Pathfinding2D item, Vector2 origin, float target_distance, float max_angle_delta)
        {
            PathNode2D origin_node = item.GetConnectionNear(origin);

            if (origin_node != null)
            {
                return(new PathNavigator2D(
                           origin_node.GetWanderingAngleLimitedDegreesPath(target_distance, max_angle_delta)
                           ));
            }

            return(null);
        }
Exemplo n.º 4
0
        static public PathNavigator2D GetPathNavigatorToWander(this Pathfinding2D item, Vector2 origin, float target_distance)
        {
            PathNode2D origin_node = item.GetConnectionNear(origin);

            if (origin_node != null)
            {
                return(new PathNavigator2D(
                           origin_node.GetWanderingRandomPath(target_distance)
                           ));
            }

            return(null);
        }
Exemplo n.º 5
0
        public bool Update(Vector2 position)
        {
            if (waypoint_index < waypoints.Count)
            {
                if (Pathfinding2D.GetInstance().IsPotentialConnection(position, GetNextTargetPosition()))
                {
                    waypoint_index++;
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        protected override void GenerateInternal(Rect r)
        {
            rect = r;

            directions = directions = Vector2s.RadialFromDegrees(
                Floats.Line(0.0f, 360.0f, max_number_branches, false)
                ).ToList();

            active_nodes = new Queue <PathNode2D>();
            Seed(origin, Pathfinding2D.GetInstance().GetPotentialClearingRadius(origin));

            while (active_nodes.IsNotEmpty())
            {
                GrowPathNode(active_nodes.Dequeue());
            }
        }
Exemplo n.º 7
0
        public bool TryAlterDestination(Vector2 destination)
        {
            int           final_index;
            Pathfinding2D pathfinding = Pathfinding2D.GetInstance();

            if (waypoints.Offset(waypoint_index).TryApproximateEarliestEdge(
                    p => pathfinding.IsConnection(p, destination), out final_index)
                )
            {
                waypoints.RemoveEnding(waypoint_index + final_index + 1);
                waypoints.Add(destination);
                return(true);
            }

            return(false);
        }
Exemplo n.º 8
0
        private void GenerateQuadTree(Rect rect, int depth)
        {
            Vector2 position       = rect.GetCenterPoint();
            float   maximum_radius = rect.GetSize().GetMaxComponent();

            float acceptable_radius = maximum_radius * target_utilization;
            float radius            = Pathfinding2D.GetInstance().GetPotentialClearingRadius(position).BindBelow(maximum_radius * 2.0f);

            if (radius < acceptable_radius && depth < max_depth)
            {
                rect.SplitIntoQuarters().Process(r => GenerateQuadTree(r, depth + 1));
            }
            else
            {
                if (radius >= minimum_radius)
                {
                    AddPathNode(position, radius);
                }
            }
        }
Exemplo n.º 9
0
        static public PathNavigator2D GetPathNavigatorToDestination(this Pathfinding2D item, Vector2 origin, Vector2 destination)
        {
            if (item.IsConnection(origin, destination))
            {
                return(new PathNavigator2D(destination));
            }
            else
            {
                PathNode2D origin_node      = item.GetConnectionNear(origin);
                PathNode2D destination_node = item.GetConnectionNear(destination);

                if (origin_node != null && destination_node != null)
                {
                    return(new PathNavigator2D(
                               origin_node.GetOptimalPathTo(destination_node),
                               destination
                               ));
                }
            }

            return(null);
        }
Exemplo n.º 10
0
 static public bool IsPotentialConnection(this Pathfinding2D item, Component component1, Component component2)
 {
     return(item.IsPotentialConnection(component1.GetPlanarPosition(), component2.GetPlanarPosition()));
 }
Exemplo n.º 11
0
 static public bool IsPotentialConnection(this Pathfinding2D item, Vector2 position, Component component)
 {
     return(item.IsPotentialConnection(position, component.GetPlanarPosition()));
 }
Exemplo n.º 12
0
 static public bool IsConnection(this Pathfinding2D item, Component component, Vector2 position)
 {
     return(item.IsConnection(component.GetPlanarPosition(), position));
 }
Exemplo n.º 13
0
 public IEnumerable <PathNode2D> CalculatePotentialConnections()
 {
     return(Pathfinding2D.GetInstance().GetPotentialConnections(this.GetPlanarPosition(), radius)
            .Skip(this));
 }
Exemplo n.º 14
0
 public bool IsPotentialConnection(Vector2 position)
 {
     return(Pathfinding2D.GetInstance().IsPotentialConnection(this, position));
 }
Exemplo n.º 15
0
 private void InitializePathNode()
 {
     this.SetLayer(Pathfinding2D.GetInstance().GetNodeLayer());
 }