示例#1
0
        public IEnumerable <Ets2Point> GeneratePolygonForRoute(Ets2PrefabRoute route, Ets2Node node, int nodeOr)
        {
            List <Ets2Point> p = new List <Ets2Point>();

            if (route == null || route.Route == null)
            {
                return(p);
            }

            /*
             * yaw -= this.Nodes[nodeOr].Yaw;
             * yaw += Math.PI/2;
             */
            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI / 2;

            foreach (var curve in route.Route)
            {
                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var sry = curve.StartZ - this.Nodes[nodeOr].Z;
                var ery = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float)Math.Sqrt(srx * srx + sry * sry);
                var er = (float)Math.Sqrt(erx * erx + ery * ery);

                var ans = yaw - Math.Atan2(sry, srx);
                var ane = yaw - Math.Atan2(ery, erx);

                var sx = xOr - sr * (float)Math.Sin(ans);
                var ex = xOr - er * (float)Math.Sin(ane);
                var sy = yOr - sr * (float)Math.Cos(ans);
                var ey = yOr - er * (float)Math.Cos(ane);
                // tmp
                var ps = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, node.Y, sy, (float)ans);
                ps[1] = new Ets2Point(ex, node.Y, ey, (float)ane);

                p.AddRange(ps);
            }

            return(p);
        }
示例#2
0
        public IEnumerable<Ets2Point> GeneratePolygonForRoute(Ets2PrefabRoute route, Ets2Node node,  int nodeOr)
        {
            List<Ets2Point> p = new List<Ets2Point>();

            if (route == null || route.Route == null)
            return p;

            /*
            yaw -= this.Nodes[nodeOr].Yaw;
            yaw += Math.PI/2;
            */
            var xOr = node.X;
            var yOr = node.Z;
            var yaw = node.Yaw - this.Nodes[nodeOr].Yaw + Math.PI / 2;

            foreach (var curve in route.Route)
            {
                var srx = curve.StartX - this.Nodes[nodeOr].X;
                var erx = curve.EndX - this.Nodes[nodeOr].X;
                var sry = curve.StartZ - this.Nodes[nodeOr].Z;
                var ery = curve.EndZ - this.Nodes[nodeOr].Z;

                var sr = (float) Math.Sqrt(srx*srx + sry*sry);
                var er = (float) Math.Sqrt(erx*erx + ery*ery);

                var ans = yaw - Math.Atan2(sry, srx);
                var ane = yaw - Math.Atan2(ery, erx);

                var sx = xOr - sr*(float) Math.Sin(ans);
                var ex = xOr - er*(float) Math.Sin(ane);
                var sy = yOr - sr*(float) Math.Cos(ans);
                var ey = yOr - er*(float) Math.Cos(ane);
                // tmp
                var ps = new Ets2Point[2];
                ps[0] = new Ets2Point(sx, node.Y, sy,(float) ans);
                ps[1] = new Ets2Point(ex, node.Y, ey, (float)ane);

                p.AddRange(ps);
            }

            return p;
        }