Esempio n. 1
0
        public void UpdateChildrenRecursively(GraphicsDevice graphicsDevice, HeightProvider heightProvider, Vector3Double cameraPosition, List <QuadTreeNode> renderQueue, List <QuadTreeNode> disposalQueue, int childCreationDepth)
        {
            // Node should have children
            if (childCreationDepth < MaxChildCreationDepth && _halfEdgeLengthFlat > EdgeLengthLimit && Vector3Double.Distance(OriginPositionSphere, cameraPosition) < SplitDistanceMultiplier * _edgeLengthFlat)
            {
                // Add children if they aren't there
                if (!_hasChildren)
                {
                    ChildUpLeft    = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildUpLeft, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (_upDirectionFlat - _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere);
                    ChildUpRight   = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildUpRight, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (_upDirectionFlat + _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere);
                    ChildDownRight = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildDownRight, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (-_upDirectionFlat + _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere);
                    ChildDownLeft  = new QuadTreeNode(graphicsDevice, heightProvider, NodeType.ChildDownLeft, this, _halfEdgeLengthFlat, _originPositionFlat + _quarterEdgeLengthFlat * (-_upDirectionFlat - _rightDirectionFlat), _upDirectionFlat, _rightDirectionFlat, _radiusSphere);

                    _hasChildren = true;

                    childCreationDepth += 1;
                }

                ChildUpLeft.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth);
                ChildUpRight.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth);
                ChildDownRight.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth);
                ChildDownLeft.UpdateChildrenRecursively(graphicsDevice, heightProvider, cameraPosition, renderQueue, disposalQueue, childCreationDepth);
            }
            // Node shouldn't have children
            else
            {
                // Remove children and mark them for disposal if they are there
                if (_hasChildren)
                {
                    disposalQueue.Add(ChildUpLeft);
                    disposalQueue.Add(ChildUpRight);
                    disposalQueue.Add(ChildDownRight);
                    disposalQueue.Add(ChildDownLeft);

                    ChildUpLeft    = null;
                    ChildUpRight   = null;
                    ChildDownRight = null;
                    ChildDownLeft  = null;

                    _hasChildren = false;
                }

                if (VertexBuffer == null)
                {
                    CalculateContents();
                }

                renderQueue.Add(this);
            }
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_hasChildren)
            {
                ChildUpLeft.Dispose();
                ChildUpRight.Dispose();
                ChildDownRight.Dispose();
                ChildDownLeft.Dispose();
            }

            if (VertexBuffer != null)
            {
                VertexBuffer.Dispose();
            }
        }
Esempio n. 3
0
        public void UpdateNeighboursRecursively()
        {
            switch (_nodeType)
            {
            case NodeType.ChildUpLeft:
                if (_parentNode.NeighbourUp != null)
                {
                    NeighbourUp = _parentNode.NeighbourUp.ChildDownLeft;
                }
                NeighbourRight = _parentNode.ChildUpRight;
                NeighbourDown  = _parentNode.ChildDownLeft;
                if (_parentNode.NeighbourLeft != null)
                {
                    NeighbourLeft = _parentNode.NeighbourLeft.ChildUpRight;
                }
                break;

            case NodeType.ChildUpRight:
                if (_parentNode.NeighbourUp != null)
                {
                    NeighbourUp = _parentNode.NeighbourUp.ChildDownRight;
                }
                if (_parentNode.NeighbourRight != null)
                {
                    NeighbourRight = _parentNode.NeighbourRight.ChildUpLeft;
                }
                NeighbourDown = _parentNode.ChildDownRight;
                NeighbourLeft = _parentNode.ChildUpLeft;
                break;

            case NodeType.ChildDownRight:
                NeighbourUp = _parentNode.ChildUpRight;
                if (_parentNode.NeighbourRight != null)
                {
                    NeighbourRight = _parentNode.NeighbourRight.ChildDownLeft;
                }
                if (_parentNode.NeighbourDown != null)
                {
                    NeighbourDown = _parentNode.NeighbourDown.ChildUpRight;
                }
                NeighbourLeft = _parentNode.ChildDownLeft;
                break;

            case NodeType.ChildDownLeft:
                NeighbourUp    = _parentNode.ChildUpLeft;
                NeighbourRight = _parentNode.ChildDownRight;
                if (_parentNode.NeighbourDown != null)
                {
                    NeighbourDown = _parentNode.NeighbourDown.ChildUpLeft;
                }
                if (_parentNode.NeighbourLeft != null)
                {
                    NeighbourLeft = _parentNode.NeighbourLeft.ChildDownRight;
                }
                break;
            }

            if (_hasChildren)
            {
                ChildUpLeft.UpdateNeighboursRecursively();
                ChildUpRight.UpdateNeighboursRecursively();
                ChildDownLeft.UpdateNeighboursRecursively();
                ChildDownRight.UpdateNeighboursRecursively();
            }
        }