コード例 #1
0
ファイル: Drone.cs プロジェクト: rakrob/GridNav
        public Drone(float droneRadius, float flightSpeed, Grid.Grid parentGrid)
        {
            //just setting some local variables, properties, things of that nature
            radius        = droneRadius; speed = flightSpeed; xPosition = parentGrid.startX; yPosition = parentGrid.startY;
            xGrid         = parentGrid;
            prevDirection = float.NaN;

            preComputeFlightPath = new FlightPath();
            preComputeFlightPath.addNode(xGrid.startX, xGrid.startY, false);
            preComputeFlightPath.addNode(xGrid.endX, xGrid.endY, true);
        }
コード例 #2
0
ファイル: Drone.cs プロジェクト: rakrob/GridNav
        public FlightPath BeginFlight()
        {
            //Start our index at 1 because 0 will always be our origin and we want to fly towards the first node
            pathNodeIndex = 1;
            path          = new FlightPath();

            xPosition = xGrid.startX;
            yPosition = xGrid.startY;

            direction           = float.NaN;
            prevCollidingEdge   = null;
            prevCollidingCorner = null;

            eliminatedCorners = new List <Grid.Corner>();

            //main control loop for a single flight
            do
            {
                //determine the direction in which we should move via our estimated path
                CalculateDirection(preComputeFlightPath);

                //move in said direction and increment the path node if we have arrived at one
                Move(preComputeFlightPath);

                //terminate loop if we have reached the last node, i.e. the end
            } while (pathNodeIndex < preComputeFlightPath.path.Count());

            //add that end node since we didn't get a chance to do it earlier
            path.addNode(xGrid.endX, xGrid.endY, true);

            return(path);
        }
コード例 #3
0
ファイル: Drone.cs プロジェクト: rakrob/GridNav
        public FlightPath OptimizeFlightPath()
        {
            FlightPath copyPath = new FlightPath();

            foreach (FlightPath.PathNode x in path.path)
            {
                copyPath.addNode(x.node.X, x.node.Y, x.optimal);
            }

            float maxDistance = 0;

            for (int i = path.path.Count - 1; i > 0; i--)
            {
                if (!copyPath.path.ElementAt(i).optimal)
                {
                    copyPath.path.RemoveAt(i);
                    continue;
                }

                float d       = Length(new PointF(copyPath.path.ElementAt(i).node.X - copyPath.path.ElementAt(copyPath.path.Count - 1).node.X, copyPath.path.ElementAt(i).node.Y - copyPath.path.ElementAt(copyPath.path.Count - 1).node.Y));
                bool  removed = false;

                if (d < maxDistance)
                {
                    copyPath.path.RemoveAt(i);
                    removed = true;
                }

                maxDistance = d;

                if (removed)
                {
                    continue;
                }

                if (i < path.path.Count - 2)
                {
                    float l1 = Length(new PointF(copyPath.path.ElementAt(i + 1).node.X - copyPath.path.ElementAt(i - 1).node.X, copyPath.path.ElementAt(i + 1).node.Y - copyPath.path.ElementAt(i - 1).node.Y));
                    float l2 = Length(new PointF(copyPath.path.ElementAt(i).node.X - copyPath.path.ElementAt(i - 1).node.X, copyPath.path.ElementAt(i).node.Y - copyPath.path.ElementAt(i - 1).node.Y));

                    if (l2 > l1)
                    {
                        copyPath.path.RemoveAt(i);
                        continue;
                    }
                }
            }

            preComputeFlightPath = copyPath;
            return(copyPath);
        }