コード例 #1
0
 private void HandleSouthConnections(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode sw, NeighbourTrackerNode se, List <Connection> southConnections)
 {
     if (southConnections.Count == 1)
     {
         if (southConnections[0].node.side == sw.side)
         {
             MakeConnection(sw, southConnections[0].node, ConnectionDirection.south);
             MakeConnection(se, southConnections[0].node, ConnectionDirection.south);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectSouthSideEdges(nodeToReplace, sw, se, southConnections);
             }
         }
     }
     if (southConnections.Count == 2)
     {
         if (southConnections[0].node.side == sw.side)
         {
             MakeConnection(sw, southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node, ConnectionDirection.south);
             MakeConnection(se, southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node, ConnectionDirection.south);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectMultipleSouthEdges(nodeToReplace, sw, se, southConnections);
             }
         }
     }
 }
コード例 #2
0
 private void ConnectSouthSideEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode sw, NeighbourTrackerNode se, List <Connection> southConnections)
 {
     //left to bottom
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.left)
     {
         MakeConnection(sw, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.east);
         MakeConnection(se, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.east);
     }
     //right to bottom
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.right)
     {
         MakeConnection(sw, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.west);
         MakeConnection(se, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.west);
     }
     //forward to bottom
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front)
     {
         MakeConnection(sw, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.south);
         MakeConnection(se, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.south);
     }
     //backward to bottom
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
     {
         MakeConnection(sw, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.north);
         MakeConnection(se, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.north);
     }
     //top to front
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.bottom)
     {
         MakeConnection(sw, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.north);
         MakeConnection(se, southConnections[0].node, ConnectionDirection.south, ConnectionDirection.north);
     }
 }
コード例 #3
0
        private void ConnectEastSideEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode ne, NeighbourTrackerNode se, List <Connection> eastConnections)
        {
            //top to right
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.top)
            {
                MakeConnection(se, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.north);
                MakeConnection(ne, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.north);
            }

            //bottom to left
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.bottom)
            {
                MakeConnection(se, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.south);
                MakeConnection(ne, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.south);
            }

            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.left ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.right ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
            {
                MakeConnection(se, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.west);
                MakeConnection(ne, eastConnections[0].node, ConnectionDirection.east, ConnectionDirection.west);
            }
        }
コード例 #4
0
        public void ReplaceNodeWithChildren(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode nw, NeighbourTrackerNode sw, NeighbourTrackerNode se, NeighbourTrackerNode ne)
        {
            //children are connected to each other on two edges, and inherit the parent connections on the others
            MakeConnection(nw, sw, ConnectionDirection.south);
            MakeConnection(nw, ne, ConnectionDirection.east);
            MakeConnection(sw, se, ConnectionDirection.east);
            MakeConnection(se, ne, ConnectionDirection.north);

            List <Connection> parentConnections = GetConnections(nodeToReplace);


            var northConnections = connections[nodeToReplace].FindAll(x => x.direction == ConnectionDirection.north);
            var southConnections = connections[nodeToReplace].FindAll(x => x.direction == ConnectionDirection.south);
            var westConnections  = connections[nodeToReplace].FindAll(x => x.direction == ConnectionDirection.west);
            var eastConnections  = connections[nodeToReplace].FindAll(x => x.direction == ConnectionDirection.east);


            HandleNorthConnections(nodeToReplace, nw, ne, northConnections);
            HandleSouthConnections(nodeToReplace, sw, se, southConnections);
            HandleWestConnections(nodeToReplace, nw, sw, westConnections);
            HandleEastConnections(nodeToReplace, ne, se, eastConnections);


            RemoveAllConnections(nodeToReplace);
        }
コード例 #5
0
 private void ConnectNorthSideEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode nw, NeighbourTrackerNode ne, List <Connection> northConnections)
 {
     //left to top
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.left)
     {
         MakeConnection(nw, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.west);
         MakeConnection(ne, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.west);
     }
     //right to top
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.right)
     {
         MakeConnection(nw, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.east);
         MakeConnection(ne, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.east);
     }
     //forward to top
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front)
     {
         MakeConnection(nw, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.south);
         MakeConnection(ne, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.south);
     }
     //backward to top
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
     {
         MakeConnection(nw, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.north);
         MakeConnection(ne, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.north);
     }
     //bottom to back
     if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.bottom)
     {
         MakeConnection(nw, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.south);
         MakeConnection(ne, northConnections[0].node, ConnectionDirection.north, ConnectionDirection.south);
     }
 }
