public void Load() { m_RootNode = new QuadNode(QuadNodeType.FullNode, m_TopNodeSize, 1, null, this, 0); if (CameraManager.Instance.ActiveCamera != null) { Camera3D camera3D = (CameraManager.Instance.ActiveCamera as Camera3D); if (camera3D != null) ViewFrustum = new BoundingFrustum(camera3D.ViewProjection); } }
/// <summary> /// QuadNode constructor /// </summary> /// <param name="nodeType">Type of node.</param> /// <param name="nodeSize">Width/Height of node (# of vertices across - 1).</param> /// <param name="nodeDepth">Depth of current node</param> /// <param name="parent">Parent QuadNode</param> /// <param name="parentTree">Top level Tree.</param> /// <param name="positionIndex">Index of top left Vertice in the parent tree Vertices array</param> public QuadNode(QuadNodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex) { NodeType = nodeType; m_NodeSize = nodeSize; m_NodeDepth = nodeDepth; m_PositionIndex = positionIndex; m_ParentNode = parent; m_ParentTree = parentTree; // Add the 9 vertices AddVertices(); m_BoundingBox = new BoundingBox(m_ParentTree[VertexTopLeft.Index].Position, m_ParentTree[VertexBottomLeft.Index].Position); m_BoundingBox.Min.Y = -950f; m_BoundingBox.Max.Y = 950f; if (m_NodeSize > 4) AddChildren(); //Make call to UpdateNeighbors from the parent node. //This will update all neighbors recursively for the //children as well. This ensures all nodes are created //prior to updating neighbors. if (m_NodeDepth == 1) { AddNeighbours(); // Activate nodes inside node m_VertexTopLeft.Activated = true; m_VertexTopRight.Activated = true; m_VertexCenter.Activated = true; m_VertexBottomLeft.Activated = true; m_VertexBottomRight.Activated = true; } }
private void AddNeighbours() { switch (NodeType) { case QuadNodeType.TopLeft: //Top Left Corner //Top neighbor if (m_ParentNode.NeighbourTop != null) m_NeighbourTop = m_ParentNode.NeighbourTop.ChildBottomLeft; //Right neighbor m_NeighbourRight = m_ParentNode.ChildTopRight; //Bottom neighbor m_NeighbourBottom = m_ParentNode.ChildBottomLeft; //Left neighbor if (m_ParentNode.NeighbourLeft != null) m_NeighbourLeft = m_ParentNode.NeighbourLeft.ChildTopRight; break; case QuadNodeType.TopRight: //Top Right Corner //Top neighbor if (m_ParentNode.NeighbourTop != null) m_NeighbourTop = m_ParentNode.NeighbourTop.ChildBottomRight; //Right neighbor if (m_ParentNode.NeighbourRight != null) m_NeighbourRight = m_ParentNode.NeighbourRight.ChildTopLeft; //Bottom neighbor m_NeighbourBottom = m_ParentNode.ChildBottomRight; //Left neighbor m_NeighbourLeft = m_ParentNode.ChildTopLeft; break; case QuadNodeType.BottomLeft: //Bottom Left Corner //Top neighbor m_NeighbourTop = m_ParentNode.ChildTopLeft; //Right neighbor m_NeighbourRight = m_ParentNode.ChildBottomRight; //Bottom neighbor if (m_ParentNode.NeighbourBottom != null) m_NeighbourBottom = m_ParentNode.NeighbourBottom.ChildTopLeft; //Left neighbor if (m_ParentNode.NeighbourLeft != null) m_NeighbourLeft = m_ParentNode.NeighbourLeft.ChildBottomRight; break; case QuadNodeType.BottomRight: //Bottom Right Corner //Top neighbor m_NeighbourTop = m_ParentNode.ChildTopRight; //Right neighbor if (m_ParentNode.NeighbourRight != null) m_NeighbourRight = m_ParentNode.NeighbourRight.ChildBottomLeft; //Bottom neighbor if (m_ParentNode.NeighbourBottom != null) m_NeighbourBottom = m_ParentNode.NeighbourBottom.ChildTopRight; //Left neighbor m_NeighbourLeft = m_ParentNode.ChildBottomLeft; break; } if (m_HasChildren) { m_ChildTopLeft.AddNeighbours(); m_ChildTopRight.AddNeighbours(); m_ChildBottomLeft.AddNeighbours(); m_ChildBottomRight.AddNeighbours(); } }
private void AddChildren() { //Add top left (northwest) child m_ChildTopLeft = new QuadNode(QuadNodeType.TopLeft, (int)(m_NodeSize * 0.5f), m_NodeDepth + 1, this, m_ParentTree, VertexTopLeft.Index); //Add top right (northeast) child m_ChildTopRight = new QuadNode(QuadNodeType.TopRight, (int)(m_NodeSize * 0.5f), m_NodeDepth + 1, this, m_ParentTree, VertexTop.Index); //Add bottom left (southwest) child m_ChildBottomLeft = new QuadNode(QuadNodeType.BottomLeft, (int)(m_NodeSize * 0.5f), m_NodeDepth + 1, this, m_ParentTree, VertexLeft.Index); //Add bottom right (southeast) child m_ChildBottomRight = new QuadNode(QuadNodeType.BottomRight, (int)(m_NodeSize * 0.5f), m_NodeDepth + 1, this, m_ParentTree, VertexCenter.Index); // State that this node has children m_HasChildren = true; }