/// <summary>
    /// 利用3个点得到两个pointLine
    /// </summary>
    /// <param name="verticals"></param>
    /// <returns></returns>
    public static void GetPointLines(PointLines pls, int id, /*Color32[] colors,*/ Vector3[] verticals)
    {
        List <PointLine> olds = pls.data.FindAll(x => x.id == id);

        if (olds != null && olds.Count > 0)
        {
            foreach (var item in olds)
            {
                item.ReFleshPos(/*colors,*/ verticals);
            }
        }
        else//第一次加载时,可预测
        {
            for (int i = 0; i < verticals.Length; ++i)
            {
                for (int j = i + 1; j < verticals.Length; ++j)
                {
                    Vector3 nor = Vector3.Normalize(verticals[i] - verticals[j]);

                    if (ApproximateRights(nor, true) || ApproximateRights(nor, false))//轴向
                    {
                        //去除重复的线
                        if (pls.data.Find(x => { return((x.startPoint == verticals[i] && x.endPoint == verticals[j]) || (x.startPoint == verticals[j] && x.endPoint == verticals[i])); }) == null)
                        {
                            PointLine pl = new PointLine(/*colors[i], */ verticals[i], verticals[j], id, i, j);
                            pls.data.Add(pl);
                        }
                    }
                }
            }
        }
    }
Example #2
0
 /// <summary>
 /// 利用网格信息得到线集合
 /// </summary>
 /// <param name="meshData"></param>
 /// <returns></returns>
 public static void UpdatePointLines(MeshStruct meshData, ref PointLines pointLine)
 {
     for (int i = 0; i < meshData.triangles.Length - 2; i += 3)
     {
         PointLine.GetPointLines(pointLine, i,
                                 new Vector3[] { meshData.vertices[meshData.triangles[i]], meshData.vertices[meshData.triangles[i + 1]], meshData.vertices[meshData.triangles[i + 2]] });
     }
 }
Example #3
0
        private void ButtonSolveClick(object sender, RoutedEventArgs e)
        {
            if (_currentPolyLine.Points.Count >= 2)
            {
                _currentPolyLine.Points.Add(_currentPolyLine.Points[0]);
            }

            var initialState = new PathFindingState(new Search.Types.Point(100, 100));
            var goalState    = new PathFindingState(new Search.Types.Point(800, 600));

            var environment = new PathFindingEnvironment();

            foreach (var polyLine in _polyLines)
            {
                var points = polyLine.Points.Select(p => p).Distinct().ToList();
                for (int i = 0; i < points.Count; i++)
                {
                    for (int j = i + 1; j < points.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }

                        var pointLine = new PointLine(
                            new Point(points[i].X, points[i].Y),
                            new Point(points[j].X, points[j].Y));

                        environment.PointLines.Add(pointLine);
                    }
                }
            }

            var actionFunction  = new PathFindingActionFunction(environment, goalState);
            var resultFunction  = new PathFindingResultFunction();
            var goalTest        = new PathFindingGoalTest(goalState);
            var stepCost        = new PathFindingStepCost();
            var searchAlgorithm = new GraphSearch <PathFindingState, PathFindingAction>();

            var problem = new Problem <PathFindingState, PathFindingAction>(initialState, actionFunction, resultFunction, goalTest, stepCost);

            var solution = searchAlgorithm.Search(problem);

            for (int i = 1; i < solution.Count; i++)
            {
                AddLine(
                    solution[i - 1].State.Point.X,
                    solution[i - 1].State.Point.Y,
                    solution[i].State.Point.X,
                    solution[i].State.Point.Y);
            }
        }
Example #4
0
    public LevelMediator(LevelManager manager) : base(NAME, manager)
    {
        this.manager = manager;

        var obj = GameObject.Find("Cubes");

        if (obj == null)
        {
            obj = new GameObject("Cubes");
        }
        obj.transform.position = Vector3.zero;//   new Vector3(-3, -3);
        manager.Init(obj.transform);
        line = new PointLine();
    }
Example #5
0
                public List <Point> GetPointLine()
                {
                    List <Point> points      = new List <Point>();
                    PointLine    twoPoint    = GetPoints();
                    int          dX          = -GetDirection(twoPoint.Point1.X, twoPoint.Point2.X);
                    int          dY          = -GetDirection(twoPoint.Point1.Y, twoPoint.Point2.Y);
                    int          differenceX = twoPoint.Point1.X - twoPoint.Point2.X;
                    int          differenceY = twoPoint.Point1.Y - twoPoint.Point2.Y;
                    int          x           = twoPoint.Point1.X;
                    int          y           = twoPoint.Point1.Y;

                    if (debugMode)
                    {
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(dX) + ": " + dX);
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(dY) + ": " + dY);
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(differenceX) + ": " + differenceX);
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(differenceY) + ": " + differenceY);
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(x) + ": " + x);
                        ReferenceSamples.azercadmium.Logger.Debug(nameof(y) + ": " + y);
                    }

                    for (int i = 0; i < (Math.Abs(differenceX) + 1); i++)
                    {
                        points.Add(new Point(x, y));
                        x += dX;

                        bool flag = false;
                        if (Math.Abs(differenceY) > 0 && dY != 0) // So it never divides by zero
                        {
                            for (int j = 1; j < (Math.Abs(differenceY) + 1); j++)
                            {
                                int quotient = (int)Math.Abs(differenceX / (float)differenceY * j);

                                if (debugMode)
                                {
                                    ReferenceSamples.azercadmium.Logger.Debug(nameof(i) + ": " + i);
                                    ReferenceSamples.azercadmium.Logger.Debug(nameof(j) + ": " + j);
                                    ReferenceSamples.azercadmium.Logger.Debug(nameof(quotient) + ": " + quotient);
                                }

                                if (i < quotient)
                                {
                                    break;
                                }

                                if (i == quotient)
                                {
                                    if (flag)
                                    {
                                        points.Add(new Point(x, y));
                                    }

                                    y   += dY;
                                    flag = true;
                                }
                            }
                        }
                        else
                        {
                            if (i >= (Math.Abs(differenceX)))
                            {
                                break;
                            }
                        }
                    }
                    return(points);
                }
Example #6
0
        public ControllUI()
        {
            InitializeComponent();

            rudder = new PointLine(boat_graphics.Width / 2, boat_graphics.Height - (boat_graphics.Height / 4), 100);
        }