コード例 #6
0
        public void MakeConnection(NeighbourTrackerNode a, NeighbourTrackerNode b, ConnectionDirection dir)
        {
            if (a == null || b == null)
            {
                return;
            }

            if (!connections.ContainsKey(a))
            {
                connections.Add(a, new List <Connection>());
            }

            connections[a].Add(new Connection(dir, b));

            if (!connections.ContainsKey(b))
            {
                connections.Add(b, new List <Connection>());
            }

            connections[b].Add(new Connection(GetOpposite(dir), a));

            if (!nodeDictionary.ContainsKey(a.keyPoint))
            {
                nodeDictionary.Add(a.keyPoint, a);
            }
            if (!nodeDictionary.ContainsKey(b.keyPoint))
            {
                nodeDictionary.Add(b.keyPoint, b);
            }
        }
コード例 #7
0
        private void ConnectMultipleSouthEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode sw, NeighbourTrackerNode se, List <Connection> southConnections)
        {
            ////left side connects to bottom's east edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.left)
            {
                MakeConnection(sw,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.south, ConnectionDirection.east);

                MakeConnection(se,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.south, ConnectionDirection.east);
            }


            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.right)
            {
                MakeConnection(sw,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.south, ConnectionDirection.west);

                MakeConnection(se,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.south, ConnectionDirection.west);
            }

            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front)
            {
                MakeConnection(sw,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.south, ConnectionDirection.south);

                MakeConnection(se,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.south, ConnectionDirection.south);
            }

            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
            {
                MakeConnection(sw,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.south, ConnectionDirection.north);

                MakeConnection(se,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.south, ConnectionDirection.north);
            }

            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.top)
            {
                MakeConnection(sw,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.south, ConnectionDirection.north);

                MakeConnection(se,
                               southConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.south, ConnectionDirection.north);
            }
        }
コード例 #8
0
 public List <Connection> GetConnections(NeighbourTrackerNode node)
 {
     if (connections.ContainsKey(node))
     {
         return(connections[node]);
     }
     return(new List <Connection>());
 }
コード例 #9
0
        private void ConnectMultipleNorthEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode nw, NeighbourTrackerNode ne, List <Connection> northConnections)
        {
            //left side connects to top's west edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.left)
            {
                MakeConnection(nw,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.north, ConnectionDirection.west);
                MakeConnection(ne,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.north, ConnectionDirection.west);
            }
            //right side connects to top's east edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.right)
            {
                MakeConnection(nw,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.north, ConnectionDirection.east);
                MakeConnection(ne,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.north, ConnectionDirection.east);
            }
            //front side connects to top's south edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front)
            {
                MakeConnection(nw,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.north, ConnectionDirection.south);
                MakeConnection(ne,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.north, ConnectionDirection.south);
            }

            //back side connects to top's north edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
            {
                MakeConnection(nw,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.north, ConnectionDirection.north);
                MakeConnection(ne,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.north, ConnectionDirection.north);
            }

            //bottom side connects to backs south edge.
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.bottom)
            {
                MakeConnection(nw,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.north, ConnectionDirection.south);
                MakeConnection(ne,
                               northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.north, ConnectionDirection.south);
            }
        }
コード例 #10
0
        public void RemoveAllConnections(NeighbourTrackerNode nodeToReplace)
        {
            List <Connection> nodeConnections = GetConnections(nodeToReplace);

            foreach (Connection conn in nodeConnections)
            {
                connections[conn.node].RemoveAll(x => x.node == nodeToReplace);
            }
            connections.Remove(nodeToReplace);
            nodeDictionary.Remove(nodeToReplace.keyPoint);
        }
コード例 #11
0
        public List <Connection> GetConnectionsTo(NeighbourTrackerNode nodeOfInterest)
        {
            var nodeConnections = GetConnections(nodeOfInterest);
            var connectionsTo   = new List <Connection>();

            foreach (Connection conn in nodeConnections)
            {
                connectionsTo.AddRange(connections[conn.node].FindAll(x => x.node == nodeOfInterest));
            }

            return(connectionsTo);
        }
