Exemplo n.º 1
0
        internal void Update(GameTime gameTime, ICamera Camera)
        {
            ViewFrustrum.Matrix = Camera.ViewProjection;
            CameraPosition = Camera.Position;

            //Corners 0-3 = near plane clockwise, Corners 4-7 = far plane clockwise
            ViewFrustrum.GetCorners(VFCorners);

            var clip = ClippingFrustrum.FromFrustrumCorners(VFCorners, CameraPosition);
            ClipShape = clip.ProjectToTargetY(_position.Y);

            _lastCameraPosition = _cameraPosition;
            IndexCount = 0;

            _rootNode.Merge();
            _rootNode.EnforceMinimumDepth();

            _activeNode = _rootNode.DeepestNodeWithPoint(ClipShape.ViewPoint);


            if (_activeNode != null)
            {
                _activeNode.Split();
            }

            _rootNode.SetActiveVertices();

            _buffers.UpdateIndexBuffer(Indices, IndexCount);
            _buffers.SwapBuffer();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add child nodes
        /// </summary>
        private void AddChildren()
        {
            //Add top left (northwest) child
            ChildTopLeft = new QuadNode(NodeType.TopLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTopLeft.Index);

            //Add top right (northeast) child
            ChildTopRight = new QuadNode(NodeType.TopRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTop.Index);

            //Add bottom left (southwest) child
            ChildBottomLeft = new QuadNode(NodeType.BottomLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexLeft.Index);

            //Add bottom right (southeast) child
            ChildBottomRight = new QuadNode(NodeType.BottomRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexCenter.Index);

            HasChildren = true;
        }
Exemplo n.º 3
0
        internal QuadTree(Vector3 position, List<VertexPositionNormalTexture> positions, Texture2D heightMap, Matrix viewMatrix, Matrix projectionMatrix, GraphicsDevice device)
        {
            Device = device;
            _position = position;
            _topNodeSize = heightMap.Width - 1;

            _vertices = new TreeVertexCollection(positions);

            _buffers = new BufferManager(_vertices.Vertices, device);
            _rootNode = new QuadNode(NodeType.FullNode, _topNodeSize, 1, null, this, 0);

            //Initialize the bounding frustrum to be used for culling later.
            ViewFrustrum = new BoundingFrustum(viewMatrix * projectionMatrix);

            //Construct an array large enough to hold all of the indices we'll need
            Indices = new int[((heightMap.Width + 1) * (heightMap.Height + 1)) * 3];

            Cull = false;
        }
Exemplo n.º 4
0
        internal QuadTree(Vector3 position, List <VertexPositionNormalTexture> positions, Texture2D heightMap, Matrix viewMatrix, Matrix projectionMatrix, GraphicsDevice device)
        {
            Device       = device;
            _position    = position;
            _topNodeSize = heightMap.Width - 1;

            _vertices = new TreeVertexCollection(positions);

            _buffers  = new BufferManager(_vertices.Vertices, device);
            _rootNode = new QuadNode(NodeType.FullNode, _topNodeSize, 1, null, this, 0);

            //Initialize the bounding frustrum to be used for culling later.
            ViewFrustrum = new BoundingFrustum(viewMatrix * projectionMatrix);

            //Construct an array large enough to hold all of the indices we'll need
            Indices = new int[((heightMap.Width + 1) * (heightMap.Height + 1)) * 3];

            Cull = false;
        }
Exemplo n.º 5
0
        internal QuadNode(NodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex)
        {
            NodeType       = nodeType;
            _nodeSize      = nodeSize;
            _nodeDepth     = nodeDepth;
            _positionIndex = positionIndex;

            _parent     = parent;
            _parentTree = parentTree;

            //Add the 9 vertices
            AddVertices();

            var tl = new Vector2(_parentTree.Vertices[VertexTopLeft.Index].Position.X, _parentTree.Vertices[VertexTopLeft.Index].Position.Z);
            var br = new Vector2(_parentTree.Vertices[VertexBottomRight.Index].Position.X, _parentTree.Vertices[VertexBottomRight.Index].Position.Z);

            Bounds = Culling.Rectangle.FromPoints(tl, br);

            if (nodeSize >= 4)
            {
                AddChildren();
            }

            //Make call to UpdateNeighbors from the parent node only.
            //This will update neighbors recursively for the children
            //as well.  This ensures all nodes are created prior to
            //updating neighbors.
            if (_nodeDepth == 1)
            {
                AddNeighbors();

                VertexTopLeft.Activated     = true;
                VertexTopRight.Activated    = true;
                VertexCenter.Activated      = true;
                VertexBottomLeft.Activated  = true;
                VertexBottomRight.Activated = true;
            }
        }
Exemplo n.º 6
0
		internal QuadNode(NodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex)
		{
			NodeType = nodeType;
			_nodeSize = nodeSize;
			_nodeDepth = nodeDepth;
			_positionIndex = positionIndex;

			_parent = parent;
			_parentTree = parentTree;

			//Add the 9 vertices
			AddVertices();

			var tl = new Vector2(_parentTree.Vertices[VertexTopLeft.Index].Position.X, _parentTree.Vertices[VertexTopLeft.Index].Position.Z);
			var br = new Vector2(_parentTree.Vertices[VertexBottomRight.Index].Position.X, _parentTree.Vertices[VertexBottomRight.Index].Position.Z);

			Bounds = Culling.Rectangle.FromPoints(tl, br);

			if (nodeSize >= 4)
				AddChildren();

			//Make call to UpdateNeighbors from the parent node only.
			//This will update neighbors recursively for the children 
			//as well.  This ensures all nodes are created prior to 
			//updating neighbors.
			if (_nodeDepth == 1)
			{
				AddNeighbors();

				VertexTopLeft.Activated = true;
				VertexTopRight.Activated = true;
				VertexCenter.Activated = true;
				VertexBottomLeft.Activated = true;
				VertexBottomRight.Activated = true;

			}
		}
Exemplo n.º 7
0
		/// <summary>
		/// Make sure neighbor parents are split to ensure 
		/// consistency with vertex sharing and tessellation.
		/// </summary>
		private static void EnsureNeighborParentSplit(QuadNode neighbor)
		{
			//Checking for null neighbor and null parent in case 
			//we recode for additional quad trees in the future.
			if (neighbor != null && neighbor.Parent != null)
				if (!neighbor.Parent.IsSplit)
					neighbor.Parent.Split();
		}
Exemplo n.º 8
0
		/// <summary>
		/// Add child nodes
		/// </summary>
		private void AddChildren()
		{
			//Add top left (northwest) child
			ChildTopLeft = new QuadNode(NodeType.TopLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTopLeft.Index);
			
			//Add top right (northeast) child
			ChildTopRight = new QuadNode(NodeType.TopRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexTop.Index);

			//Add bottom left (southwest) child
			ChildBottomLeft = new QuadNode(NodeType.BottomLeft, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexLeft.Index);

			//Add bottom right (southeast) child
			ChildBottomRight = new QuadNode(NodeType.BottomRight, _nodeSize / 2, _nodeDepth + 1, this, _parentTree, VertexCenter.Index);

			HasChildren = true;
		}