public override void WriteLine(string Line)
 {
     foreach (string SubLine in Line.Split('\n'))
     {
         FlushLine(SubLine.TrimEnd());
     }
 }
Beispiel #2
0
 public SubGrid(ref SubLine b, ref SubLine r, ref SubLine l, ref SubLine t, int startIndex, int w, int h)
 {
     this.bottom     = b; this.right = r; this.left = l; this.top = t;
     this.startIndex = startIndex;
     this.w          = w;
     this.h          = h;
     dtw             = 1.0f / (this.w + 1);
     dth             = 1.0f / (this.h + 1);
 }
Beispiel #3
0
        /// <summary>
        /// Every bezier curve is liked to its previous and current curve:
        /// _  _  _  _
        ///  c1 c2 c3
        /// </summary>
        /// <param name="prev"></param>
        internal override void link(ref SubLine prev)
        {
            BezierSubline bPrev = (BezierSubline)prev;

            base.link(ref prev);
            Bezier prevB = new Bezier(new int[] { prev.a, a, b }, endIndex - startIndex);

            this.prevB  = prevB;
            bPrev.nextB = prevB;
        }
        public void SetPropByCurrentTrain()
        {
            Train t = MonitorDataModel.Instance().CurrentTrain;

            if (t != null)
            {
                DateTime now = DateTime.Now;
                txtCurrentDate.Text = now.ToString("yyyy-MM-dd");

                SubLine line = MonitorDataModel.Instance().SubWayLines[t.LineNo];
                stationGrid.ItemsSource = line.Stations;
                double nextstationID;
                if (t.IsDown)
                {
                    if (line.Stations.Count > (int)t.Location && (int)t.Location >= 0)
                    {
                        Station next = line.Stations[(int)t.Location];
                        this.txtNextStation.Text        = next.Name;
                        this.txtEstimateArrivaTime.Text = now.AddMinutes(next.DownFirstTime).ToString("HH:mm");
                        this.txtPlanArriveTime.Text     = this.txtEstimateArrivaTime.Text;
                    }
                    else
                    {
                        this.txtNextStation.Text        = "终点站";
                        this.txtPlanArriveTime.Text     = now.ToString("HH:mm");
                        this.txtEstimateArrivaTime.Text = now.ToString("HH:mm");
                    }
                }
                else
                {
                    nextstationID = t.Location - 2;
                    if (line.Stations.Count > (int)(t.Location - 2) && (int)(t.Location - 2) >= 0)
                    {
                        Station next = line.Stations[(int)t.Location - 2];
                        this.txtNextStation.Text        = next.Name;
                        this.txtEstimateArrivaTime.Text = now.AddMinutes(next.UpFirstTime).ToString("HH:mm");
                        this.txtPlanArriveTime.Text     = this.txtEstimateArrivaTime.Text;
                    }
                    else
                    {
                        this.txtNextStation.Text        = "终点站";
                        this.txtPlanArriveTime.Text     = now.ToString("HH:mm");
                        this.txtEstimateArrivaTime.Text = now.ToString("HH:mm");
                    }
                }
            }
        }
Beispiel #5
0
        private void addBorderTriangles(int thisStart, int thisIncr, ref SubLine line, ref List <int> triangles)
        {
            for (int i = 0; i < line.endIndex - line.startIndex - 1; i++)
            {
                int gridA = thisStart + thisIncr * i;
                int gridB = thisStart + thisIncr * (i + 1);
                int lineA = line.startIndex + i;
                int lineB = lineA + 1;

                triangles.Add(lineA);
                triangles.Add(lineB);
                triangles.Add(gridB);

                triangles.Add(lineA);
                triangles.Add(gridB);
                triangles.Add(gridA);
            }
        }
        void UpdateStationInfor(object sender, int subway)
        {
            stationinfo.IsOpen          = true;
            stationinfo.PlacementTarget = sender as UIElement;
            SubLine line  = MonitorDataModel.Instance().SubWayLines[subway];
            string  name  = (sender as Canvas).Name;
            int     index = int.Parse(name.Substring(name.IndexOf("_") + 1));
            Station s     = line.Stations[index - 1];

            stationName.Text = s.Name;
            inNumber.Text    = s.InNumber.ToString();
            outNumber.Text   = s.OutNumber.ToString();

            if (subway == 0)
            {
                sublinename.Text         = "1";
                sublineBorder.Background = new SolidColorBrush(Colors.Green);
            }
            else
            {
                sublinename.Text         = "2";
                sublineBorder.Background = new SolidColorBrush(Colors.Red);
            }
        }
Beispiel #7
0
 internal virtual void link(ref SubLine prev)
 {
     this.prev = prev;
     prev.next = this;
     Debug.Assert(prev.b == this.a);
 }