コード例 #12
0
 private void HandleNorthConnections(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode nw, NeighbourTrackerNode ne, List <Connection> northConnections)
 {
     if (northConnections.Count == 1)
     {
         if (northConnections[0].node.side == nw.side)
         {
             MakeConnection(nw, northConnections[0].node, ConnectionDirection.north);
             MakeConnection(ne, northConnections[0].node, ConnectionDirection.north);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectNorthSideEdges(nodeToReplace, nw, ne, northConnections);
             }
         }
     }
     if (northConnections.Count == 2)
     {
         //connections on same side of cube
         if (northConnections[0].node.side == nw.side)
         {
             MakeConnection(nw,
                            northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                            ConnectionDirection.north);
             MakeConnection(ne,
                            northConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                            ConnectionDirection.north);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectMultipleNorthEdges(nodeToReplace, nw, ne, northConnections);
             }
         }
     }
 }
コード例 #13
0
 private void HandleEastConnections(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode ne, NeighbourTrackerNode se, List <Connection> eastConnections)
 {
     if (eastConnections.Count == 1)
     {
         if (eastConnections[0].node.side == ne.side)
         {
             MakeConnection(se, eastConnections[0].node, ConnectionDirection.east);
             MakeConnection(ne, eastConnections[0].node, ConnectionDirection.east);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectEastSideEdges(nodeToReplace, ne, se, eastConnections);
             }
         }
     }
     if (eastConnections.Count == 2)
     {
         if (eastConnections[0].node.side == ne.side)
         {
             MakeConnection(se,
                            eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                            ConnectionDirection.east);
             MakeConnection(ne,
                            eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                            ConnectionDirection.east);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectMultipleEastSideEdges(nodeToReplace, ne, se, eastConnections);
             }
         }
     }
 }
コード例 #14
0
 private void HandleWestConnections(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode nw, NeighbourTrackerNode sw, List <Connection> westConnections)
 {
     if (westConnections.Count == 1)
     {
         if (westConnections[0].node.side == nw.side)
         {
             MakeConnection(sw, westConnections[0].node, ConnectionDirection.west);
             MakeConnection(nw, westConnections[0].node, ConnectionDirection.west);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectWestSideEdges(nodeToReplace, nw, sw, westConnections);
             }
         }
     }
     if (westConnections.Count == 2)
     {
         if (westConnections[0].node.side == nw.side)
         {
             MakeConnection(sw,
                            westConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                            ConnectionDirection.west);
             MakeConnection(nw,
                            westConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                            ConnectionDirection.west);
         }
         else
         {
             if (SystemWarGlobalSettings.EnableQuadTreeInterconnections)
             {
                 ConnectMultipleWestSideEdges(nodeToReplace, nw, sw, westConnections);
             }
         }
     }
 }
コード例 #15
0
        private void ConnectMultipleEastSideEdges(NeighbourTrackerNode nodeToReplace, NeighbourTrackerNode ne, NeighbourTrackerNode se, List <Connection> eastConnections)
        {
            //top connects on east to right's north
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.top)
            {
                MakeConnection(se,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.east, ConnectionDirection.north);
                MakeConnection(ne,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.ne).node,
                               ConnectionDirection.east, ConnectionDirection.north);
            }

            //bottom to left
            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.bottom)
            {
                MakeConnection(se,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.se).node,
                               ConnectionDirection.east, ConnectionDirection.south);
                MakeConnection(ne,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.east, ConnectionDirection.south);
            }

            if (nodeToReplace.side == NeighbourTrackerNode.CubeSide.front ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.left ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.right ||
                nodeToReplace.side == NeighbourTrackerNode.CubeSide.back)
            {
                MakeConnection(se,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.sw).node,
                               ConnectionDirection.east, ConnectionDirection.west);
                MakeConnection(ne,
                               eastConnections.Find(x => x.node.quadrant == NeighbourTrackerNode.Quadrant.nw).node,
                               ConnectionDirection.east, ConnectionDirection.west);
            }
        }
