Esempio n. 1
0
    public Path(Vector3[] waypoints, Vector3 startPos, float turnDist, float stoppingDist)
    {
        lookPoints      = waypoints;
        turnBoundaries  = new PathLine[lookPoints.Length];
        finishLineIndex = turnBoundaries.Length - 1;

        Vector2 previousPoint = V3ToV2(startPos);

        for (int i = 0; i < lookPoints.Length; i++)
        {
            Vector2 currentPoint      = V3ToV2(lookPoints[i]);
            Vector2 dirToCurrentPoint = (currentPoint - previousPoint).normalized;
            Vector2 turnBoundaryPoint = (i == finishLineIndex) ? currentPoint : currentPoint - dirToCurrentPoint * turnDist;
            turnBoundaries[i] = new PathLine(turnBoundaryPoint, previousPoint - dirToCurrentPoint * turnDist);
            previousPoint     = turnBoundaryPoint;
        }

        float distFromEndPoint = 0;

        for (int i = lookPoints.Length - 1; i > 0; i--)
        {
            distFromEndPoint += Vector3.Distance(lookPoints[i], lookPoints[i - 1]);
            if (distFromEndPoint > stoppingDist)
            {
                slowDownIndex = i;
                break;
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Draws a line between two waypoints.
    /// </summary>
    /// <param name="start">The starting waypoint of the line.</param>
    /// <param name="end">The ending waypoint of the line.</param>
    private void DrawLine(Waypoint start, Waypoint end)
    {
        PathLine line = Instantiate(lineRenderer) as PathLine;

        line.SetEndpoints(start.transform.position, end.transform.position);
        line.transform.parent = pathLines.transform;
    }
Esempio n. 3
0
        private void textBoxName_TextChanged(object sender, System.EventArgs e)
        {
            if (this.curPathList.Count > 0)
            {
                foreach (PathLine pl in this.curPathList)
                {
                    this.worldWindow.CurrentWorld.RenderableObjects.Remove(pl.Name);
                    pl.Dispose();
                }

                this.curPathList.Clear();
            }

            this.listBoxPaths.Items.Clear();
            DirectoryInfo inDir = new DirectoryInfo(this.saveDirPath + "/" + this.textBoxName.Text);

            if (inDir.Exists)
            {
                foreach (FileInfo file in inDir.GetFiles("*.wwb"))
                {
                    this.listBoxPaths.Items.Add(file.Name);
                    PathLine newPathLine = new PathLine(this.textBoxName.Text + " - " + file.Name, this.worldWindow.CurrentWorld, file.FullName, (float)this.numericUpDownHeight.Value, System.Drawing.Color.Red);
                    newPathLine.IsOn = true;
                    this.curPathList.Add(newPathLine);
                    this.worldWindow.CurrentWorld.RenderableObjects.Add(newPathLine);
                }
            }
        }
Esempio n. 4
0
        private void buttonStop_Click(object sender, System.EventArgs e)
        {
            try
            {
                this.timer.Stop();
                string saveFileName = this.saveDirPath + "/" + this.textBoxName.Text + "/" + this.getAvailableLineNumber() + ".wwb";
                if (this.curPathLine != null)
                {
                    this.curPathLine.SaveToFile(saveFileName);

                    if (File.Exists(saveFileName))
                    {
                        this.listBoxPaths.Items.Add(Path.GetFileName(saveFileName));
                    }

                    this.curPathList.Add(this.curPathLine);
                    this.curPathLine = null;
                }
                this.listBoxPaths.Enabled           = true;
                this.textBoxName.Enabled            = true;
                this.buttonStart.Enabled            = true;
                this.buttonStop.Enabled             = false;
                this.buttonSave.Enabled             = true;
                this.numericUpDownHeight.Enabled    = true;
                this.numericUpDownFrequency.Enabled = true;
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
Esempio n. 5
0
    private void touchBeganHandler(Touch touch)
    {
        Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);

        RaycastHit2D[] hits           = Physics2D.RaycastAll(touchPosition, -Vector2.up);
        GameObject     spaceCarrierGO = null;

        for (int i = 0; i < hits.Length; i++)
        {
            GameObject colliderGO = hits[i].collider.gameObject;
            if (colliderGO.tag == "TouchRadar")
            {
                spaceCarrierGO = colliderGO;
                break;
            }
        }
        if (spaceCarrierGO == null)
        {
            return;
        }
        PathLine     pathLine     = spaceCarrierGO.GetComponentInParent <PathLine>();
        TouchCarrier touchCarrier = new TouchCarrier(touch.fingerId, touch, pathLine);

        touches.Add(touchCarrier);
        touchCarrier.pathLine.touchBegan(getTouchWorldPosition(touchCarrier));
    }
Esempio n. 6
0
 /// <summary>
 /// Finds the navigator.
 /// </summary>
 private void Start()
 {
     navigator = GetComponent <Navigator>();
     user      = FindObjectOfType <Camera>().gameObject;
     if (items != null && items.Length > 0)
     {
         currentItem   = items[0];
         userLine      = Instantiate(navigator.lineRenderer) as PathLine;
         userLine.name = "User Line";
     }
 }
Esempio n. 7
0
    void Awake()
    {
        containerManager = GetComponentInChildren <ContainerManager>();

        engine = GetComponentInChildren <Engine>();

        proximityRadar = GetComponentInChildren <ProximityRadar>();

        pathLine           = GetComponent <PathLine>();
        rigidBody          = GetComponent <Rigidbody2D>();
        rigidBody.velocity = new Vector2(0, 0);
        turnToCenter();
    }
Esempio n. 8
0
    //create path out of perpendicular lines as checkpoints
    public Path(Vector2[] _waypoints, Vector2 _startPos)
    {
        points     = _waypoints;
        turnBounds = new PathLine[points.Length];
        finishLine = turnBounds.Length - 1;
        Vector2 previousPoint = _startPos;

        for (int i = 0; i < points.Length; i++)
        {
            Vector2 currentPoint      = points[i];
            Vector2 dirToCurrentPoint = (currentPoint - previousPoint).normalized;
            Vector2 boundaryPoint     = currentPoint - dirToCurrentPoint;
            turnBounds[i] = new PathLine(boundaryPoint, previousPoint - dirToCurrentPoint); //set checkpoint bounds for turning as perpendicular lines
            previousPoint = currentPoint;
        }
    }
Esempio n. 9
0
        private void buttonStart_Click(object sender, System.EventArgs e)
        {
            try
            {
                this.listBoxPaths.Enabled           = false;
                this.textBoxName.Enabled            = false;
                this.buttonStop.Enabled             = true;
                this.buttonStart.Enabled            = false;
                this.buttonSave.Enabled             = false;
                this.numericUpDownHeight.Enabled    = false;
                this.numericUpDownFrequency.Enabled = false;

                World.Settings.ShowCrosshairs = true;

                this.curPathLine = new PathLine(this.textBoxName.Text + " - " + this.getAvailableLineNumber() + ".wwb",
                                                this.worldWindow.CurrentWorld,
                                                null,
                                                (float)this.numericUpDownHeight.Value,
                                                System.Drawing.Color.Red);

                this.worldWindow.CurrentWorld.RenderableObjects.Add(this.curPathLine);
                this.curPathLine.IsOn = true;

                this.curHeight = (float)this.numericUpDownHeight.Value;

                this.lastPosition = new Microsoft.DirectX.Vector2((float)this.worldWindow.DrawArgs.WorldCamera.Latitude.Degrees, (float)this.worldWindow.DrawArgs.WorldCamera.Longitude.Degrees);
                this.curPathLine.AddPointToPath(this.lastPosition.X, this.lastPosition.Y, false, (float)this.numericUpDownHeight.Value);

                if (this.timer == null)
                {
                    this.timer          = new System.Timers.Timer((double)this.numericUpDownFrequency.Value);
                    this.timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
                }
                else
                {
                    this.timer.Interval = (double)this.numericUpDownFrequency.Value;
                }
                this.timer.Start();
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
Esempio n. 10
0
        public static List <Point2D> FindPath(Line lineA, Line lineB, PathLine pathLine = PathLine.Orthogonal, double angle = 0)
        {
            List <Point2D> linkPoints = new List <Point2D>();

            linkPoints.Add(lineA.ToStartPoint2D());

            switch (pathLine)
            {
            case PathLine.Straight:
                break;

            case PathLine.Orthogonal:
                GeometryCore.PathCalculator.DetermineOrthogonalPoints(lineA.ToLine2D(), lineB.ToLine2D(), ref linkPoints);
                break;
            }

            linkPoints.Add(lineB.ToStartPoint2D());
            if (angle != 0)
            {
                List <Point> bpoints = null;
                switch (pathLine)
                {
                case PathLine.Straight:
                    double radius = lineA.ToStartPoint2D().DetermineArcRadius(lineB.ToStartPoint2D(), angle);
                    bpoints = GetArcGeometry(lineA.ToStartPoint(), lineB.ToStartPoint(), radius).ToPointsList();
                    break;

                case PathLine.Orthogonal:
                    bpoints = GetBezierGeometry(linkPoints.Select(a => a.ToPoint()).ToList()).ToPointsList();
                    break;
                }
                linkPoints.Clear();
                foreach (var point in bpoints)
                {
                    linkPoints.Add(point.ToPoint2D());
                }
            }
            return(linkPoints);
        }
Esempio n. 11
0
    public void end()
    {
        b__command     = (PathType[])__command.ToArray(typeof(PathType));
        b__coordinates = (float[])__coordinates.ToArray(typeof(float));
        b__quats       = (Quaternion[])__quats.ToArray(typeof(Quaternion));

        int      cmd_len = __cmd_index;
        PathType c;
        int      ci   = 0;
        int      roti = 0;
        float    x;
        float    y;
        float    z;
        float    px     = 0;
        float    py     = 0;
        float    pz     = 0;
        int      path_i = 0;

        __length = 0;
        for (int i = 0; i < cmd_len; i++)
        {
            c = b__command[i];
            switch (c)
            {
            case PathType.__MOVE_TO:
                px  = b__coordinates[ci];
                py  = b__coordinates[ci + 1];
                pz  = b__coordinates[ci + 2];
                ci += 3;
                break;

            case PathType.__LINE_TO:
                x = b__coordinates[ci];
                y = b__coordinates[ci + 1];
                z = b__coordinates[ci + 2];
                PathLine pline = new PathLine(px, py, pz, x, y, z, b__quats[roti], b__quats[roti + 1]);
                //__path[path_i] = pline;
                __path.Add(pline);
                __length += pline.length;
                //__path_length[path_i] = __length;
                __path_length.Add(__length);
                path_i++;
                px    = x;
                py    = y;
                pz    = z;
                ci   += 3;
                roti += 1;
                break;

            case PathType.__CURVE_TO:
                x = b__coordinates[ci + 3];
                y = b__coordinates[ci + 4];
                z = b__coordinates[ci + 5];
                QBezier pbezier = new QBezier(px, py, pz, b__coordinates[ci], b__coordinates[ci + 1], b__coordinates[ci + 2], x, y, z, b__quats[roti], b__quats[roti + 1]);
                //__path[path_i] = pbezier;
                __path.Add(pbezier);
                __length += pbezier.length;
                //__path_length[path_i] = __length;
                __path_length.Add(__length);
                path_i++;
                px    = x;
                py    = y;
                pz    = z;
                ci   += 6;
                roti += 1;
                break;
            }
        }

        b__path        = (IPath[])__path.ToArray(typeof(IPath));
        b__path_length = (float[])__path_length.ToArray(typeof(float));
    }
Esempio n. 12
0
    public void end()
    {
        b__command = (PathType[])__command.ToArray( typeof(PathType) );
        b__coordinates = (float[])__coordinates.ToArray( typeof(float) );
        b__quats = (Quaternion[])__quats.ToArray( typeof(Quaternion) );

        int cmd_len = __cmd_index;
        PathType c;
        int ci = 0;
        int roti = 0;
        float x;
        float y;
        float z;
        float px = 0;
        float py = 0;
        float pz = 0;
        int path_i = 0;
        __length = 0;
        for ( int i = 0; i < cmd_len; i++ )
        {
            c = b__command[i];
            switch( c )
            {
                case PathType.__MOVE_TO:
                    px = b__coordinates[ci];
                    py = b__coordinates[ci + 1];
                    pz = b__coordinates[ci + 2];
                    ci += 3;
                    break;

                case PathType.__LINE_TO:
                    x = b__coordinates[ci];
                    y = b__coordinates[ci + 1];
                    z = b__coordinates[ci + 2];
                    PathLine pline = new PathLine( px, py, pz, x, y, z, b__quats[roti], b__quats[roti+1] );
                    //__path[path_i] = pline;
                    __path.Add( pline );
                    __length += pline.length;
                    //__path_length[path_i] = __length;
                    __path_length.Add( __length );
                    path_i++;
                    px = x;
                    py = y;
                    pz = z;
                    ci += 3;
                    roti += 1;
                    break;

                case PathType.__CURVE_TO:
                    x = b__coordinates[ci + 3];
                    y = b__coordinates[ci + 4];
                    z = b__coordinates[ci + 5];
                    QBezier pbezier =  new QBezier( px, py, pz, b__coordinates[ci], b__coordinates[ci + 1], b__coordinates[ci + 2], x, y, z, b__quats[roti], b__quats[roti+1] );
                    //__path[path_i] = pbezier;
                    __path.Add( pbezier );
                    __length += pbezier.length;
                    //__path_length[path_i] = __length;
                    __path_length.Add( __length );
                    path_i++;
                    px = x;
                    py = y;
                    pz = z;
                    ci += 6;
                    roti += 1;
                    break;
            }
        }

        b__path = (IPath[])__path.ToArray( typeof(IPath) );
        b__path_length = (float[])__path_length.ToArray( typeof(float) );
    }
    public PathLine OptimizePath(PathLine cluster)
    {
        PathLine line = new PathLine(new List <PathPoint>());

        //Построение матрицы расстояний между точками
        double[,] lengths = new double[cluster.Points.Count, cluster.Points.Count];
        for (int i = 0; i < cluster.Points.Count; i++)
        {
            for (int j = 0; j < cluster.Points.Count; j++)
            {
                if (i == j)
                {
                    lengths[i, j] = Double.MaxValue;
                }
                else if (i > j)
                {
                    lengths[i, j] = lengths[j, i];
                }
                else
                {
                    lengths[i, j] = cluster.Points[i].GetDistance(cluster.Points[j]);
                }
            }
        }

        int pointsCount = cluster.Points.Count;

        while (cluster.Points.Count > 1)       // проход алгоритма с уменьшением размерности матрицы расстояний

        // приведение матрицы
        {
            int    optI, optJ;
            double koef1 = Adduction(lengths, out optI, out optJ);

            double tmp = lengths[optJ, optI];     // для создания уменьшенной матрицы
            lengths[optJ, optI] = Double.MaxValue;

            // уменьшение матрицы
            double[,] buf = new double[cluster.Points.Count - 1, cluster.Points.Count - 1];
            for (int i = 0; i < buf.GetLength(0); i++)   // убираются строки
            {
                for (int j = 0; j < buf.GetLength(0); j++)
                {
                    if (i >= optI)
                    {
                        buf[i, j] = lengths[i + 1, j];
                    }
                    else
                    {
                        buf[i, j] = lengths[i, j];
                    }
                }
            }
            for (int i = 0; i < buf.GetLength(0); i++)   // убираются столбцы
            {
                for (int j = 0; j < buf.GetLength(0); j++)
                {
                    if (j >= optJ && i >= optI)
                    {
                        buf[i, j] = lengths[i + 1, j + 1];
                    }
                    else if (j >= optJ)
                    {
                        buf[i, j] = lengths[i, j + 1];
                    }
                }
            }

            lengths[optJ, optI] = tmp;

            // приведение матрицы во второй ветви
            double[,] lengths2 = (double[, ])buf.Clone();
            double koef2 = Adduction(lengths2, out optI, out optJ);

            if (koef2 < koef1 || cluster.Points.Count == 2)   // добавляем точку и переходим к меньшей матрице
            {
                line.Points.Add(cluster.Points[optI]);
                cluster.Points.RemoveAt(optI);     // устраняет смещение индексов для выбора новых точек
                lengths = buf;
            }
        }

        line.Points.Add(cluster.Points[0]);

        return(line);
    }
 void Awake()
 {
     instance    = this;
     pathfinding = GetComponent <PathLine>();
 }
Esempio n. 15
0
 public TouchCarrier(int fingerId, Touch touch, PathLine pathLine)
 {
     this.fingerId = fingerId;
     this.touch    = touch;
     this.pathLine = pathLine;
 }