Beispiel #8
0
    public TriangularModelMesh(ParticleModel model, ClothSimulation settings)
    {
        this.model = model;

        GameObject meshGameObject = new GameObject("TriangularModelMesh");

        MeshFilter meshFilter = meshGameObject.AddComponent <MeshFilter>();

        this.mesh = meshFilter.mesh;

        MeshRenderer meshRenderer    = meshGameObject.AddComponent <MeshRenderer>();
        Material     defaultMaterial = new Material(Shader.Find("VR/SpatialMapping/Wireframe"));

        meshRenderer.sharedMaterial = defaultMaterial;

        this.mesh.Clear();

        int subdivisions = 6;
        int modelWH      = this.model.getWidthHeight();

        points = new Vector3[(int)Math.Pow((modelWH + (modelWH - 1)) * subdivisions, 2)];
        Array.Copy(model.positions, points, model.positions.Length);
        int index = model.positions.Length;

        List <int> triangles = new List <int>();

        List <SubLine> SubLines = new List <SubLine>();

        // horizontal
        for (int j = 0; j < modelWH; j++)
        {
            for (int i = 0; i < modelWH - 1; i++)
            {
                int left  = j * modelWH + i;
                int right = left + 1;

                SubLine subLine = bezier > 0 ? new BezierSubline(left, right, index, index + subdivisions) : new SubLine(left, right, index, index + subdivisions);
                index = index + subdivisions;

                if (i > 0)
                {
                    SubLine prev = SubLines[(modelWH - 1) * j + (i - 1)];
                    subLine.link(ref prev);
                }

                SubLines.Add(subLine);
            }
        }
        // vertical
        for (int j = 0; j < modelWH - 1; j++)
        {
            for (int i = 0; i < modelWH; i++)
            {
                int bottom = j * modelWH + i;
                int top    = bottom + modelWH;

                SubLine subLine = bezier > 0 ? new BezierSubline(bottom, top, index, index + subdivisions) : new SubLine(bottom, top, index, index + subdivisions);
                index = index + subdivisions;

                if (j > 0)
                {
                    SubLine prev = SubLines[modelWH * (modelWH - 1) + modelWH * (j - 1) + i];
                    subLine.link(ref prev);
                }

                SubLines.Add(subLine);
            }
        }
        List <SubGrid> SubGrids = new List <SubGrid>();

        for (int j = 0; j < modelWH - 1; j++)
        {
            for (int i = 0; i < modelWH - 1; i++)
            {
                int a = modelWH * j + i;
                int b = a + 1;
                int c = a + modelWH;
                int d = c + 1;

                SubLine bottom = SubLines[(modelWH - 1) * j + i];
                SubLine top    = SubLines[(modelWH - 1) * (j + 1) + i];
                SubLine left   = SubLines[(modelWH - 1) * modelWH + modelWH * j + i];
                SubLine right  = SubLines[(modelWH - 1) * modelWH + modelWH * j + i + 1];

                SubGrid grid = new SubGrid(ref bottom, ref right, ref left, ref top, index, subdivisions, subdivisions);
                index += subdivisions * subdivisions;

                if (i > 0)
                {
                    SubGrid prev = SubGrids[(modelWH - 1) * j + i - 1];
                    grid.linkHorizontal(ref prev);
                }
                if (j > 0)
                {
                    SubGrid prev = SubGrids[(modelWH - 1) * (j - 1) + i];
                    grid.linkVertical(ref prev);
                }

                SubGrids.Add(grid);

                // Add triangles for the grid
                triangles.AddRange(grid.GenTriangles());
            }
        }

        List <int> included = new List <int>(new HashSet <int>(triangles));

        // Calculate the uvs
        Vector2[] uvs = new Vector2[points.Length]; // uv maps texture to points
        float     du  = 1.0f / modelWH;
        float     dv  = 1.0f / modelWH;

        for (int u = 0; u < modelWH; u++)
        {
            for (int v = 0; v < modelWH; v++)
            {
                uvs[u * modelWH + v] = new Vector2(u * du, v * dv);
            }
        }

        if (showGridPoints)
        {
            gridPointsObjectManager = new MonoManager <SceneObject>();
            GameObject unitPrefab = new GameObject();
            unitPrefab.AddComponent <SceneObject>();
            unitPrefab.AddComponent <MeshFilter>();
            unitPrefab.AddComponent <MeshRenderer>();
            gridPointsObjectManager.OverrideGameObject(unitPrefab);

            Mesh     mesh     = Assets.Scripts.Tools.Geometry.PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Sphere);
            Material material = new Material(Shader.Find("Transparent/Diffuse"));
            material.color = Color.yellow;


            for (int i = model.positions.Length; i < points.Length; i++)
            {
                var newObj = gridPointsObjectManager.New();
                newObj.Init(mesh, material);
                newObj.transform.position = points[i];
            }
        }

        SubLines.ForEach(sl => {
            sl.setUV(ref uvs);
        });
        this.subLines = SubLines.ToArray();
        SubGrids.ForEach(sl => {
            sl.setUV(ref uvs);
        });
        this.subGrids = SubGrids.ToArray();

        SubLines.ForEach(sl => {
            sl.setPoints(ref points);
        });
        SubGrids.ForEach(sl => {
            sl.setPoints(ref points);
        });

        // Set unit mesh
        this.mesh.vertices  = points;
        this.mesh.uv        = uvs;
        this.mesh.triangles = addBothSide(triangles.ToArray());
    }