コード例 #16
0
ファイル: Planet.cs プロジェクト: NickMcCrea/SystemWars
        private void RenderConnections(PlanetNode node)
        {
            List <NeighbourTracker.Connection> connections = neighbourTracker.GetConnections(node);
            Color nodeQuadrantColor = Color.Red;

            if (neighbourTracker.nodeDictionary.ContainsKey(node.GetKeyPoint()))
            {
                NeighbourTrackerNode trackerNode = neighbourTracker.nodeDictionary[node.GetKeyPoint()];

                if (trackerNode.quadrant == NeighbourTrackerNode.Quadrant.ne)
                {
                    nodeQuadrantColor = Color.White;
                }
                if (trackerNode.quadrant == NeighbourTrackerNode.Quadrant.nw)
                {
                    nodeQuadrantColor = Color.Green;
                }
                if (trackerNode.quadrant == NeighbourTrackerNode.Quadrant.se)
                {
                    nodeQuadrantColor = Color.Pink;
                }
                if (trackerNode.quadrant == NeighbourTrackerNode.Quadrant.sw)
                {
                    nodeQuadrantColor = Color.Yellow;
                }

                DebugShapeRenderer.AddBoundingSphere(new BoundingSphere(node.GetSurfaceMidPoint(), 100f / trackerNode.depth), nodeQuadrantColor);
            }


            foreach (NeighbourTracker.Connection conn in connections)
            {
                DebugShapeRenderer.AddLine(node.GetSurfaceMidPoint(),
                                           Vector3.Transform(Vector3.Normalize(conn.node.keyPoint) * radius, Transform.AbsoluteTransform), Color.Blue);
            }
        }
コード例 #17
0
ファイル: Planet.cs プロジェクト: NickMcCrea/SystemWars
        private void Initialise()
        {
            activePatches = new Dictionary <Vector3, PlanetNode>();
            rootNodes     = new List <PlanetNode>();
            float vectorSpacing = 1f;
            float cubeVerts     = 21;
            float sphereSize    = radius;



            //top
            PlanetNode top = new PlanetNode(testEffect, module, this, 1, new Vector3(-cubeVerts / 2, cubeVerts / 2 - 1, -cubeVerts / 2), new Vector3(cubeVerts / 2, cubeVerts / 2 - 1, cubeVerts / 2), vectorSpacing, Vector3.Up, sphereSize);

            top.BuildGeometry();
            AddPatch(top);
            rootNodes.Add(top);
            topNode      = new NeighbourTrackerNode(1, top.min, top.max, vectorSpacing, Vector3.Up);
            topNode.side = NeighbourTrackerNode.CubeSide.top;

            ////bottom
            PlanetNode bottom = new PlanetNode(testEffect, module, this, 1, new Vector3(-cubeVerts / 2, -cubeVerts / 2, -cubeVerts / 2), new Vector3(cubeVerts / 2, -cubeVerts / 2, cubeVerts / 2), vectorSpacing, Vector3.Down, sphereSize);

            bottom.BuildGeometry();
            AddPatch(bottom);
            rootNodes.Add(bottom);
            bottomNode      = new NeighbourTrackerNode(1, bottom.min, bottom.max, vectorSpacing, Vector3.Down);
            bottomNode.side = NeighbourTrackerNode.CubeSide.bottom;

            ////forward
            PlanetNode forward = new PlanetNode(testEffect, module, this, 1, new Vector3(-cubeVerts / 2, -cubeVerts / 2, -cubeVerts / 2), new Vector3(cubeVerts / 2, cubeVerts / 2, cubeVerts / 2), vectorSpacing, Vector3.Forward, sphereSize);

            forward.BuildGeometry();
            AddPatch(forward);
            rootNodes.Add(forward);
            forwardNode      = new NeighbourTrackerNode(1, forward.min, forward.max, vectorSpacing, Vector3.Forward);
            forwardNode.side = NeighbourTrackerNode.CubeSide.front;

            ////backward
            PlanetNode backward = new PlanetNode(testEffect, module, this, 1, new Vector3(-cubeVerts / 2, -cubeVerts / 2, cubeVerts / 2 - 1), new Vector3(cubeVerts / 2, cubeVerts / 2, cubeVerts / 2 - 1), vectorSpacing, Vector3.Backward, sphereSize);

            backward.BuildGeometry();
            AddPatch(backward);
            rootNodes.Add(backward);
            backwardNode      = new NeighbourTrackerNode(1, backward.min, backward.max, vectorSpacing, Vector3.Backward);
            backwardNode.side = NeighbourTrackerNode.CubeSide.back;

            //right
            PlanetNode right = new PlanetNode(testEffect, module, this, 1, new Vector3(-cubeVerts / 2, -cubeVerts / 2, -cubeVerts / 2), new Vector3(-cubeVerts / 2, cubeVerts / 2, cubeVerts / 2), vectorSpacing, Vector3.Right, sphereSize);

            right.BuildGeometry();
            AddPatch(right);
            rootNodes.Add(right);
            rightNode      = new NeighbourTrackerNode(1, right.min, right.max, vectorSpacing, Vector3.Right);
            rightNode.side = NeighbourTrackerNode.CubeSide.right;


            //left
            PlanetNode left = new PlanetNode(testEffect, module, this, 1, new Vector3(cubeVerts / 2 - 1, -cubeVerts / 2, -cubeVerts / 2), new Vector3(cubeVerts / 2 - 1, cubeVerts / 2, cubeVerts / 2), vectorSpacing, Vector3.Left, sphereSize);

            left.BuildGeometry();
            AddPatch(left);
            rootNodes.Add(left);
            leftNode      = new NeighbourTrackerNode(1, left.min, left.max, vectorSpacing, Vector3.Left);
            leftNode.side = NeighbourTrackerNode.CubeSide.left;



            ReinitialiseTracker();
        }
