Beispiel #1
0
        public bool RemoveNode(TrainTrackNode node)
        {
            bool r = false;

            r = Nodes.Remove(node);

            NodeCount = Nodes.Count;

            if (r)
            {
                var l0 = node.Links[0];
                var l1 = node.Links[1];

                if (l0 != null)
                {
                    l0.Links[1] = l1;
                }
                if (l1 != null)
                {
                    l1.Links[0] = l0;
                }

                for (int i = 0; i < Nodes.Count; i++)
                {
                    Nodes[i].Index = i;
                }

                BuildVertices();
            }

            return(r);
        }
Beispiel #2
0
        public void Load(string trackstr)
        {
            //load nodes from a text string...
            NodesString = trackstr;

            if (!string.IsNullOrEmpty(trackstr))
            {
                string[] trackstrs = trackstr.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                if (trackstrs.Length > 1)
                {
                    int nodecount;
                    int.TryParse(trackstrs[0], out nodecount);
                    NodeCount = nodecount;
                    List <TrainTrackNode> nodes = new List <TrainTrackNode>();
                    for (int i = 1; i < trackstrs.Length; i++)
                    {
                        var nodestr  = trackstrs[i].Trim();
                        var nodevals = nodestr.Split(' ');
                        if (nodevals.Length == 4)
                        {
                            TrainTrackNode ttnode = new TrainTrackNode();
                            var            x      = FloatUtil.Parse(nodevals[0]);
                            var            y      = FloatUtil.Parse(nodevals[1]);
                            var            z      = FloatUtil.Parse(nodevals[2]);
                            int            nodetype;
                            int.TryParse(nodevals[3], out nodetype);
                            ttnode.Position = new Vector3(x, y, z);
                            ttnode.NodeType = nodetype;
                            ttnode.Track    = this;
                            ttnode.Index    = nodes.Count;
                            ttnode.Links[0] = (nodes.Count > 0) ? nodes[nodes.Count - 1] : null;
                            if (ttnode.Links[0] != null)
                            {
                                ttnode.Links[0].Links[1] = ttnode;
                            }
                            nodes.Add(ttnode);
                        }
                        else
                        {
                        }
                    }
                    Nodes = nodes;
                }
                else
                {
                }
            }
            else
            {
            }

            if (Nodes == null)
            {
                Nodes = new List <TrainTrackNode>();
            }
        }
Beispiel #3
0
        public TrainTrackNode AddNode(TrainTrackNode afternode = null)
        {
            int            cnt = Nodes?.Count ?? 0;
            TrainTrackNode tn  = new TrainTrackNode();

            tn.Track = this;
            tn.Index = (afternode != null) ? afternode.Index + 1 : cnt;

            if (Nodes == null)
            {
                Nodes = new List <TrainTrackNode>();
            }

            if (afternode != null)
            {
                TrainTrackNode aln = afternode.Links[1];
                if (aln != null)
                {
                    aln.Links[0] = tn;
                }
                afternode.Links[1] = tn;
                tn.Links[0]        = afternode;
                tn.Links[1]        = aln;

                int idx = tn.Index;
                Nodes.Insert(idx, tn);

                for (int i = 0; i < Nodes.Count; i++)
                {
                    Nodes[i].Index = i;
                }
            }
            else
            {
                if (cnt > 0)
                {
                    TrainTrackNode ln = Nodes[cnt - 1];
                    tn.Links[0] = ln;
                    ln.Links[1] = tn;
                }

                Nodes.Add(tn);
            }


            NodeCount = Nodes.Count;

            return(tn);
        }
Beispiel #4
0
        public void UpdateBvhForNode(TrainTrackNode node)
        {
            //this needs to be called when a node's position changes...
            //need to recalc the BVH for mouse intersection optimisation purposes.

            //if (BVH == null) return;
            //BVH.UpdateForNode(node);

            BuildBVH();

            //also updates the NodePositions for the visible vertex
            if (Nodes != null)
            {
                for (int i = 0; i < Nodes.Count; i++)
                {
                    if (Nodes[i] == node)
                    {
                        NodePositions[i] = new Vector4(node.Position, 1.0f);
                        break;
                    }
                }
            }
        }