コード例 #1
0
ファイル: Objects.cs プロジェクト: JGEsteves89/TheVis
 public Road(Cross start, Cross end) : base(start.i, end.i, (end.pos - start.pos).LengthFast)
 {
     this.start = start;
     this.end   = end;
     this.start.roads.Add(this);
     this.end.roads.Add(this);
 }
コード例 #2
0
ファイル: Objects.cs プロジェクト: JGEsteves89/TheVis
 public Car(Cross source, Cross target, Vector2 targetPos, List <Cross> route)
 {
     this.source = source;
     this.target = target;
     this.pos    = source.pos;
     this.route.AddRange(route);
     this.route.Add(new Cross(0, targetPos));
 }
コード例 #3
0
ファイル: StringPoints.cs プロジェクト: JGEsteves89/TheVis
        public static Cross FindCrossCloses(ref List <Cross> crosses, Vector2 pos)
        {
            Cross bestCross = crosses.First();
            float bestDist  = 10000;

            foreach (Cross item in crosses)
            {
                float dist = (item.pos - pos).LengthFast;
                if (dist < bestDist)
                {
                    bestDist  = dist;
                    bestCross = item;
                }
            }
            return(bestCross);
        }
コード例 #4
0
ファイル: Objects.cs プロジェクト: JGEsteves89/TheVis
        internal Vector2 nextPos()
        {
            if (arrived)
            {
                return(new Vector2(0, 0));
            }

            Cross nextCross = route[location];

            if ((pos - nextCross.pos).Length < pace)
            {
                location++;
                if (location == route.Count)
                {
                    arrived = true;
                }
                return(nextCross.pos);
            }

            return(pos + pace * (nextCross.pos - pos).Normalized());
        }
コード例 #5
0
        public override void SetUp()
        {
            base.SetUp();
            Canvas((int)width, (int)height);
            BackgroundColor(51);
            Vector2 trans = new Vector2(70, 200);

            string         text         = "Tarina";
            List <Vector2> stringPoints = GetPointsOfString(text, 200f, (int)width, (int)height);
            List <Vector2> medians      = GetMedPoints(text.Length, stringPoints);
            List <Vector2> gridPoints   = CreateRandomGridPoints(cols, rows, width, height);


            foreach (Vector2 gridPoint in gridPoints)
            {
                crosses.Add(new Cross(crosses.Count, gridPoint));
            }
            //foreach (Vector2 median in medians) {
            //    crosses.Add(new Cross(crosses.Count, median + trans));
            //}

            Tesselate(ref crosses, ref roads);

            Graph graph = new Graph();

            foreach (Node item in crosses)
            {
                graph.nodes.Add(item);
            }
            foreach (Road item in roads)
            {
                graph.edges.Add(item);
            }

            foreach (Vector2 stringPoint in stringPoints)
            {
                Vector2 targetPoint = stringPoint + trans;
                Vector2 sourcePoint = new Vector2();

                sourcePoint.X = Rndf(-0.1f, 0.1f) * Width + targetPoint.X;
                sourcePoint.Y = height * 2;

                Cross targetCross = FindCrossCloses(ref crosses, targetPoint);
                Cross sourceCross = FindCrossCloses(ref crosses, sourcePoint);

                List <Cross> route = new List <Cross>();
                foreach (Car car in cars)
                {
                    if (car.source.i == sourceCross.i && car.target.i == targetCross.i)
                    {
                        route = car.route;
                        break;
                    }
                }
                if (route.Count == 0)
                {
                    List <int> routeInd = Dijkstra.runDijkstra(graph, sourceCross.i, targetCross.i);
                    foreach (int i in routeInd)
                    {
                        route.Add(crosses[i]);
                    }
                }

                cars.Add(new Car(sourceCross, targetCross, targetPoint, route));
                Console.WriteLine(stringPoints.Count + "/" + cars.Count());
            }
        }