コード例 #18
0
 public Connection(ConnectionDirection dir, NeighbourTrackerNode n)
 {
     node      = n;
     direction = dir;
 }
コード例 #19
0
ファイル: Planet.cs プロジェクト: NickMcCrea/SystemWars
        private void CalculateConnectivity()
        {
            ReinitialiseTracker();

            // have to go through the tree in a breadth first fashion, building connectivity.
            Queue <PatchMinMax> nodesToCheck = new Queue <PatchMinMax>();

            foreach (PlanetNode rootNode in rootNodes)
            {
                nodesToCheck.Enqueue(new PatchMinMax(rootNode.min, rootNode.max, rootNode.depth, rootNode.normal,
                                                     rootNode.step, neighbourTracker.nodeDictionary[(rootNode.min + rootNode.max) / 2].side));
            }


            while (nodesToCheck.Count > 0)
            {
                PatchMinMax next = nodesToCheck.Dequeue();
                if (ShouldSplit(next.Min, next.Max, radius, next.depth))
                {
                    Vector3 se, sw, mid1, mid2, nw, ne, midBottom, midRight, midLeft, midTop;
                    PlanetNode.CalculatePatchBoundaries(next.normal, next.step, next.Min, next.Max, out se, out sw, out mid1, out mid2, out nw, out ne, out midBottom, out midRight, out midLeft, out midTop);

                    //remove this node in the neighbour tracker, generate and connect children
                    NeighbourTrackerNode southEast = new NeighbourTrackerNode(next.depth + 1, se, mid1, next.step / 2, next.normal);
                    southEast.quadrant = NeighbourTrackerNode.Quadrant.se;
                    southEast.side     = next.side;
                    PatchMinMax sePatchMinMax = new PatchMinMax(se, mid1, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(sePatchMinMax);

                    NeighbourTrackerNode northWest = new NeighbourTrackerNode(next.depth + 1, mid2, nw, next.step / 2, next.normal);
                    northWest.quadrant = NeighbourTrackerNode.Quadrant.nw;
                    northWest.side     = next.side;
                    PatchMinMax nwPatchMinMax = new PatchMinMax(mid2, nw, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(nwPatchMinMax);

                    NeighbourTrackerNode southWest = new NeighbourTrackerNode(next.depth + 1, midBottom, midLeft,
                                                                              next.step / 2, next.normal);
                    southWest.quadrant = NeighbourTrackerNode.Quadrant.sw;
                    southWest.side     = next.side;
                    PatchMinMax swPatchMinMax = new PatchMinMax(midBottom, midLeft, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(swPatchMinMax);

                    NeighbourTrackerNode northEast = new NeighbourTrackerNode(next.depth + 1, midRight, midTop, next.step / 2, next.normal);
                    northEast.quadrant = NeighbourTrackerNode.Quadrant.ne;
                    northEast.side     = next.side;
                    PatchMinMax nePatchMinMax = new PatchMinMax(midRight, midTop, next.depth + 1, next.normal, next.step / 2, next.side);
                    nodesToCheck.Enqueue(nePatchMinMax);

                    //if (next.side == NeighbourTrackerNode.CubeSide.right || next.side == NeighbourTrackerNode.CubeSide.back)
                    //{
                    //    southEast.quadrant = NeighbourTrackerNode.Quadrant.sw;
                    //    northEast.quadrant = NeighbourTrackerNode.Quadrant.nw;
                    //    southWest.quadrant = NeighbourTrackerNode.Quadrant.se;
                    //    northWest.quadrant = NeighbourTrackerNode.Quadrant.ne;
                    //}

                    neighbourTracker.ReplaceNodeWithChildren(neighbourTracker.nodeDictionary[(next.Min + next.Max) / 2],
                                                             northWest, southWest, southEast, northEast);
                }
            }


            neighbourTracker.CopyConnectionDataToThreadSafeBuffer();
        }