Пример #1
0
 public override void Initialize(Vector2 position)
 {
     navigator = Pathfinding2D.GetInstance().GetPathNavigatorToDestination(
         position,
         destination
         );
 }
Пример #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);
            }
        }
Пример #3
0
        public bool Update(Vector2 position)
        {
            if (waypoint_index < waypoints.Count)
            {
                if (Pathfinding2D.GetInstance().IsPotentialConnection(position, GetNextTargetPosition()))
                {
                    waypoint_index++;
                }

                return(true);
            }

            return(false);
        }
Пример #4
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());
            }
        }
Пример #5
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);
        }
Пример #6
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);
                }
            }
        }
Пример #7
0
 public IEnumerable <PathNode2D> CalculatePotentialConnections()
 {
     return(Pathfinding2D.GetInstance().GetPotentialConnections(this.GetPlanarPosition(), radius)
            .Skip(this));
 }
Пример #8
0
 public bool IsPotentialConnection(Vector2 position)
 {
     return(Pathfinding2D.GetInstance().IsPotentialConnection(this, position));
 }
Пример #9
0
 private void InitializePathNode()
 {
     this.SetLayer(Pathfinding2D.GetInstance().GetNodeLayer());
 }